Class: Philiprehberger::SafeExec::Parser
- Inherits:
-
Object
- Object
- Philiprehberger::SafeExec::Parser
- Defined in:
- lib/philiprehberger/safe_exec/parser.rb
Overview
Recursive descent parser that builds an AST from tokens
Instance Method Summary collapse
-
#initialize(tokens) ⇒ Parser
constructor
A new instance of Parser.
-
#parse ⇒ Hash
Parse the token stream into an AST node.
Constructor Details
#initialize(tokens) ⇒ Parser
Returns a new instance of Parser.
7 8 9 10 |
# File 'lib/philiprehberger/safe_exec/parser.rb', line 7 def initialize(tokens) @tokens = tokens @pos = 0 end |
Instance Method Details
#parse ⇒ Hash
Parse the token stream into an AST node
16 17 18 19 20 21 |
# File 'lib/philiprehberger/safe_exec/parser.rb', line 16 def parse node = parse_ternary raise Error, "unexpected token: #{current&.value}" if current node end |