From c052962410047d3b2a444b693f7c3bd678b539ed Mon Sep 17 00:00:00 2001 From: William Joye Date: Tue, 8 May 2018 16:25:26 -0400 Subject: add ds9 mode parser --- ds9/library/source.tcl | 2 ++ ds9/library/util.tcl | 10 +++++++++- ds9/parsers/modelex.fcl | 23 ++++++++++++++++++++++ ds9/parsers/modeparser.tac | 49 ++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 83 insertions(+), 1 deletion(-) create mode 100644 ds9/parsers/modelex.fcl create mode 100644 ds9/parsers/modeparser.tac diff --git a/ds9/library/source.tcl b/ds9/library/source.tcl index 0354058..304f996 100644 --- a/ds9/library/source.tcl +++ b/ds9/library/source.tcl @@ -250,6 +250,8 @@ source $ds9(root)/library/matchparser.tcl source $ds9(root)/library/matchlex.tcl source $ds9(root)/library/minmaxparser.tcl source $ds9(root)/library/minmaxlex.tcl +source $ds9(root)/library/modeparser.tcl +source $ds9(root)/library/modelex.tcl source $ds9(root)/library/nanparser.tcl source $ds9(root)/library/nanlex.tcl source $ds9(root)/library/nvssparser.tcl diff --git a/ds9/library/util.tcl b/ds9/library/util.tcl index c6273e6..6c6c709 100644 --- a/ds9/library/util.tcl +++ b/ds9/library/util.tcl @@ -1582,8 +1582,15 @@ proc ProcessModeCmd {varname iname} { upvar $varname var upvar $iname i - global current + global debug + if {$debug(tcl,parser)} { + mode::YY_FLUSH_BUFFER + mode::yy_scan_string [lrange $var $i end] + mode::yyparse + incr i [expr $mode::yycnt-1] + } else { + global current set current(mode) [string tolower [lindex $var $i]] # backward compatibility switch $current(mode) { @@ -1591,6 +1598,7 @@ proc ProcessModeCmd {varname iname} { } ChangeMode } +} proc ProcessQuitCmd {varname iname} { upvar $varname var diff --git a/ds9/parsers/modelex.fcl b/ds9/parsers/modelex.fcl new file mode 100644 index 0000000..6be1a90 --- /dev/null +++ b/ds9/parsers/modelex.fcl @@ -0,0 +1,23 @@ +#tab modeparser.tab.tcl + +%{ +%} + +#include defs.fin + +%% + +none {return $NONE_} +region {return $REGION_} +crosshair {return $CROSSHAIR_} +colorbar {return $COLORBAR_} +pan {return $PAN_} +zoom {return $ZOOM_} +rotate {return $ROTATE_} +catalog {return $CATALOG_} +examine {return $EXAMINE_} +pointer {return $POINTER_} + +#include string.fin + +%% diff --git a/ds9/parsers/modeparser.tac b/ds9/parsers/modeparser.tac new file mode 100644 index 0000000..862ea8c --- /dev/null +++ b/ds9/parsers/modeparser.tac @@ -0,0 +1,49 @@ +%{ +%} + +#include string.tin + +%start command + +%token NONE_ +%token REGION_ +%token CROSSHAIR_ +%token COLORBAR_ +%token PAN_ +%token ZOOM_ +%token ROTATE_ +%token CATALOG_ +%token EXAMINE_ +%token POINTER_ + +%% + +command : mode + | mode {yyclearin; YYACCEPT} STRING_ + ; + +mode : item {CurrentCmdSet mode $1 ChangeMode} + ; + +item : NONE_ {set _ none} + | REGION_ {set _ region} + | CROSSHAIR_ {set _ crosshair} + | COLORBAR_ {set _ colorbar} + | PAN_ {set _ pan} + | ZOOM_ {set _ zoom} + | ROTATE_ {set _ rotate} + | CATALOG_ {set _ catalog} + | EXAMINE_ {set _ examine} +# backward compatibilty + | POINTER_ {set _ region} + ; + +%% + +proc mode::yyerror {msg} { + variable yycnt + variable yy_current_buffer + variable index_ + + ParserError $msg $yycnt $yy_current_buffer $index_ +} -- cgit v0.12