Class: QDA::Backend::NPReader
- Inherits:
-
Object
- Object
- QDA::Backend::NPReader
- Defined in:
- lib/weft/backend/n6.rb
Overview
An implementation of a nested parenthesis reader. This implementation constructs an AST from a data source.
Instance Method Summary collapse
-
#initialize ⇒ NPReader
constructor
Initialize a new instance of the reader.
-
#parse(string) ⇒ Object
Parse the data contained in the string and return the reference to the top level group.
Constructor Details
#initialize ⇒ NPReader
Initialize a new instance of the reader. This does not start the parsing, that is done with the parse method.
330 331 |
# File 'lib/weft/backend/n6.rb', line 330 def initialize () end |
Instance Method Details
#parse(string) ⇒ Object
Parse the data contained in the string and return the reference to the top level group.
335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 |
# File 'lib/weft/backend/n6.rb', line 335 def parse (string) @curgroup = nil @top = nil string.each_byte { |byte| ch = byte.chr if ( ch == '(' ) then @curgroup = NPNode.new(@curgroup) if ( @top == nil ) then @top = @curgroup end elsif ( ch == ')' ) then @curgroup.close @curgroup = @curgroup.parent else if ( @curgroup != nil ) then @curgroup.push(ch) end end } return @top end |