Class: SportDb::Lexer::Context
- Inherits:
-
Object
- Object
- SportDb::Lexer::Context
- Defined in:
- lib/sportdb/parser/lexer-tokenize.rb
Overview
use nested class for context - why? why not?
note: first arg passed in MUST be ref to lexer (instance)
Instance Attribute Summary collapse
-
#lineno ⇒ Object
readonly
Returns the value of attribute lineno.
-
#offset ⇒ Object
writeonly
passed along to on_round_def etc.
Instance Method Summary collapse
- #_add_warn(msg) ⇒ Object
-
#initialize(lexer, line:, lineno:, errors:) ⇒ Context
constructor
A new instance of Context.
- #warn_on_else(match, mode: 'TOP') ⇒ Object
Constructor Details
#initialize(lexer, line:, lineno:, errors:) ⇒ Context
Returns a new instance of Context.
14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/sportdb/parser/lexer-tokenize.rb', line 14 def initialize( lexer, line:, lineno:, errors: ) @lexer = lexer @line = line @lineno = lineno @errors = errors @offset = [0,0] ## or use [] aka [nil,nil] for not defined??? why? why not? ## @offset = offset ## MatchData offset e.g. [m.begin(0),m.end(0)] end |
Instance Attribute Details
#lineno ⇒ Object (readonly)
Returns the value of attribute lineno.
12 13 14 |
# File 'lib/sportdb/parser/lexer-tokenize.rb', line 12 def lineno @lineno end |
#offset=(value) ⇒ Object (writeonly)
passed along to on_round_def etc. handlers in tokenize_line
note - for now only offset (in line begin/end) gets updated !!!
11 12 13 |
# File 'lib/sportdb/parser/lexer-tokenize.rb', line 11 def offset=(value) @offset = value end |
Instance Method Details
#_add_warn(msg) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/sportdb/parser/lexer-tokenize.rb', line 39 def _add_warn( msg ) ## note - warns gets logged as error for now too ## maybe add @warns later - why? why not? ## ## note - add +1 to offset (start at one - not zero-based) ## will match with (external) text editors msg = "parse error (tokenize) - " + msg + " in line @#{@lineno}:#{@offset[0]+1},#{@offset[1]+1} >#{@line}< " @errors << msg @lexer.log( "!! WARN - #{msg}" ) @lexer._warn( msg ) end |
#warn_on_else(match, mode: 'TOP') ⇒ Object
29 30 31 32 33 34 35 36 |
# File 'lib/sportdb/parser/lexer-tokenize.rb', line 29 def warn_on_else( match, mode: 'TOP' ) if match[:any] _add_warn( "unexpected char >#{match[:any]}< (#{mode})" ) else ## internal error - shouldn't really happen _add_warn( "internal error - unknown match (#{mode}): #{match.inspect}") end end |