Class: Ibex::IR::Validator::GrammarDocument

Inherits:
Base
  • Object
show all
Defined in:
lib/ibex/ir/validator/grammar.rb

Overview

Structural and referential validation for a current Grammar IR JSON object. rubocop:disable Metrics/ClassLength -- inline type contracts accompany one cohesive document validator.

Constant Summary collapse

ROOT_REQUIRED =
%w[
  ibex_ir schema_version class_name superclass start expect options symbols productions user_code
  conversions warnings source_provenance parser_contract
].freeze
ROOT_OPTIONAL =

: Array

%w[
  user_code_chunks expect_rr params printers tests recovery lexer mode starts
].freeze
SYMBOL_REQUIRED =

: Array

%w[id name kind reserved prec loc].freeze
SYMBOL_OPTIONAL =

: Array

%w[display_name semantic_type].freeze
SYMBOL_METADATA_REQUIRED =

: Array

%w[doc].freeze
PRODUCTION_REQUIRED =

: Array

%w[id lhs rhs action prec_override origin].freeze
PRODUCTION_METADATA_REQUIRED =

: Array

%w[doc expansion].freeze
ACTION_COMPOSITION_REQUIRED =

: Array

%w[composition].freeze
ORIGIN_KINDS =

: Array

%w[
  optional_expansion star_expansion plus_expansion separated_list_expansion group_expansion
].freeze
RUBY_KEYWORDS =

: Array

%w[
  __ENCODING__ __FILE__ __LINE__ alias and begin break case class def defined do else elsif end ensure false for
  if in module next nil not or redo rescue retry return self super then true undef unless until when while yield
].freeze

Constants inherited from Base

Base::POSITION

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data, path: "$", version: data.fetch("schema_version")) ⇒ GrammarDocument

Returns a new instance of GrammarDocument.



41
42
43
44
45
46
47
48
49
# File 'lib/ibex/ir/validator/grammar.rb', line 41

def initialize(data, path: "$", version: data.fetch("schema_version"))
  super()
  @data = data
  @path = path
  @version = version
  @symbols_by_id = {}
  @symbols_by_name = {}
  @productions_by_id = {}
end

Instance Attribute Details

#productions_by_idObject (readonly)

: Hash[Integer, json_object]



34
35
36
# File 'lib/ibex/ir/validator/grammar.rb', line 34

def productions_by_id
  @productions_by_id
end

#symbols_by_idObject (readonly)

: Array



32
33
34
# File 'lib/ibex/ir/validator/grammar.rb', line 32

def symbols_by_id
  @symbols_by_id
end

#symbols_by_nameObject (readonly)

: Hash[String, json_object]



33
34
35
# File 'lib/ibex/ir/validator/grammar.rb', line 33

def symbols_by_name
  @symbols_by_name
end

Instance Method Details

#validateObject



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/ibex/ir/validator/grammar.rb', line 52

def validate
  validate_root_record
  validate_envelope
  validate_header
  validate_options
  validate_parser_parameters_if_present
  validate_symbols
  
  validate_reserved_symbols
  validate_start
  validate_productions
  validate_string_map(@data["user_code"], "#{@path}.user_code")
  validate_string_map(@data["conversions"], "#{@path}.conversions")
  validate_warnings
  
  self
end