Class: LLIP::AbstractParser
- Inherits:
-
Object
- Object
- LLIP::AbstractParser
- Defined in:
- lib/llip/abstract_parser.rb
Overview
This class hide all the complexity of generating an building a parser. Ater subclassing it, it’s possible to use all the methods defined in AbstractParser::ClassMethods to specify the productions.
Direct Known Subclasses
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
Instance Method Summary collapse
- #[](key) ⇒ Object
- #[]=(key, value) ⇒ Object
-
#initialize ⇒ AbstractParser
constructor
A new instance of AbstractParser.
-
#parse(scanner) ⇒ Object
Parse the token generated from the scanner until it reaches the end.
- #productions ⇒ Object
-
#raise(*args) ⇒ Object
It raises a ParserError instead of a RuntimeError if no exception is given.
Constructor Details
#initialize ⇒ AbstractParser
Returns a new instance of AbstractParser.
17 18 19 |
# File 'lib/llip/abstract_parser.rb', line 17 def initialize @hash = {} end |
Class Method Details
.inherited(other) ⇒ Object
13 14 15 |
# File 'lib/llip/abstract_parser.rb', line 13 def self.inherited(other) other.extend(ClassMethods) end |
Instance Method Details
#[](key) ⇒ Object
31 32 33 |
# File 'lib/llip/abstract_parser.rb', line 31 def [](key) @hash[key] end |
#[]=(key, value) ⇒ Object
35 36 37 |
# File 'lib/llip/abstract_parser.rb', line 35 def []=(key,value) @hash[key] = value end |
#parse(scanner) ⇒ Object
Parse the token generated from the scanner until it reaches the end. See AbstractScanner to know how to develop a scanner.
27 28 29 |
# File 'lib/llip/abstract_parser.rb', line 27 def parse(scanner) raise "This method hasn't been compiled yet." end |
#productions ⇒ Object
21 22 23 |
# File 'lib/llip/abstract_parser.rb', line 21 def productions self.class.productions end |
#raise(*args) ⇒ Object
It raises a ParserError instead of a RuntimeError if no exception is given.
It’s public so it’s important to call it from the production definitions, to have the exception set to ParserError.
42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/llip/abstract_parser.rb', line 42 def raise(*args) if args.first.respond_to? :exception or not @scanner.respond_to? :current or @scanner.current == nil super(*args) else error = ParserError.new(@scanner.current,args.shift) backtrace = args.shift backtrace ||= caller(1) error.set_backtrace(backtrace) super error end end |