Class: Crisp::Parser

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

Overview

The Crisp parser

The parser uses treetop for defining the syntax (see crisp.treetop) For parsing crisp code (as string) call parse on a instance. The output of the parser can be evaluated by passing it to a Crisp runtime.

Instance Method Summary collapse

Constructor Details

#initializeParser

create a new treetop parser



11
12
13
# File 'lib/crisp/parser.rb', line 11

def initialize
  @parser = CrispParser.new
end

Instance Method Details

#parse(code) ⇒ Object

parse the code and return an abstract syntax tree (ast)

Raises:



16
17
18
19
20
21
22
# File 'lib/crisp/parser.rb', line 16

def parse(code)
  ast = @parser.parse(code)

  raise SyntaxError, "syntax error at : #{@parser.index}" if !ast

  ast
end