Class: SpotFeel::Parser

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

Constant Summary collapse

@@parser =
SpotFeelParser.new

Class Method Summary collapse

Class Method Details

.clean_tree(root_node) ⇒ Object



23
24
25
26
27
# File 'lib/spot_feel/parser.rb', line 23

def self.clean_tree(root_node)
  return if(root_node.elements.nil?)
  root_node.elements.delete_if{|node| node.class.name == "Treetop::Runtime::SyntaxNode" }
  root_node.elements.each {|node| self.clean_tree(node) }
end

.parse(expression, root: nil) ⇒ Object



11
12
13
14
15
# File 'lib/spot_feel/parser.rb', line 11

def self.parse(expression, root: nil)
  @@parser.parse(expression, root:).tap do |ast|
    raise SyntaxError, "Invalid expression: #{expression.inspect}" unless ast
  end
end

.parse_test(expression) ⇒ Object



17
18
19
20
21
# File 'lib/spot_feel/parser.rb', line 17

def self.parse_test(expression)
  @@parser.parse(expression || '-', root: :simple_unary_tests).tap do |ast|
    raise SyntaxError, "Invalid unary test: #{expression.inspect}" unless ast
  end
end