Module: Aurum::Engine::BasicTokenizationCapability
- Defined in:
- lib/aurum/engine/tokenization_facility.rb
Instance Attribute Summary collapse
-
#column ⇒ Object
readonly
Returns the value of attribute column.
-
#line ⇒ Object
readonly
Returns the value of attribute line.
Instance Method Summary collapse
Instance Attribute Details
#column ⇒ Object (readonly)
Returns the value of attribute column.
11 12 13 |
# File 'lib/aurum/engine/tokenization_facility.rb', line 11 def column @column end |
#line ⇒ Object (readonly)
Returns the value of attribute line.
11 12 13 |
# File 'lib/aurum/engine/tokenization_facility.rb', line 11 def line @line end |
Instance Method Details
#next_symbol ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/aurum/engine/tokenization_facility.rb', line 12 def next_symbol return @push_back.pop unless @push_back.empty? @recognized, @recognized_lexeme = nil, '' until @recognized @lexeme, next_state, char = '', @states.last, nil lookaheads, action = [], nil while next_state if char lookaheads << char @column += 1 end return EOF if @input.eof? && @recognized_lexeme.empty? && @lexeme.empty? && lookaheads.empty? state, char = next_state, @input.get_char if lexical_table.actions[state] action = lexical_table.actions[state] while (c = lookaheads.shift) @lexeme << c end end next_state = goto(state, char) end @input.pushback char unless action unrecognized_lexeme = @recognized_lexeme lookaheads.each {|lookahead| unrecognized_lexeme << lookahead} return Token.new('$unknown', unrecognized_lexeme) end while (c = lookaheads.pop) @input.pushback c end @recognized_lexeme += @lexeme unless action.token == '$ignored' shift_to(action.state) if action.state @recognized = Token.new(action.token, @recognized_lexeme) if action.token && action.token != '$ignored' instance_eval(&action.action) if action.action end @recognized end |
#pushback(symbol) ⇒ Object
50 51 52 |
# File 'lib/aurum/engine/tokenization_facility.rb', line 50 def pushback symbol @push_back.push(symbol) end |