Class: Pdfrb::Arlington::Predicate::Parser
- Inherits:
-
Object
- Object
- Pdfrb::Arlington::Predicate::Parser
- Defined in:
- lib/pdfrb/arlington/predicate/parser.rb
Overview
Recursive-descent parser. Builds AST from tokens. Per the
Arlington grammar: && and || must be fully parenthesised
(no precedence); we enforce that by only accepting them inside
(...) groups.
Instance Attribute Summary collapse
-
#ast ⇒ Object
readonly
Returns the value of attribute ast.
-
#tokens ⇒ Object
readonly
Returns the value of attribute tokens.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(tokens) ⇒ Parser
constructor
A new instance of Parser.
- #parse ⇒ Object
Constructor Details
#initialize(tokens) ⇒ Parser
Returns a new instance of Parser.
13 14 15 16 |
# File 'lib/pdfrb/arlington/predicate/parser.rb', line 13 def initialize(tokens) @tokens = tokens @pos = 0 end |
Instance Attribute Details
#ast ⇒ Object (readonly)
Returns the value of attribute ast.
11 12 13 |
# File 'lib/pdfrb/arlington/predicate/parser.rb', line 11 def ast @ast end |
#tokens ⇒ Object (readonly)
Returns the value of attribute tokens.
11 12 13 |
# File 'lib/pdfrb/arlington/predicate/parser.rb', line 11 def tokens @tokens end |
Class Method Details
Instance Method Details
#parse ⇒ Object
23 24 25 26 27 28 29 30 |
# File 'lib/pdfrb/arlington/predicate/parser.rb', line 23 def parse return nil if tokens.empty? node = parse_expr raise Pdfrb::SyntaxError, "trailing tokens at pos #{@pos}" unless eof? node end |