Class: Zenlish::ZParser
- Inherits:
-
Object
- Object
- Zenlish::ZParser
- Defined in:
- lib/zenlish/parser/zparser.rb
Instance Attribute Summary collapse
-
#engine ⇒ Object
readonly
Returns the value of attribute engine.
Instance Method Summary collapse
-
#initialize ⇒ ZParser
constructor
A new instance of ZParser.
-
#parse(tokenSeq) ⇒ Rley::PTree;;ParseTree
(also: #to_ptree)
Parse the sequence of words into a parse tree.
-
#to_pforest(tokenSeq) ⇒ Rley::SPPF::ParseForest
Parse the sequence of words into a parse forest.
Constructor Details
#initialize ⇒ ZParser
Returns a new instance of ZParser.
11 12 13 14 15 16 17 18 19 |
# File 'lib/zenlish/parser/zparser.rb', line 11 def initialize # Create a Rley facade object @engine = Rley::Engine.new do |config| config.diagnose = true end # Step 1. Load Zenlish grammar @engine.use_grammar(ZenlishGrammar) end |
Instance Attribute Details
#engine ⇒ Object (readonly)
Returns the value of attribute engine.
9 10 11 |
# File 'lib/zenlish/parser/zparser.rb', line 9 def engine @engine end |
Instance Method Details
#parse(tokenSeq) ⇒ Rley::PTree;;ParseTree Also known as: to_ptree
Parse the sequence of words into a parse tree.
24 25 26 27 28 29 |
# File 'lib/zenlish/parser/zparser.rb', line 24 def parse(tokenSeq) result = earley_parse(tokenSeq) # Convert into a parse tree engine.to_ptree(result) end |
#to_pforest(tokenSeq) ⇒ Rley::SPPF::ParseForest
Parse the sequence of words into a parse forest. Parse forests are needed when dealing with ambiguous input.
36 37 38 39 40 41 42 |
# File 'lib/zenlish/parser/zparser.rb', line 36 def to_pforest(tokenSeq) result = earley_parse(tokenSeq) # puts result # Convert into a parse forest engine.to_pforest(result) end |