Class: Kumi::Core::RubyParser::Parser

Inherits:
Object
  • Object
show all
Includes:
ErrorReporting, Syntax
Defined in:
lib/kumi/core/ruby_parser/parser.rb

Overview

Main parser class for Ruby DSL

Instance Method Summary collapse

Methods included from ErrorReporting

#inferred_location, #raise_localized_error, #raise_syntax_error, #raise_type_error, #report_enhanced_error, #report_error, #report_semantic_error, #report_syntax_error, #report_type_error

Constructor Details

#initializeParser

Returns a new instance of Parser.



11
12
13
14
# File 'lib/kumi/core/ruby_parser/parser.rb', line 11

def initialize
  @context = BuildContext.new
  @interface = SchemaBuilder.new(@context)
end

Instance Method Details

#parse(&rule_block) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/kumi/core/ruby_parser/parser.rb', line 16

def parse(&rule_block)
  enable_refinements(rule_block)

  before_consts = ::Object.constants
  @interface.freeze # stop singleton hacks
  @interface.instance_eval(&rule_block)
  added = ::Object.constants - before_consts

  unless added.empty?
    raise Kumi::Core::Errors::SemanticError,
          "DSL cannot define global constants: #{added.join(', ')}"
  end

  build_syntax_tree
rescue ArgumentError => e
  handle_parse_error(e)
  raise
end