class STSScanner
Public Class Methods
new( script )
click to toggle source
Initialization & Terminating methods
# File lib/statsailr/scanner/sts_scanner.rb, line 58 def initialize( script ) @script = script end
Public Instance Methods
append_to_data_script( script )
click to toggle source
# File lib/statsailr/scanner/sts_scanner.rb, line 195 def append_to_data_script( script ) @data_script << script end
append_to_proc_tokens( tokens )
click to toggle source
# File lib/statsailr/scanner/sts_scanner.rb, line 213 def append_to_proc_tokens( tokens ) @proc_tokens.concat tokens end
bol?()
click to toggle source
# File lib/statsailr/scanner/sts_scanner.rb, line 93 def bol?() @scanner.bol? end
check(pattern)
click to toggle source
# File lib/statsailr/scanner/sts_scanner.rb, line 97 def check(pattern) @scanner.check(pattern) end
eos?()
click to toggle source
# File lib/statsailr/scanner/sts_scanner.rb, line 89 def eos?() @scanner.eos? end
get_data_script()
click to toggle source
# File lib/statsailr/scanner/sts_scanner.rb, line 199 def get_data_script() return @data_script end
get_proc_tokens()
click to toggle source
# File lib/statsailr/scanner/sts_scanner.rb, line 209 def get_proc_tokens() return @proc_tokens end
get_scan_state()
click to toggle source
# File lib/statsailr/scanner/sts_scanner.rb, line 329 def get_scan_state() return @scan_state end
matched()
click to toggle source
# File lib/statsailr/scanner/sts_scanner.rb, line 85 def matched() @scanner.matched end
prepare_data_script()
click to toggle source
Additional features for data script
# File lib/statsailr/scanner/sts_scanner.rb, line 191 def prepare_data_script() @data_script = "" end
prepare_proc_tokens()
click to toggle source
Additional features for proc stmts
# File lib/statsailr/scanner/sts_scanner.rb, line 205 def prepare_proc_tokens() @proc_tokens = [] end
scan(pattern)
click to toggle source
Delegate corresponding methods to StringScanner
# File lib/statsailr/scanner/sts_scanner.rb, line 73 def scan(pattern) @scanner.scan(pattern) end
scan_end_line?()
click to toggle source
# File lib/statsailr/scanner/sts_scanner.rb, line 170 def scan_end_line?() if( scan(/[ \t]*E[Nn][Dd][ \t]*/)) if scan(/\S+/) puts "Script after END is ignored (" + matched + ")" end scan_until(/\n/) # Move to the end of line return true else return false end end
scan_ident()
click to toggle source
# File lib/statsailr/scanner/sts_scanner.rb, line 135 def scan_ident() scan(IDENT_PATTERN) end
scan_proc_inst()
click to toggle source
# File lib/statsailr/scanner/sts_scanner.rb, line 217 def scan_proc_inst() skip_spaces() scan(PROC_INST_PATTERN) end
scan_proc_special()
click to toggle source
# File lib/statsailr/scanner/sts_scanner.rb, line 222 def scan_proc_special() case when scan(/\=/) return :P_EQ when scan(/\*/) return :P_MULT when scan(/\+/) return :P_PLUS when scan(/\-/) return :P_MINUS when scan(/\^/) return :P_HAT when scan(/\%in\%/) return :P_IN when scan(/\%in\%/) return :P_PERC when scan(/\~/) return :P_TILDA when scan(/\:/) return :P_COLON when scan(/\(/) return :P_LPAR when scan(/\)/) return :P_RPAR when scan(/\[/) return :P_LSQBR when scan(/\]/) return :P_RSQBR when scan(/\,/) return :P_COMMA end end
scan_state_data?()
click to toggle source
# File lib/statsailr/scanner/sts_scanner.rb, line 301 def scan_state_data?() if @scan_state == :DATA return true else return false end end
scan_state_proc?()
click to toggle source
# File lib/statsailr/scanner/sts_scanner.rb, line 309 def scan_state_proc?() if @scan_state == :PROC return true else return false end end
scan_state_set_data()
click to toggle source
# File lib/statsailr/scanner/sts_scanner.rb, line 321 def scan_state_set_data() @scan_state = :DATA end
scan_state_set_proc()
click to toggle source
# File lib/statsailr/scanner/sts_scanner.rb, line 325 def scan_state_set_proc() @scan_state = :PROC end
scan_state_set_top()
click to toggle source
# File lib/statsailr/scanner/sts_scanner.rb, line 317 def scan_state_set_top() @scan_state = :TOP end
scan_state_top?()
click to toggle source
Manage scan states
# File lib/statsailr/scanner/sts_scanner.rb, line 293 def scan_state_top?() if @scan_state == :TOP return true else return false end end
scan_toplevel_instruction()
click to toggle source
Additional features for TOPLEVEL
# File lib/statsailr/scanner/sts_scanner.rb, line 184 def scan_toplevel_instruction inst = Regexp.new( /\s*/.source() + IDENT_PATTERN.source() ) scan( inst ) end
scan_until(pattern)
click to toggle source
# File lib/statsailr/scanner/sts_scanner.rb, line 77 def scan_until(pattern) @scanner.scan_until(pattern) end
scan_whole_line()
click to toggle source
# File lib/statsailr/scanner/sts_scanner.rb, line 166 def scan_whole_line() scan(/.*\n/) end
skip_empty_line()
click to toggle source
# File lib/statsailr/scanner/sts_scanner.rb, line 119 def skip_empty_line() if scan(/[ \t]*\n/) # Empty line return true else return false end end
skip_line()
click to toggle source
# File lib/statsailr/scanner/sts_scanner.rb, line 107 def skip_line() scan_until(/\n/) end
skip_multiple_line_comment()
click to toggle source
# File lib/statsailr/scanner/sts_scanner.rb, line 127 def skip_multiple_line_comment() if scan(/\s*\/\*(.|\n)+?\*\//) return true else return false end end
skip_rest_after_comment_sign()
click to toggle source
# File lib/statsailr/scanner/sts_scanner.rb, line 111 def skip_rest_after_comment_sign() if scan(/[ \t]*(\/\/).*\n/) # line after // return true else return false end end
skip_spaces()
click to toggle source
Additional scanner methods
# File lib/statsailr/scanner/sts_scanner.rb, line 103 def skip_spaces() scan(/[ \t]*/) end
skip_until(pattern)
click to toggle source
# File lib/statsailr/scanner/sts_scanner.rb, line 81 def skip_until(pattern) @scanner.skip_until(pattern) end
start()
click to toggle source
# File lib/statsailr/scanner/sts_scanner.rb, line 62 def start() @scanner = StringScanner.new(@script) @scan_state = :TOP end
terminate()
click to toggle source
# File lib/statsailr/scanner/sts_scanner.rb, line 67 def terminate() @scanner.terminate() end
tokenize_options()
click to toggle source
# File lib/statsailr/scanner/sts_scanner.rb, line 139 def tokenize_options() tokens = [] while 1 do case when eos? || scan(/\n/) break when scan(/=/) tokens << [:ASSIGN, matched ] when scan(IDENT_PATTERN) tokens << [:IDENT, matched ] when scan(FLOATP_PATTERN) tokens << [:NUMBER, matched.to_f ] when scan(INT_PATTERN) tokens << [:NUMBER, matched.to_i ] when scan(SQ_STR_PATTERN) tokens << [:STRING, matched[Range.new(1, -2)] ] when scan(DQ_STR_PATTERN) tokens << [:STRING, interpret_escape_sequences(matched[Range.new(1, -2)]) ] when scan(/[ \t]/) #ignore else raise "options cannot be tokenized." end end return tokens end
tokenize_proc_line()
click to toggle source
# File lib/statsailr/scanner/sts_scanner.rb, line 255 def tokenize_proc_line() tokens = [] while 1 do case when eos? || scan(/\n/) break when scan(IDENT_PATTERN) tokens << [:IDENT, matched ] when scan(FLOATP_PATTERN) tokens << [:NUMBER, matched.to_f ] when scan(INT_PATTERN) tokens << [:NUMBER, matched.to_i ] when scan(SQ_STR_PATTERN) tokens << [:STRING, matched[Range.new(1, -2)] ] when scan(DQ_STR_PATTERN) tokens << [:STRING, interpret_escape_sequences(matched[Range.new(1, -2)]) ] when type = scan_proc_special() tokens << [ type , matched ] when scan(/[ \t]/) # Separators #ignore when scan(/\/\//) # Start comment @scanner.unscan break when scan(/\/\*/) # Start comment @scanner.unscan break when scan(/\//) # slash to start options tokens << [:SEP_SLASH, matched] else scan(/.*\n/) raise "Current PROC line cannot be tokenized." + matched end end return tokens end