Module: Ibex::Runtime::CST::Validator
- Defined in:
- lib/ibex/runtime/cst/validator.rb,
sig/ibex/runtime/cst/validator.rbs
Overview
Validates schema-v1 CST documents while rebuilding all derived Green data.
Constant Summary collapse
- TOP_KEYS =
rubocop:disable Metrics/ModuleLength -- closed schema checks remain auditable in one boundary.
%w[ ibex_ir schema_version grammar_digest table_format state_count production_count trivia_policy kinds root memo ].freeze
- KIND_KEYS =
%w[ names terminal_range nonterminal_range named named_nonterminals trivia synthetic ].freeze
- KNOWN_FLAGS =
( Flags::CONTAINS_ERROR | Flags::CONTAINS_MISSING | Flags::CONTAINS_SKIPPED | Flags::HAS_ANNOTATION | Flags::SYNTHETIC | Flags::INCOMPLETE_INPUT )
Class Method Summary collapse
Instance Method Summary collapse
- #self?.array! ⇒ Array[json_value]
- #self?.decode_text ⇒ String
- #self?.exact_keys! ⇒ void
- #self?.fail_validation ⇒ bot
- #self?.flags! ⇒ Integer
- #self?.integer_integer_map! ⇒ Hash[Integer, Integer]
- #self?.integer_pair! ⇒ Array[Integer]
- #self?.load_element ⇒ GreenNode, GreenToken
- #self?.load_kinds ⇒ Kind
- #self?.load_memo ⇒ ParseMemo?
- #self?.load_memo_states ⇒ Array[Integer?]
- #self?.load_trivia ⇒ Array[GreenTrivia]
- #self?.nonnegative_integer! ⇒ Integer
- #self?.object! ⇒ json_object
- #self?.positive_integer! ⇒ Integer
- #self?.string! ⇒ String
- #self?.string_integer_map! ⇒ Hash[String, Integer]
- #self?.trivia_policy! ⇒ Symbol
- #self?.validate ⇒ SerializedTree
- #self?.validate_derived! ⇒ void
- #self?.validate_kind! ⇒ void
- #self?.validate_kind_metadata! ⇒ void
- #self?.validate_kind_range! ⇒ void
- #self?.validate_memo_length! ⇒ void
- #self?.value! ⇒ void
Class Method Details
.validate(source, grammar_digest: nil, state_count: nil, production_count: nil) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/ibex/runtime/cst/validator.rb', line 45 def validate(source, grammar_digest: nil, state_count: nil, production_count: nil) # rubocop:disable Metrics/MethodLength document = JSON.parse(source) #: json_value document = object!(document, "$") exact_keys!(document, TOP_KEYS, "$") value!(document, "ibex_ir", "cst", "$.ibex_ir") value!(document, "schema_version", 1, "$.schema_version") digest = string!(document.fetch("grammar_digest"), "$.grammar_digest") unless digest.match?(/\Asha256:[0-9a-f]{64}\z/) fail_validation(:invalid_digest, "$.grammar_digest", "expected a SHA-256 digest", actual: digest) end if grammar_digest && digest != grammar_digest fail_validation( :grammar_digest_mismatch, "$.grammar_digest", "grammar digest does not match", expected: grammar_digest, actual: digest ) end kinds = load_kinds(document.fetch("kinds")) root = load_element(document.fetch("root"), kinds, "$.root") fail_validation(:invalid_root, "$.root", "root must be a node") unless root.is_a?(GreenNode) validate_derived!(root, "$.root") document_state_count = nonnegative_integer!(document.fetch("state_count"), "$.state_count") document_production_count = nonnegative_integer!( document.fetch("production_count"), "$.production_count" ) memo = load_memo( document.fetch("memo"), root, digest, document_state_count, document_production_count, expected_state_count: state_count, expected_production_count: production_count ) SerializedTree.new( grammar_digest: digest, table_format: positive_integer!(document.fetch("table_format"), "$.table_format"), state_count: document_state_count, production_count: document_production_count, trivia_policy: trivia_policy!(document.fetch("trivia_policy"), "$.trivia_policy"), kinds: kinds, green_root: root, memo: memo ) rescue JSON::ParserError => e fail_validation(:invalid_json, "$", e.) rescue KeyError => e fail_validation(:missing_field, "$", e.) end |
Instance Method Details
#self?.array! ⇒ Array[json_value]
69 |
# File 'sig/ibex/runtime/cst/validator.rbs', line 69
def self?.array!: (json_value value, String path) -> Array[json_value]
|
#self?.decode_text ⇒ String
57 |
# File 'sig/ibex/runtime/cst/validator.rbs', line 57
def self?.decode_text: (json_value value, String path) -> String
|
#self?.exact_keys! ⇒ void
This method returns an undefined value.
102 |
# File 'sig/ibex/runtime/cst/validator.rbs', line 102
def self?.exact_keys!: (json_object value, Array[String] expected, String path) -> void
|
#self?.fail_validation ⇒ bot
108 |
# File 'sig/ibex/runtime/cst/validator.rbs', line 108
def self?.fail_validation: (Symbol code, String path, String message, ?expected: json_value, ?actual: json_value) -> bot
|
#self?.flags! ⇒ Integer
84 |
# File 'sig/ibex/runtime/cst/validator.rbs', line 84
def self?.flags!: (json_value value, String path) -> Integer
|
#self?.integer_integer_map! ⇒ Hash[Integer, Integer]
93 |
# File 'sig/ibex/runtime/cst/validator.rbs', line 93
def self?.integer_integer_map!: (json_value value, String path) -> Hash[Integer, Integer]
|
#self?.integer_pair! ⇒ Array[Integer]
87 |
# File 'sig/ibex/runtime/cst/validator.rbs', line 87
def self?.integer_pair!: (json_value value, String path) -> Array[Integer]
|
#self?.load_element ⇒ GreenNode, GreenToken
51 |
# File 'sig/ibex/runtime/cst/validator.rbs', line 51
def self?.load_element: (json_value value, Kind kinds, String path) -> (GreenNode | GreenToken)
|
#self?.load_kinds ⇒ Kind
38 |
# File 'sig/ibex/runtime/cst/validator.rbs', line 38
def self?.load_kinds: (json_value value) -> Kind
|
#self?.load_memo ⇒ ParseMemo?
42 |
# File 'sig/ibex/runtime/cst/validator.rbs', line 42
def self?.load_memo: (json_value value, GreenNode root, String digest, Integer state_count, Integer production_count, expected_state_count: Integer?, expected_production_count: Integer?) -> ParseMemo?
|
#self?.load_memo_states ⇒ Array[Integer?]
45 |
# File 'sig/ibex/runtime/cst/validator.rbs', line 45
def self?.load_memo_states: (json_value value, Integer state_count) -> Array[Integer?]
|
#self?.load_trivia ⇒ Array[GreenTrivia]
54 |
# File 'sig/ibex/runtime/cst/validator.rbs', line 54
def self?.load_trivia: (json_value value, Kind kinds, String path) -> Array[GreenTrivia]
|
#self?.nonnegative_integer! ⇒ Integer
75 |
# File 'sig/ibex/runtime/cst/validator.rbs', line 75
def self?.nonnegative_integer!: (json_value value, String path) -> Integer
|
#self?.object! ⇒ json_object
66 |
# File 'sig/ibex/runtime/cst/validator.rbs', line 66
def self?.object!: (json_value value, String path) -> json_object
|
#self?.positive_integer! ⇒ Integer
78 |
# File 'sig/ibex/runtime/cst/validator.rbs', line 78
def self?.positive_integer!: (json_value value, String path) -> Integer
|
#self?.string! ⇒ String
72 |
# File 'sig/ibex/runtime/cst/validator.rbs', line 72
def self?.string!: (json_value value, String path) -> String
|
#self?.string_integer_map! ⇒ Hash[String, Integer]
90 |
# File 'sig/ibex/runtime/cst/validator.rbs', line 90
def self?.string_integer_map!: (json_value value, String path) -> Hash[String, Integer]
|
#self?.trivia_policy! ⇒ Symbol
81 |
# File 'sig/ibex/runtime/cst/validator.rbs', line 81
def self?.trivia_policy!: (json_value value, String path) -> Symbol
|
#self?.validate ⇒ SerializedTree
35 |
# File 'sig/ibex/runtime/cst/validator.rbs', line 35
def self?.validate: (String source, ?grammar_digest: String?, ?state_count: Integer?, ?production_count: Integer?) -> SerializedTree
|
#self?.validate_derived! ⇒ void
This method returns an undefined value.
60 |
# File 'sig/ibex/runtime/cst/validator.rbs', line 60
def self?.validate_derived!: (GreenNode | GreenToken element, String path) -> void
|
#self?.validate_kind! ⇒ void
This method returns an undefined value.
63 |
# File 'sig/ibex/runtime/cst/validator.rbs', line 63
def self?.validate_kind!: (Integer kind, Kind kinds, String path) -> void
|
#self?.validate_kind_metadata! ⇒ void
This method returns an undefined value.
96 |
# File 'sig/ibex/runtime/cst/validator.rbs', line 96
def self?.validate_kind_metadata!: (Kind::metadata metadata) -> void
|
#self?.validate_kind_range! ⇒ void
This method returns an undefined value.
99 |
# File 'sig/ibex/runtime/cst/validator.rbs', line 99
def self?.validate_kind_range!: (Array[Integer] range, Integer limit, String path) -> void
|
#self?.validate_memo_length! ⇒ void
This method returns an undefined value.
48 |
# File 'sig/ibex/runtime/cst/validator.rbs', line 48
def self?.validate_memo_length!: (Array[Integer?] states, GreenNode root) -> void
|
#self?.value! ⇒ void
This method returns an undefined value.
105 |
# File 'sig/ibex/runtime/cst/validator.rbs', line 105
def self?.value!: (json_object value, String key, json_value expected, String path) -> void
|