Class: Ibex::IR::Validator::AutomatonDocument

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

Overview

Structural and referential validation for a versioned Automaton 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 algorithm grammar_digest grammar states conflict_summary
].freeze
V2_ROOT_OPTIONAL =

: Array

%w[entry_states].freeze
STATE_REQUIRED =

: Array

%w[id items transitions actions gotos default_action conflicts].freeze
ACTION_TYPES =

: Array

%w[shift reduce accept error].freeze
RESOLUTION_KINDS =

: Array

%w[definition_order default_shift precedence associativity].freeze

Constants inherited from Base

Base::POSITION

Instance Method Summary collapse

Constructor Details

#initialize(data, version: data.fetch("schema_version")) ⇒ AutomatonDocument

Returns a new instance of AutomatonDocument.



23
24
25
26
27
28
# File 'lib/ibex/ir/validator/automaton.rb', line 23

def initialize(data, version: data.fetch("schema_version"))
  super()
  @data = data
  @version = version
  @states_by_id = {} #: Hash[Integer, Hash[String, untyped]]
end

Instance Method Details

#validateObject



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/ibex/ir/validator/automaton.rb', line 31

def validate
  record(@data, "$", ROOT_REQUIRED, @version >= 2 ? V2_ROOT_OPTIONAL : [])
  literal(@data["ibex_ir"], "$.ibex_ir", "automaton")
  literal(@data["schema_version"], "$.schema_version", @version)
  enum(@data["algorithm"], "$.algorithm", %w[slr lalr1 ielr1 lr1])
  validate_digest
  grammar = object(@data["grammar"], "$.grammar")
  literal(grammar["schema_version"], "$.grammar.schema_version", @version)
  @grammar = GrammarDocument.new(grammar, path: "$.grammar", version: @version).validate
  validate_state_records
  validate_entry_states
  validate_state_contents
  validate_conflict_summary
  self
end