From f40d4ead0b7592cdd1dc46d23286197bc818bdb8 Mon Sep 17 00:00:00 2001 From: William Joye Date: Mon, 26 Mar 2018 16:34:38 -0400 Subject: add ds9 cat parser --- ds9/library/cat.tcl | 50 +++++++++++++++++++++++++---------------------- ds9/parsers/catlex.fcl | 13 +++++++++++- ds9/parsers/catparser.tac | 44 ++++++++++++++++++++++++++++++++++++++--- 3 files changed, 80 insertions(+), 27 deletions(-) diff --git a/ds9/library/cat.tcl b/ds9/library/cat.tcl index dc687b1..e3a1c4a 100644 --- a/ds9/library/cat.tcl +++ b/ds9/library/cat.tcl @@ -1305,11 +1305,6 @@ proc ProcessCatalogCmd {varname iname} { global debug if {$debug(tcl,parser)} { - global icat - set ref [lindex $icat(cats) end] - global cvarname - set cvarname $ref - cat::YY_FLUSH_BUFFER cat::yy_scan_string [lrange $var $i end] cat::yyparse @@ -1566,8 +1561,6 @@ proc ProcessCatalog {varname iname cvarname} { unique {incr i; set icat(unique) [FromYesNo [lindex $var $i]]} return {incr i; set icat(return) [lindex $var $i]} default { - set icat(match1) {} - set icat(match2) {} set m1 [lindex $var $i] set m2 [lindex $var [expr $i+1]] if {$m1 != {}} { @@ -1575,27 +1568,15 @@ proc ProcessCatalog {varname iname cvarname} { if {$m2 != {}} { if {[string range $m2 0 0] != {-}} { incr i - set icat(match1) "cat$m1" - set icat(match2) "cat$m2" - CATMatch $current(frame) \ - $icat(match1) $icat(match2) + CatalogCmdMatchParams "cat$m1" "cat$m2" return } - } else { - # error - return } } - } - incr i -1 - # find them - set ll [llength $icat(cats)] - if {$ll>1} { - set icat(match1) [lindex $icat(cats) [expr $ll-2]] - set icat(match2) [lindex $icat(cats) [expr $ll-1]] - CATMatch $current(frame) $icat(match1) $icat(match2) } else { - # error + # find them + incr i -1 + CatalogCmdMatch } } } @@ -1926,6 +1907,29 @@ proc CatalogCmdLoad {fn reader} { } } +proc CatalogCmdMatch {} { + global icat + + set icat(match1) {} + set icat(match2) {} + set ll [llength $icat(cats)] + if {$ll>1} { + CatalogCmdMatchParams [lindex $icat(cats) [expr $ll-2]] \ + [lindex $icat(cats) [expr $ll-1]] + } +} + +proc CatalogCmdMatchParams {cat1 cat2} { + global icat + global current + + set icat(match1) $cat1 + set icat(match2) $cat2 + if {$current(frame) != {}} { + CATMatch $current(frame) $icat(match1) $icat(match2) + } +} + proc CatalogCmdSave {cvarname fn writer} { global icat diff --git a/ds9/parsers/catlex.fcl b/ds9/parsers/catlex.fcl index 18b6279..b29e86f 100644 --- a/ds9/parsers/catlex.fcl +++ b/ds9/parsers/catlex.fcl @@ -7,8 +7,14 @@ %% +1and2 {return $1AND2_} +1not2 {return $1NOT2_} +1only {return $1ONLY_} +2not1 {return $2NOT1_} +2only {return $2ONLY_} allcols {return $ALLCOLS_} allrows {return $ALLROWS_} +broadcast {return $BROADCAST_} cancel {return $CANCEL_} cds {return $CDS_} clear {return $CLEAR_} @@ -17,13 +23,17 @@ coordinate {return $COORDINATE_} crosshair {return $CROSSHAIR_} csv {return $CSV_} dec {return $DEC_} +decr {return $DECR_} edit {return $EDIT_} +error {return $ERROR_} export {return $EXPORT_} file {return $FILE_} filter {return $FILTER_} +function {return $FUNCTION_} header {return $HEADER_} hide {return $HIDE_} import {return $IMPORT_} +incr {return $INCR_} load {return $LOAD_} location {return $LOCATION_} match {return $MATCH_} @@ -37,6 +47,7 @@ psystem {return $PSYSTEM_} ra {return $RA_} regions {return $REGIONS_} retrieve {return $RETRIEVE_} +return {return $RETURN_} samp {return $SAMP_} save {return $SAVE_} sb {return $SB_} @@ -50,11 +61,11 @@ starbase {return $STARBASE_} symbol {return $SYMBOL_} system {return $SYSTEM_} tsv {return $TSV_} +unique {return $UNIQUE_} update {return $UPDATE_} vot {return $VOT_} xml {return $XML_} - #include yesno.fin #include skyformat.fin #include skyframe.fin diff --git a/ds9/parsers/catparser.tac b/ds9/parsers/catparser.tac index 7fc9016..ba4d9c6 100644 --- a/ds9/parsers/catparser.tac +++ b/ds9/parsers/catparser.tac @@ -1,4 +1,8 @@ %{ + global icat + set ref [lindex $icat(cats) end] + global cvarname + set cvarname $ref %} #include yesno.tin @@ -10,8 +14,14 @@ %start command +%token 1AND2_ +%token 1NOT2_ +%token 1ONLY_ +%token 2NOT1_ +%token 2ONLY_ %token ALLCOLS_ %token ALLROWS_ +%token BROADCAST_ %token CANCEL_ %token CDS_ %token CLEAR_ @@ -22,8 +32,10 @@ %token DEC_ %token EDIT_ %token EXPORT_ +%token ERROR_ %token FILE_ %token FILTER_ +%token FUNCTION_ %token HEADER_ %token HIDE_ %token IMPORT_ @@ -40,9 +52,11 @@ %token RA_ %token REGIONS_ %token RETRIEVE_ +%token RETURN_ %token SAMP_ %token SAVE_ %token SB_ +%token SEND_ %token SERVER_ %token SHOW_ %token SIZE_ @@ -53,6 +67,7 @@ %token SYMBOL_ %token SYSTEM_ %token TSV_ +%token UNIQUE_ %token UPDATE_ %token VOT_ %token XML_ @@ -93,7 +108,7 @@ cat : | HEADER_ {global cvarname; CATHeader $cvarname} | HIDE_ {global cvarname; global $cvarname; set ${cvarname}(show) 0; CATGenerate $cvarname} | LOCATION_ INT_ {global cvarname; global $cvarname; set ${cvarname}(loc) $2; CATGenerate $cvarname} - | MATCH_ + | MATCH_ match | MAXROWS_ INT_ {global cvarname; global $cvarname; set ${cvarname}(max) $2} | NAME_ STRING_ {global cvarname; global $cvarname; set ${cvarname}(name) $2} | PANTO_ yesno {global cvarname; global $cvarname; set ${cvarname}(panto) $2} @@ -103,11 +118,11 @@ cat : | PSYSTEM_ wcssys {global cvarname; global $cvarname; set ${cvarname}(psystem) $2; CATGenerate $cvarname} | REGIONS_ {global cvarname; CATGenerateRegions $cvarname} | RETRIEVE_ {global cvarname; CATApply $cvarname 1} - | SAMP_ + | SAMP_ samp | SAVE_ STRING_ {global cvarname; CatalogCmdSave $cvarname $2 VOTWrite} | SERVER_ STRING_ {global cvarname; global $cvarname; set ${cvarname}(server) $2} | SHOW_ {global cvarname; global $cvarname; set ${cvarname}(show) 1; CATGenerate $cvarname} - | SIZE_ + | SIZE_ numeric numeric skyformat {global cvarname; global $cvarname; set ${cvarname}(width) $1; set ${cvarname}(height) $2; set ${cvarname}(rformat) $3; set ${cvarname}(rformat,msg) $3} | SKY_ skyframe {global cvarname; global $cvarname; set ${cvarname}(sky) $1; CoordMenuButtonCmd $cvarname system sky [list CATWCSMenuUpdate $cvarname]} | SKYFORMAT_ skyformat {global cvarname; global $cvarname; set ${cvarname}(skyformat) $2} | SORT_ @@ -131,6 +146,24 @@ filter : LOAD_ STRING_ {global cvarname; CatalogCmdFilter $cvarname $2} | STRING_ {global cvarname; global $cvarname; set ${cvarname}(filter) $1; CATable $cvarname} ; +match : {CatalogCmdMatch} + | ERROR_ numeric skyformat {global icat; set icat(error) $2; set icat(eformat) $3} + | FUNCTION_ matchFunction {global icat; set icat(function) $2} + | UNIQUE_ yesno {global icat; set icat(unique) $2} + | RETURN_ matchReturn {global icat; set icat(return) $2} + | STRING_ STRING_ {CatalogCmdMatchParams $1 $2} + ; + +matchFunction : 1AND2_ {set _ 1and2} + | 1NOT2_ {set _ 1not2} + | 2NOT1_ {set _ 2not1} + ; + +matchReturn : 1AND2_ {set _ 1and2} + | 1ONLY_ {set _ 1only} + | 2ONLY_ {set _ 2only} + ; + reader : XML_ {set _ VOTRead} | VOT_ {set _ VOTRead} | SB_ {set _ starbase_read} @@ -139,6 +172,11 @@ reader : XML_ {set _ VOTRead} | TSV_ {set _ TSVRead} ; +samp : {global cvarname; SAMPSendTableLoadVotable {} $cvarname} + | BROADCAST_ {global cvarname; SAMPSendTableLoadVotable {} $cvarname} + | SEND_ STRING_ {CatalogSAMPCmd $2} + ; + writer : XML_ {set _ VOTWrite} | VOT_ {set _ VOTWrite} | SB_ {set _ starbase_write} -- cgit v0.12