From 21af893753bca8a1e5b1e7507cdbed44ad895004 Mon Sep 17 00:00:00 2001 From: William Joye Date: Wed, 20 Jun 2018 15:58:34 -0400 Subject: add ds9 plot send parser --- ds9/library/plotprocess.tcl | 227 +++-------------------------------------- ds9/library/source.tcl | 2 + ds9/library/util.tcl | 24 +++++ ds9/parsers/plotparser.tac | 5 +- ds9/parsers/plotsendlex.fcl | 58 +++++++++++ ds9/parsers/plotsendparser.tac | 162 +++++++++++++++++++++++++++++ 6 files changed, 264 insertions(+), 214 deletions(-) create mode 100644 ds9/parsers/plotsendlex.fcl create mode 100644 ds9/parsers/plotsendparser.tac diff --git a/ds9/library/plotprocess.tcl b/ds9/library/plotprocess.tcl index 6a6557a..bc1b8bd 100644 --- a/ds9/library/plotprocess.tcl +++ b/ds9/library/plotprocess.tcl @@ -102,16 +102,17 @@ proc PrefsDialogPlot {} { proc ProcessPlotCmd {xarname iname buf fn} { upvar $xarname xar upvar $iname i - global iap - set ref [lindex $iap(windows) end] - global cvarname - set cvarname $ref + global iap global parse set parse(buf) $buf set parse(fn) $fn set parse(tt) $iap(tt) + set ref [lindex $iap(windows) end] + global cvarname + set cvarname $ref + plot::YY_FLUSH_BUFFER plot::yy_scan_string [lrange $xar $i end] plot::yyparse @@ -820,214 +821,16 @@ proc ProcessPlotLine {varname xarname iname} { proc ProcessSendPlotCmd {proc id param {sock {}} {fn {}}} { global iap + global parse + set parse(proc) $proc + set parse(id) $id - set i 0 - - # determine which plot - switch -- [string tolower [lindex $param $i]] { - {} - - stats - - statistics - - list - - mode - - axis - - legend - - font - - title - - barmode - - show - - color - - error - - errorbar - - name - - shape - - relief - - smooth - - width - - dash - - dataset - - select { - set varname [lindex $iap(windows) end] - set idd [lsearch $iap(windows) $varname] - } - - default { - set varname [lindex $param $i] - set idd [lsearch $iap(windows) $varname] - incr i - } - } - - # we better have a tt by now - if {$idd == -1} { - Error "[msgcat::mc {Unable to find plot window}] $varname" - return - } - - upvar #0 $varname var - global $varname - - # now, process plot command - switch -- [string tolower [lindex $param $i]] { - {} {$proc $id "$iap(windows)\n"} - stats - - statistics {$proc $id "[PlotStatsGenerate $varname]"} - list {$proc $id "[PlotListGenerate $varname]"} - mode {$proc $id "$var(mode)\n"} - axis { - incr i - switch -- [string tolower [lindex $param $i]] { - x { - incr i - switch -- [string tolower [lindex $param $i]] { - grid {$proc $id [ToYesNo $var(axis,x,grid)]} - log {$proc $id [ToYesNo $var(axis,x,log)]} - flip {$proc $id [ToYesNo $var(axis,x,flip)]} - auto {$proc $id [ToYesNo $var(axis,x,auto)]} - min {$proc $id "$var(axis,x,min)\n"} - max {$proc $id "$var(axis,x,max)\n"} - format {$proc $id "$var(axis,x,format)\n"} - } - } - y { - incr i - switch -- [string tolower [lindex $param $i]] { - grid {$proc $id [ToYesNo $var(axis,y,grid)]} - log {$proc $id [ToYesNo $var(axis,y,log)]} - flip {$proc $id [ToYesNo $var(axis,y,flip)]} - auto {$proc $id [ToYesNo $var(axis,y,auto)]} - min {$proc $id "$var(axis,y,min)\n"} - max {$proc $id "$var(axis,y,max)\n"} - format {$proc $id "$var(axis,y,format)\n"} - } - } - } - } - legend { - incr i - switch -- [string tolower [lindex $param $i]] { - position {$proc $id "$var(legend,position)\n"} - default {$proc $id [ToYesNo $var(legend)]} - } - } - font { - incr i - switch -- [string tolower [lindex $param $i]] { - title { - incr i - switch -- [string tolower [lindex $param $i]] { - family - - font {$proc $id "$var(graph,title,family)\n"} - size {$proc $id "$var(graph,title,size)\n"} - weight {$proc $id "$var(graph,title,weight)\n"} - slant {$proc $id "$var(graph,title,slant)\n"} - style { - # backward compatibility - $proc $id "$var(graph,title,weight)\n" - } - } - } - axestitle - - labels { - incr i - switch -- [string tolower [lindex $param $i]] { - family - - font {$proc $id "$var(axis,title,family)\n"} - size {$proc $id "$var(axis,title,size)\n"} - weight {$proc $id "$var(axis,title,weight)\n"} - slant {$proc $id "$var(axis,title,slant)\n"} - style { - # backward compatibility - $proc $id "$var(axis,title,weight)\n" - } - } - } - axesnumbers - - numbers { - incr i - switch -- [string tolower [lindex $param $i]] { - family - - font {$proc $id "$var(axis,font,family)\n"} - size {$proc $id "$var(axis,font,size)\n"} - weight {$proc $id "$var(axis,font,weight)\n"} - slant {$proc $id "$var(axis,font,slant)\n"} - style { - # backward compatibility - $proc $id "$var(axis,font,weight)\n" - } - } - } - legendtitle { - incr i - switch -- [string tolower [lindex $param $i]] { - family - - font {$proc $id "$var(legend,title,family)\n"} - size {$proc $id "$var(legend,title,size)\n"} - weight {$proc $id "$var(legend,title,weight)\n"} - slant {$proc $id "$var(legend,title,slant)\n"} - style { - # backward compatibility - $proc $id "$var(legend,title,weight)\n" - } - } - } - legend { - incr i - switch -- [string tolower [lindex $param $i]] { - family - - font {$proc $id "$var(legend,font,family)\n"} - size {$proc $id "$var(legend,font,size)\n"} - weight {$proc $id "$var(legend,font,weight)\n"} - slant {$proc $id "$var(legend,font,slant)\n"} - style { - # backward compatibility - $proc $id "$var(legend,font,weight)\n" - } - } - } - } - } - title { - incr i - switch -- [string tolower [lindex $param $i]] { - x - - xaxis {$proc $id "$var(axis,x,title)\n"} - y - - yaxis {$proc $id "$var(axis,y,title)\n"} - legend {$proc $id "$var(legend,title)\n"} - default {$proc $id "$var(graph,title)\n"} - } - } - barmode {$proc $id "$var(bar,mode)\n"} + set ref [lindex $iap(windows) end] + global cvarname + set cvarname $ref + global parse - show {$proc $id [ToYesNo $var(show)]} - color {$proc $id "$var(color)\n"} - fill {$proc $id [ToYesNo $var(fill)]} - fillcolor {$proc $id "$var(fill,color)\n"} - error - - errorbar { - incr i - switch -- [string tolower [lindex $param $i]] { - cap {$proc $id [ToYesNo $var(error,cap)]} - color {$proc $id "$var(error,color)\n"} - width {$proc $id "$var(error,width)\n"} - default {$proc $id [ToYesNo $var(error)]} - } - } - name {$proc $id "$var(name)\n"} - shape { - incr i - switch -- [string tolower [lindex $param $i]] { - fill {$proc $id [ToYesNo $var(shape,fill)]} - color {$proc $id "$var(shape,color)\n"} - default {$proc $id "$var(shape,symbol)\n"} - } - } - relief {$proc $id "$var(bar,relief)\n"} - smooth {$proc $id "$var(smooth)\n"} - width {$proc $id "$var(width)\n"} - dash {$proc $id [ToYesNo $var(dash)]} - dataset - - select {$proc $id "$var(data,current)\n"} - } + plotsend::YY_FLUSH_BUFFER + plotsend::yy_scan_string $param + plotsend::yyparse } diff --git a/ds9/library/source.tcl b/ds9/library/source.tcl index 0d19362..ba034ed 100644 --- a/ds9/library/source.tcl +++ b/ds9/library/source.tcl @@ -350,6 +350,8 @@ source $ds9(root)/library/pixeltableparser.tcl source $ds9(root)/library/pixeltablelex.tcl source $ds9(root)/library/plotparser.tcl source $ds9(root)/library/plotlex.tcl +source $ds9(root)/library/plotsendparser.tcl +source $ds9(root)/library/plotsendlex.tcl source $ds9(root)/library/precisionparser.tcl source $ds9(root)/library/precisionlex.tcl source $ds9(root)/library/prefsparser.tcl diff --git a/ds9/library/util.tcl b/ds9/library/util.tcl index 9e26186..b6420d5 100644 --- a/ds9/library/util.tcl +++ b/ds9/library/util.tcl @@ -304,6 +304,14 @@ proc ProcessSendCmd {cmd} { $parse(proc) $parse(id) "[$cmd]" } +proc ProcessSendCmdCVAR {cmd} { + global cvarname + upvar #0 $cvarname cvar + + global parse + $parse(proc) $parse(id) "[$cmd $cvarname]" +} + proc ProcessSendCmdTxt {rr} { global parse $parse(proc) $parse(id) "$rr\n" @@ -317,6 +325,14 @@ proc ProcessSendCmdGet {varname key} { $parse(proc) $parse(id) "$var($key)\n" } +proc ProcessSendCmdCVARGet {key} { + global cvarname + upvar #0 $cvarname cvar + + global parse + $parse(proc) $parse(id) "$cvar($key)\n" +} + proc ProcessSendCmdGet2 {varname key key2} { upvar #0 $varname var global $varname @@ -349,6 +365,14 @@ proc ProcessSendCmdYesNo {varname key} { $parse(proc) $parse(id) [ToYesNo $var($key)] } +proc ProcessSendCmdCVARYesNo {key} { + global cvarname + upvar #0 $cvarname cvar + + global parse + $parse(proc) $parse(id) [ToYesNo $cvar($key)] +} + proc ProcessSendCmdCurrent {cmd} { global parse global current diff --git a/ds9/parsers/plotparser.tac b/ds9/parsers/plotparser.tac index 2181a29..9a6808c 100644 --- a/ds9/parsers/plotparser.tac +++ b/ds9/parsers/plotparser.tac @@ -330,6 +330,7 @@ legendPos : RIGHT_ {set _ right} ; fontt : fontType FONT_ font {PlotCmdUpdateGraph "$1,family" $3} +# backward compatibility | fontType FAMILY_ font {PlotCmdUpdateGraph "$1,family" $3} | fontType FONTSIZE_ INT_ {PlotCmdUpdateGraph "$1,size" $3} | fontType FONTWEIGHT_ fontWeight {PlotCmdUpdateGraph "$1,weight" $3} @@ -346,9 +347,9 @@ fontType : TITLE_ {set _ graph,title} | LABELS_ {set _ axis,title} # backward compatibility | AXESTITLE_ {set _ axis,title} - | NUMBERS_ {set _ axis,numbers} + | NUMBERS_ {set _ axis,font} # backward compatibility - | AXESNUMBERS_ {set _ axis,numbers} + | AXESNUMBERS_ {set _ axis,font} | LEGEND_ {set _ legend,font} | LEGENDTITLE_ {set _ legend,title} ; diff --git a/ds9/parsers/plotsendlex.fcl b/ds9/parsers/plotsendlex.fcl new file mode 100644 index 0000000..c6bdf2c --- /dev/null +++ b/ds9/parsers/plotsendlex.fcl @@ -0,0 +1,58 @@ +#tab plotsendparser.tab.tcl + +%{ +%} + +#include defs.fin + +%% + +auto {return $AUTO_} +axis {return $AXIS_} +axesnumbers {return $AXESNUMBERS_} +axestitle {return $AXESTITLE_} +barmode {return $BARMODE_} +cap {return $CAP_} +color {return $COLOR_} +dash {return $DASH_} +dataset {return $DATASET_} +error {return $ERROR_} +errorbar {return $ERRORBAR_} +family {return $FAMILY_} +fill {return $FILL_} +fillcolor {return $FILLCOLOR_} +flip {return $FLIP_} +format {return $FORMAT_} +grid {return $GRID_} +labels {return $LABELS_} +legend {return $LEGEND_} +legendtitle {return $LEGENDTITLE_} +list {return $LIST_} +log {return $LOG_} +max {return $MAX_} +min {return $MIN_} +mode {return $MODE_} +numbers {return $NUMBERS_} +name {return $NAME_} +position {return $POSITION_} +relief {return $RELIEF_} +select {return $SELECT_} +shape {return $SHAPE_} +show {return $SHOW_} +size {return $SIZE_} +slant {return $SLANT_} +smooth {return $SMOOTH_} +stats {return $STATS_} +statistics {return $STATISTICS_} +style {return $STYLE_} +title {return $TITLE_} +weight {return $WEIGHT_} +width {return $WIDTH_} +xaxis {return $XAXIS_} +yaxis {return $YAXIS_} + +#include font.fin +#include string.fin +#include ws.fin + +%% diff --git a/ds9/parsers/plotsendparser.tac b/ds9/parsers/plotsendparser.tac new file mode 100644 index 0000000..efcce12 --- /dev/null +++ b/ds9/parsers/plotsendparser.tac @@ -0,0 +1,162 @@ +%{ +%} + +#include font.tin +#include string.tin + +%token AUTO_ +%token AXIS_ +%token AXESNUMBERS_ +%token AXESTITLE_ +%token BARMODE_ +%token CAP_ +%token COLOR_ +%token DASH_ +%token DATASET_ +%token ERROR_ +%token ERRORBAR_ +%token FAMILY_ +%token FILL_ +%token FILLCOLOR_ +%token FLIP_ +%token FORMAT_ +%token GRID_ +%token LABELS_ +%token LEGEND_ +%token LEGENDTITLE_ +%token LIST_ +%token LOG_ +%token MAX_ +%token MIN_ +%token MODE_ +%token NUMBERS_ +%token NAME_ +%token POSITION_ +%token RELIEF_ +%token SELECT_ +%token SHAPE_ +%token SHOW_ +%token SIZE_ +%token SLANT_ +%token SMOOTH_ +%token STATS_ +%token STATISTICS_ +%token STYLE_ +%token TITLE_ +%token WEIGHT_ +%token WIDTH_ +%token XAXIS_ +%token YAXIS_ + +%start plotsend + +%% + +plotsend : {ProcessSendCmdGet iap windows} + | {if {![PlotCmdCheck]} {plot::YYABORT}} plotCmd + | STRING_ {if {![PlotCmdRef $1]} {plot::YYABORT}} plotCmd + ; + +xy : 'x' {set _ x} + | 'X' {set _ x} + | 'y' {set _ y} + | 'Y' {set _ y} + ; + +# backward compatibility +xyaxis : XAXIS_ {set _ x} + | YAXIS_ {set _ y} + ; + +plotCmd : STATS_ {ProcessSendCmdCVAR PlotStatsGenerate} + # backward compatibility + | STATISTICS_ {ProcessSendCmdCVAR PlotStatsGenerate} + | LIST_ {ProcessSendCmdCVAR PlotListGenerate} + | MODE_ {ProcessSendCmdCVARGet mode} + | AXIS_ axis + | LEGEND_ legend + | FONT_ fontt + | TITLE_ title + | BARMODE_ {ProcessSendCmdCVARGet bar,mode} + | SHOW_ {ProcessSendCmdCVARYesNo show} + | COLOR_ {ProcessSendCmdCVARGet color} + | FILL_ {ProcessSendCmdCVARGet fill} + | FILLCOLOR_ {ProcessSendCmdCVARGet fill,color} + | ERROR_ errorr + # backward compatibility + | ERRORBAR_ errorr + | NAME_ {ProcessSendCmdCVARGet name} + | SHAPE_ shape + | RELIEF_ {ProcessSendCmdCVARGet bar,relief} + | SMOOTH_ {ProcessSendCmdCVARGet smooth} + | WIDTH_ {ProcessSendCmdCVARGet width} + | DASH_ {ProcessSendCmdCVARYesNo dash} + | SELECT_ {ProcessSendCmdCVARGet data,current} + # backward compatibility + | DATASET_ {ProcessSendCmdCVARGet data,current} + ; + +axis : xy GRID_ {ProcessSendCmdCVARYesNo "axis,$1,grid"} + | xy LOG_ {ProcessSendCmdCVARYesNo "axis,$1,log"} + | xy FLIP_ {ProcessSendCmdCVARYesNo "axis,$1,flip"} + | xy AUTO_ {ProcessSendCmdCVARYesNo "axis,$1,auto"} + | xy MIN_ {ProcessSendCmdCVARGet "axis,$1,min"} + | xy MAX_ {ProcessSendCmdCVARGet "axis,$1,max"} + | xy FORMAT_ {ProcessSendCmdCVARGet "axis,$1,format"} + ; + +legend : {ProcessSendCmdCVARYesNo legend} + | POSITION_ {ProcessSendCmdCVARGet legend,position} + ; + +fontt : fontType FONT_ {ProcessSendCmdCVARGet "$1,family"} +# backward compatibility + | fontType FAMILY_ {ProcessSendCmdCVARGet "$1,family"} + | fontType FONTSIZE_ {ProcessSendCmdCVARGet "$1,size"} + | fontType FONTWEIGHT_ {ProcessSendCmdCVARGet "$1,weight"} + | fontType FONTSLANT_ {ProcessSendCmdCVARGet "$1,slant"} +# backward compatibility + | fontType FONTSTYLE_ {ProcessSendCmdCVARGet "$1,weight"} + | fontType SIZE_ {ProcessSendCmdCVARGet "$1,size"} + | fontType WEIGHT_ {ProcessSendCmdCVARGet "$1,weight"} + | fontType SLANT_ {ProcessSendCmdCVARGet "$1,slant"} + | fontType STYLE_ {ProcessSendCmdCVARGet "$1,weight"} + ; + +fontType : TITLE_ {set _ graph,title} + | LABELS_ {set _ axis,title} + # backward compatibility + | AXESTITLE_ {set _ axis,title} + | NUMBERS_ {set _ axis,font} + # backward compatibility + | AXESNUMBERS_ {set _ axis,font} + | LEGEND_ {set _ legend,font} + | LEGENDTITLE_ {set _ legend,title} + ; + +title : {ProcessSendCmdCVARGet graph,title} + | xy {ProcessSendCmdCVARGet "axis,$1,title"} + | xyaxis {ProcessSendCmdCVARGet "axis,$1,title"} + | LEGEND_ {ProcessSendCmdCVARGet legend,title} + ; + +errorr : {ProcessSendCmdCVARYesNo error} + | CAP_ {ProcessSendCmdCVARYesNo error,cap} + | COLOR_ {ProcessSendCmdCVARGet error,color} + | WIDTH_ {ProcessSendCmdCVARGet error,width} + ; + +shape : {ProcessSendCmdCVARGet shape,symbol} + | FILL_ {ProcessSendCmdCVARYesNo shape,fill} + | COLOR_ {ProcessSendCmdCVARGet shape,color} + ; + +%% + +proc plotsend::yyerror {msg} { + variable yycnt + variable yy_current_buffer + variable index_ + + ParserError $msg $yycnt $yy_current_buffer $index_ +} -- cgit v0.12