Class: DrgDSL::AstBuilder

Inherits:
Parslet::Transform
  • Object
show all
Defined in:
lib/drgdsl/ast_builder.rb

Class Method Summary collapse

Class Method Details

.broken_ast?(ast) ⇒ Boolean

Did we manage to build a correct AST?

Returns:

  • (Boolean)


51
52
53
# File 'lib/drgdsl/ast_builder.rb', line 51

def self.broken_ast?(ast)
  !ast.is_a?(Ast::Node)
end

.build(cst) ⇒ Node

Returns AST.

Parameters:

  • cst (Hash)

    CST-ish hash obtained from DrgParser.

Returns:

  • (Node)

    AST

Raises:



42
43
44
45
46
# File 'lib/drgdsl/ast_builder.rb', line 42

def self.build(cst)
  ast = new.apply(cst)
  raise UnknownCstError.new(cst, ast) if broken_ast?(ast)
  ast
end