Class: Logicality::Parser::SimpleParser

Inherits:
Object
  • Object
show all
Defined in:
lib/logicality/parser/simple_parser.rb

Overview

Parser that takes in a lexer and can take its parsed grammar and turn it into an abstract syntax tree.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(lexer) ⇒ SimpleParser

Returns a new instance of SimpleParser.

Raises:

  • (ArgumentError)


17
18
19
20
21
22
23
# File 'lib/logicality/parser/simple_parser.rb', line 17

def initialize(lexer)
  @lexer = lexer

  @current_token = lexer.next_token

  raise ArgumentError, 'Lexer must contain at least one token' if @current_token.nil?
end

Instance Attribute Details

#lexerObject (readonly)

Returns the value of attribute lexer.



15
16
17
# File 'lib/logicality/parser/simple_parser.rb', line 15

def lexer
  @lexer
end

Instance Method Details

#parseObject



25
26
27
# File 'lib/logicality/parser/simple_parser.rb', line 25

def parse
  expr
end