Class: Philiprehberger::SafeExec::Parser

Inherits:
Object
  • Object
show all
Defined in:
lib/philiprehberger/safe_exec/parser.rb

Overview

Recursive descent parser that builds an AST from tokens

Instance Method Summary collapse

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

#parseHash

Parse the token stream into an AST node

Returns:

  • (Hash)

    the AST node

Raises:



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