Class: LLIP::Parser
- Inherits:
-
Object
- Object
- LLIP::Parser
- Defined in:
- lib/llip/parser.rb
Overview
It’s a facade of the LLIP library.
To use it subclass it and then use the methods: production, scope and token to build the parser and its scanner.
Defined Under Namespace
Modules: ClassMethods
Instance Attribute Summary collapse
-
#parser ⇒ Object
readonly
The parser of the Parser subclass.
-
#scanner ⇒ Object
readonly
The scanner of the Parser subclass.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize ⇒ Parser
constructor
A new instance of Parser.
-
#parse(source) ⇒ Object
Parse the source using the parser and the scanner.
Constructor Details
#initialize ⇒ Parser
26 27 28 29 30 |
# File 'lib/llip/parser.rb', line 26 def initialize @parser = self.class.parser.new @scanner = self.class.scanner.new @scanner = Buffer.new(@scanner) if self.class.lookahead end |
Instance Attribute Details
#parser ⇒ Object (readonly)
The parser of the Parser subclass. It’s created from the class returned from LLIP::Parser::ClassMethods.parser.
21 22 23 |
# File 'lib/llip/parser.rb', line 21 def parser @parser end |
#scanner ⇒ Object (readonly)
The scanner of the Parser subclass. It’s created from the class returned from LLIP::Parser::ClassMethods.scanner.
24 25 26 |
# File 'lib/llip/parser.rb', line 24 def scanner @scanner end |
Class Method Details
.inherited(other) ⇒ Object
15 16 17 18 |
# File 'lib/llip/parser.rb', line 15 def self.inherited(other) other.extend(ClassMethods) other.send(:init_parser) end |
Instance Method Details
#parse(source) ⇒ Object
Parse the source using the parser and the scanner.
See AbstractScanner#scan to know what is a valid source.
35 36 37 |
# File 'lib/llip/parser.rb', line 35 def parse(source) @parser.parse(@scanner.scan(source)) end |