diff options
author | William Joye <wjoye@cfa.harvard.edu> | 2018-05-09 19:38:50 (GMT) |
---|---|---|
committer | William Joye <wjoye@cfa.harvard.edu> | 2018-05-09 19:38:50 (GMT) |
commit | 5273df633cc312db28f2778b05dac48cbe3ae455 (patch) | |
tree | 9301f849278abc03bfc19fc9c15a21cab7483359 | |
parent | 888c5a7dc8199ffdf42f5e58b26fa4863195f0e9 (diff) | |
download | blt-5273df633cc312db28f2778b05dac48cbe3ae455.zip blt-5273df633cc312db28f2778b05dac48cbe3ae455.tar.gz blt-5273df633cc312db28f2778b05dac48cbe3ae455.tar.bz2 |
add ds9 nrrd parser
-rw-r--r-- | ds9/library/nrrd.tcl | 42 | ||||
-rw-r--r-- | ds9/library/source.tcl | 2 | ||||
-rw-r--r-- | ds9/parsers/nrrdlex.fcl | 16 | ||||
-rw-r--r-- | ds9/parsers/nrrdparser.tac | 36 |
4 files changed, 94 insertions, 2 deletions
diff --git a/ds9/library/nrrd.tcl b/ds9/library/nrrd.tcl index 512ec7c..2dbe750 100644 --- a/ds9/library/nrrd.tcl +++ b/ds9/library/nrrd.tcl @@ -84,11 +84,22 @@ proc ProcessNRRDCmd {varname iname sock fn} { upvar $varname var upvar $iname i + global debug + if {$debug(tcl,parser)} { + global nrrd + set nrrd(load,sock) $sock + set nrrd(load,fn) $fn + set nrrd(load,layer) {} + + nrrd::YY_FLUSH_BUFFER + nrrd::yy_scan_string [lrange $var $i end] + nrrd::yyparse + incr i [expr $nrrd::yycnt-1] + } else { + global loadParam global current - set layer {} - switch -- [string tolower [lindex $var $i]] { new { incr i @@ -121,6 +132,33 @@ proc ProcessNRRDCmd {varname iname sock fn} { } FinishLoad } +} + +proc NRRDCmdLoad {param} { + global nrrd + + if {$nrrd(load,sock) != {}} { + # xpa + if {![ImportNRRDSocket $nrrd(load,sock) $param $nrrd(load,layer)]} { + InitError xpa + ImportNRRDFile $param $nrrd(load,layer) + } + } else { + # comm + if {$nrrd(load,fn) != {}} { + ImportNRRDAlloc $nrrd(load,fn) $param $nrrd(load,layer) + } else { + ImportNRRDFile $param $nrrd(load,layer) + } + } + FinishLoad +} + +proc NRRDCmdSet {which value} { + global nrrd + + set nrrd($which) $value +} proc ProcessSendNRRDCmd {proc id param sock fn} { global current diff --git a/ds9/library/source.tcl b/ds9/library/source.tcl index e6ed274..24364f2 100644 --- a/ds9/library/source.tcl +++ b/ds9/library/source.tcl @@ -256,6 +256,8 @@ 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/nrrdparser.tcl +source $ds9(root)/library/nrrdlex.tcl source $ds9(root)/library/nvssparser.tcl source $ds9(root)/library/nvsslex.tcl source $ds9(root)/library/orientparser.tcl diff --git a/ds9/parsers/nrrdlex.fcl b/ds9/parsers/nrrdlex.fcl new file mode 100644 index 0000000..820bbbe --- /dev/null +++ b/ds9/parsers/nrrdlex.fcl @@ -0,0 +1,16 @@ +#tab nrrdparser.tab.tcl + +%{ +%} + +#include defs.fin + +%% + +mask {return $MASK_} +new {return $NEW_} +slice {return $SLICE_} + +#include string.fin + +%% diff --git a/ds9/parsers/nrrdparser.tac b/ds9/parsers/nrrdparser.tac new file mode 100644 index 0000000..49b4d1f --- /dev/null +++ b/ds9/parsers/nrrdparser.tac @@ -0,0 +1,36 @@ +%{ +%} + +#include string.tin + +%start command + +%token MASK_ +%token NEW_ +%token SLICE_ + +%% + +command : nrrd + | nrrd {yyclearin; YYACCEPT} STRING_ + ; + +nrrd : opts {NRRDCmdLoad {}} + | opts STRING_ {NRRDCmdLoad $2} + ; + +opts : + | NEW_ {CreateFrame} + | MASK_ {NRRDCmdSet load,layer mask} + | SLICE_ + ; + +%% + +proc nrrd::yyerror {msg} { + variable yycnt + variable yy_current_buffer + variable index_ + + ParserError $msg $yycnt $yy_current_buffer $index_ +} |