ibex-runtime 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +95 -272
- data/lib/ibex/runtime/cst/green/node.rb +1 -1
- data/lib/ibex/runtime/cst/green/token.rb +1 -1
- data/lib/ibex/runtime/cst/green/trivia.rb +1 -1
- data/lib/ibex/runtime/cst/incremental/blender.rb +1 -1
- data/lib/ibex/runtime/cst/incremental/lexed_syntax.rb +2 -2
- data/lib/ibex/runtime/cst/incremental/parse_memo.rb +2 -2
- data/lib/ibex/runtime/cst/incremental/relexer.rb +3 -0
- data/lib/ibex/runtime/cst/incremental/session.rb +26 -2
- data/lib/ibex/runtime/cst/parse_result.rb +7 -7
- data/lib/ibex/runtime/cst/serialize.rb +6 -3
- data/lib/ibex/runtime/cst/syntax_node.rb +4 -4
- data/lib/ibex/runtime/cst/syntax_token.rb +5 -5
- data/lib/ibex/runtime/cst/typed_node.rb +1 -1
- data/lib/ibex/runtime/cst/validator.rb +40 -30
- data/lib/ibex/runtime/embedded_source.rb +98 -0
- data/lib/ibex/runtime/event.rb +7 -4
- data/lib/ibex/runtime/event_jsonl_tracer.rb +1 -1
- data/lib/ibex/runtime/event_sanitizer.rb +32 -26
- data/lib/ibex/runtime/generated_lexer.rb +23 -16
- data/lib/ibex/runtime/lexer_input.rb +1 -1
- data/lib/ibex/runtime/location_span.rb +15 -15
- data/lib/ibex/runtime/observation.rb +1 -1
- data/lib/ibex/runtime/parser.rb +309 -191
- data/lib/ibex/runtime/parser_sync_recovery.rb +19 -15
- data/lib/ibex/runtime/repair.rb +36 -5
- data/lib/ibex/runtime/repair_priority_queue.rb +10 -6
- data/lib/ibex/runtime/repair_search.rb +92 -29
- data/lib/ibex/runtime/syntax_repair.rb +490 -0
- data/lib/ibex/runtime/syntax_session.rb +416 -0
- data/lib/ibex/runtime/table_format.rb +1 -1
- data/lib/ibex/runtime/version.rb +1 -1
- data/lib/ibex/runtime.rb +2 -1
- data/lib/ibex/tables/compact.rb +16 -12
- data/lib/ibex/tables/compact_actions.rb +45 -33
- data/lib/ibex/tables/compact_productions.rb +18 -15
- data/sig/ibex/runtime/cst/green/node.rbs +2 -2
- data/sig/ibex/runtime/cst/green/token.rbs +2 -2
- data/sig/ibex/runtime/cst/green/trivia.rbs +2 -2
- data/sig/ibex/runtime/cst/incremental/blender.rbs +2 -2
- data/sig/ibex/runtime/cst/incremental/lexed_syntax.rbs +3 -3
- data/sig/ibex/runtime/cst/incremental/parse_memo.rbs +4 -4
- data/sig/ibex/runtime/cst/incremental/session.rbs +8 -2
- data/sig/ibex/runtime/cst/parse_result.rbs +9 -9
- data/sig/ibex/runtime/cst/serialize.rbs +8 -6
- data/sig/ibex/runtime/cst/syntax_node.rbs +6 -6
- data/sig/ibex/runtime/cst/syntax_token.rbs +10 -10
- data/sig/ibex/runtime/cst/typed_node.rbs +2 -2
- data/sig/ibex/runtime/cst/validator.rbs +46 -42
- data/sig/ibex/runtime/embedded_source.rbs +21 -0
- data/sig/ibex/runtime/event.rbs +7 -5
- data/sig/ibex/runtime/event_jsonl_tracer.rbs +1 -1
- data/sig/ibex/runtime/event_sanitizer.rbs +50 -44
- data/sig/ibex/runtime/generated_lexer.rbs +31 -24
- data/sig/ibex/runtime/lexer_input.rbs +2 -2
- data/sig/ibex/runtime/location_span.rbs +28 -28
- data/sig/ibex/runtime/observation.rbs +2 -2
- data/sig/ibex/runtime/parser.rbs +266 -252
- data/sig/ibex/runtime/parser_sync_recovery.rbs +15 -15
- data/sig/ibex/runtime/repair.rbs +28 -8
- data/sig/ibex/runtime/repair_priority_queue.rbs +9 -7
- data/sig/ibex/runtime/repair_search.rbs +38 -19
- data/sig/ibex/runtime/syntax_repair.rbs +177 -0
- data/sig/ibex/runtime/syntax_session.rbs +186 -0
- data/sig/ibex/tables/compact.rbs +12 -12
- data/sig/ibex/tables/compact_actions.rbs +10 -17
- data/sig/ibex/tables/compact_productions.rbs +19 -19
- metadata +12 -6
- data/lib/ibex/runtime/jsonl_tracer.rb +0 -75
- data/sig/ibex/runtime/jsonl_tracer.rbs +0 -42
|
@@ -10,6 +10,9 @@ module Ibex
|
|
|
10
10
|
|
|
11
11
|
# Stable JSON serialization for `ibex_cst` schema version 1.
|
|
12
12
|
module Serialize
|
|
13
|
+
# @rbs!
|
|
14
|
+
# type json_value = String | Integer | bool | nil | Array[json_value] | Hash[String, json_value]
|
|
15
|
+
|
|
13
16
|
SCHEMA_VERSION = 1 #: Integer
|
|
14
17
|
|
|
15
18
|
# @rbs (SyntaxNode | SerializedTree value, ?grammar_digest: String?, ?table_format: Integer?,
|
|
@@ -67,7 +70,7 @@ module Ibex
|
|
|
67
70
|
module_function :serialization_tree
|
|
68
71
|
private_class_method :serialization_tree
|
|
69
72
|
|
|
70
|
-
# @rbs (Kind kinds) -> Hash[String,
|
|
73
|
+
# @rbs (Kind kinds) -> Hash[String, json_value]
|
|
71
74
|
def kinds_document(kinds)
|
|
72
75
|
metadata = kinds.to_h
|
|
73
76
|
{
|
|
@@ -83,7 +86,7 @@ module Ibex
|
|
|
83
86
|
module_function :kinds_document
|
|
84
87
|
private_class_method :kinds_document
|
|
85
88
|
|
|
86
|
-
# @rbs (GreenNode | GreenToken element) -> Hash[String,
|
|
89
|
+
# @rbs (GreenNode | GreenToken element) -> Hash[String, json_value]
|
|
87
90
|
def element_document(element)
|
|
88
91
|
if element.is_a?(GreenNode)
|
|
89
92
|
raise SerializationError, "annotated Green nodes cannot be serialized" unless element.annotations.empty?
|
|
@@ -107,7 +110,7 @@ module Ibex
|
|
|
107
110
|
module_function :element_document
|
|
108
111
|
private_class_method :element_document
|
|
109
112
|
|
|
110
|
-
# @rbs (GreenTrivia trivia) -> Array[
|
|
113
|
+
# @rbs (GreenTrivia trivia) -> Array[json_value]
|
|
111
114
|
def trivia_document(trivia) = [trivia.kind, encode_text(trivia.text)]
|
|
112
115
|
module_function :trivia_document
|
|
113
116
|
private_class_method :trivia_document
|
|
@@ -348,7 +348,7 @@ module Ibex
|
|
|
348
348
|
root.equal?(other.root) && @green.equal?(other.green) && @offset == other.offset
|
|
349
349
|
end
|
|
350
350
|
|
|
351
|
-
# @rbs (
|
|
351
|
+
# @rbs (Object? other) -> bool
|
|
352
352
|
def ==(other)
|
|
353
353
|
other.is_a?(SyntaxNode) && @green == other.green
|
|
354
354
|
end
|
|
@@ -356,12 +356,12 @@ module Ibex
|
|
|
356
356
|
# @rbs () -> Array[element]
|
|
357
357
|
def deconstruct = children
|
|
358
358
|
|
|
359
|
-
# @rbs (Array[Symbol]?) -> Hash[Symbol,
|
|
359
|
+
# @rbs (Array[Symbol]?) -> Hash[Symbol, Object?]
|
|
360
360
|
def deconstruct_keys(_keys)
|
|
361
361
|
values = {
|
|
362
362
|
kind: :node, symbol: symbol, production_id: production_id, children: children,
|
|
363
363
|
location: location, trailing_trivia: trailing_trivia
|
|
364
|
-
} #: Hash[Symbol,
|
|
364
|
+
} #: Hash[Symbol, Object?]
|
|
365
365
|
@kinds.fields(kind).each do |name, slot|
|
|
366
366
|
index = slot.is_a?(Hash) ? slot.fetch(:index) : slot
|
|
367
367
|
values[name.to_sym] = child_at(index)
|
|
@@ -369,7 +369,7 @@ module Ibex
|
|
|
369
369
|
values.freeze
|
|
370
370
|
end
|
|
371
371
|
|
|
372
|
-
# @rbs () -> Hash[Symbol,
|
|
372
|
+
# @rbs () -> Hash[Symbol, Object?]
|
|
373
373
|
def to_h = deconstruct_keys(nil)
|
|
374
374
|
|
|
375
375
|
protected
|
|
@@ -45,7 +45,7 @@ module Ibex
|
|
|
45
45
|
# @rbs () -> Array[GreenTrivia]
|
|
46
46
|
def leading_trivia = @green.leading
|
|
47
47
|
|
|
48
|
-
# @rbs () -> Array[
|
|
48
|
+
# @rbs () -> Array[Object?]
|
|
49
49
|
def children = []
|
|
50
50
|
|
|
51
51
|
# @rbs () -> String
|
|
@@ -127,15 +127,15 @@ module Ibex
|
|
|
127
127
|
root.equal?(other.root) && @green.equal?(other.green) && @offset == other.offset
|
|
128
128
|
end
|
|
129
129
|
|
|
130
|
-
# @rbs (
|
|
130
|
+
# @rbs (Object? other) -> bool
|
|
131
131
|
def ==(other)
|
|
132
132
|
other.is_a?(SyntaxToken) && @green == other.green
|
|
133
133
|
end
|
|
134
134
|
|
|
135
|
-
# @rbs () -> Array[
|
|
135
|
+
# @rbs () -> Array[Object?]
|
|
136
136
|
def deconstruct = []
|
|
137
137
|
|
|
138
|
-
# @rbs (Array[Symbol]?) -> Hash[Symbol,
|
|
138
|
+
# @rbs (Array[Symbol]?) -> Hash[Symbol, Object?]
|
|
139
139
|
def deconstruct_keys(_keys)
|
|
140
140
|
{
|
|
141
141
|
kind: :token, symbol: symbol, value: value, location: location,
|
|
@@ -143,7 +143,7 @@ module Ibex
|
|
|
143
143
|
}.freeze
|
|
144
144
|
end
|
|
145
145
|
|
|
146
|
-
# @rbs () -> Hash[Symbol,
|
|
146
|
+
# @rbs () -> Hash[Symbol, Object?]
|
|
147
147
|
def to_h = deconstruct_keys(nil)
|
|
148
148
|
|
|
149
149
|
private
|
|
@@ -46,7 +46,7 @@ module Ibex
|
|
|
46
46
|
# @rbs () -> Array[element]
|
|
47
47
|
def deconstruct = @node.deconstruct
|
|
48
48
|
|
|
49
|
-
# @rbs (Array[Symbol]?) -> Hash[Symbol,
|
|
49
|
+
# @rbs (Array[Symbol]?) -> Hash[Symbol, Object?]
|
|
50
50
|
def deconstruct_keys(keys) = @node.deconstruct_keys(keys)
|
|
51
51
|
|
|
52
52
|
# @rbs () -> String
|
|
@@ -6,14 +6,18 @@ require "json"
|
|
|
6
6
|
module Ibex
|
|
7
7
|
module Runtime
|
|
8
8
|
module CST
|
|
9
|
+
# @rbs!
|
|
10
|
+
# type json_value = String | Integer | Float | bool | nil | Array[json_value] | Hash[String, json_value]
|
|
11
|
+
# type json_object = Hash[String, json_value]
|
|
12
|
+
|
|
9
13
|
# Structured failure raised for an invalid or incompatible CST document.
|
|
10
14
|
class ValidationError < StandardError
|
|
11
15
|
attr_reader :code #: Symbol
|
|
12
16
|
attr_reader :path #: String
|
|
13
|
-
attr_reader :expected #:
|
|
14
|
-
attr_reader :actual #:
|
|
17
|
+
attr_reader :expected #: json_value
|
|
18
|
+
attr_reader :actual #: json_value
|
|
15
19
|
|
|
16
|
-
# @rbs (code: Symbol, path: String, message: String, ?expected:
|
|
20
|
+
# @rbs (code: Symbol, path: String, message: String, ?expected: json_value, ?actual: json_value) -> void
|
|
17
21
|
def initialize(code:, path:, message:, expected: nil, actual: nil)
|
|
18
22
|
@code = code
|
|
19
23
|
@path = path.dup.freeze
|
|
@@ -39,8 +43,8 @@ module Ibex
|
|
|
39
43
|
# @rbs (String source, ?grammar_digest: String?, ?state_count: Integer?,
|
|
40
44
|
# ?production_count: Integer?) -> SerializedTree
|
|
41
45
|
def validate(source, grammar_digest: nil, state_count: nil, production_count: nil) # rubocop:disable Metrics/MethodLength
|
|
42
|
-
document = JSON.parse(source)
|
|
43
|
-
object!(document, "$")
|
|
46
|
+
document = JSON.parse(source) #: json_value
|
|
47
|
+
document = object!(document, "$")
|
|
44
48
|
exact_keys!(document, TOP_KEYS, "$")
|
|
45
49
|
value!(document, "ibex_ir", "cst", "$.ibex_ir")
|
|
46
50
|
value!(document, "schema_version", 1, "$.schema_version")
|
|
@@ -88,9 +92,9 @@ module Ibex
|
|
|
88
92
|
end
|
|
89
93
|
module_function :validate
|
|
90
94
|
|
|
91
|
-
# @rbs (
|
|
95
|
+
# @rbs (json_value value) -> Kind
|
|
92
96
|
def load_kinds(value)
|
|
93
|
-
object!(value, "$.kinds")
|
|
97
|
+
value = object!(value, "$.kinds")
|
|
94
98
|
exact_keys!(value, KIND_KEYS, "$.kinds")
|
|
95
99
|
names = array!(value.fetch("names"), "$.kinds.names").map.with_index do |name, index|
|
|
96
100
|
string!(name, "$.kinds.names[#{index}]")
|
|
@@ -112,13 +116,13 @@ module Ibex
|
|
|
112
116
|
module_function :load_kinds
|
|
113
117
|
private_class_method :load_kinds
|
|
114
118
|
|
|
115
|
-
# @rbs (
|
|
119
|
+
# @rbs (json_value value, GreenNode root, String digest, Integer state_count, Integer production_count,
|
|
116
120
|
# expected_state_count: Integer?, expected_production_count: Integer?) -> ParseMemo?
|
|
117
121
|
def load_memo(value, root, digest, state_count, production_count,
|
|
118
122
|
expected_state_count:, expected_production_count:)
|
|
119
123
|
return if value.nil?
|
|
120
124
|
|
|
121
|
-
object!(value, "$.memo")
|
|
125
|
+
value = object!(value, "$.memo")
|
|
122
126
|
exact_keys!(value, %w[version left_states], "$.memo")
|
|
123
127
|
value!(value, "version", ParseMemo::VERSION, "$.memo.version")
|
|
124
128
|
states = load_memo_states(value.fetch("left_states"), state_count)
|
|
@@ -136,7 +140,7 @@ module Ibex
|
|
|
136
140
|
module_function :load_memo
|
|
137
141
|
private_class_method :load_memo
|
|
138
142
|
|
|
139
|
-
# @rbs (
|
|
143
|
+
# @rbs (json_value value, Integer state_count) -> Array[Integer?]
|
|
140
144
|
def load_memo_states(value, state_count)
|
|
141
145
|
array!(value, "$.memo.left_states").map.with_index do |state, index|
|
|
142
146
|
next if state.nil?
|
|
@@ -171,9 +175,9 @@ module Ibex
|
|
|
171
175
|
module_function :validate_memo_length!
|
|
172
176
|
private_class_method :validate_memo_length!
|
|
173
177
|
|
|
174
|
-
# @rbs (
|
|
178
|
+
# @rbs (json_value value, Kind kinds, String path) -> (GreenNode | GreenToken)
|
|
175
179
|
def load_element(value, kinds, path)
|
|
176
|
-
object!(value, path)
|
|
180
|
+
value = object!(value, path)
|
|
177
181
|
kind = nonnegative_integer!(value.fetch("k"), "#{path}.k")
|
|
178
182
|
validate_kind!(kind, kinds, "#{path}.k")
|
|
179
183
|
flags = flags!(value.fetch("f"), "#{path}.f")
|
|
@@ -199,7 +203,7 @@ module Ibex
|
|
|
199
203
|
module_function :load_element
|
|
200
204
|
private_class_method :load_element
|
|
201
205
|
|
|
202
|
-
# @rbs (
|
|
206
|
+
# @rbs (json_value value, Kind kinds, String path) -> Array[GreenTrivia]
|
|
203
207
|
def load_trivia(value, kinds, path)
|
|
204
208
|
array!(value, path).map.with_index do |item, index|
|
|
205
209
|
pair = array!(item, "#{path}[#{index}]")
|
|
@@ -218,11 +222,11 @@ module Ibex
|
|
|
218
222
|
module_function :load_trivia
|
|
219
223
|
private_class_method :load_trivia
|
|
220
224
|
|
|
221
|
-
# @rbs (
|
|
225
|
+
# @rbs (json_value value, String path) -> String
|
|
222
226
|
def decode_text(value, path)
|
|
223
227
|
return value.b if value.is_a?(String)
|
|
224
228
|
|
|
225
|
-
object!(value, path)
|
|
229
|
+
value = object!(value, path)
|
|
226
230
|
exact_keys!(value, ["b64"], path)
|
|
227
231
|
encoded = string!(value.fetch("b64"), "#{path}.b64")
|
|
228
232
|
decoded = encoded.unpack1("m0")
|
|
@@ -266,25 +270,31 @@ module Ibex
|
|
|
266
270
|
module_function :validate_kind!
|
|
267
271
|
private_class_method :validate_kind!
|
|
268
272
|
|
|
269
|
-
# @rbs (
|
|
273
|
+
# @rbs (json_value value, String path) -> json_object
|
|
270
274
|
def object!(value, path)
|
|
271
|
-
|
|
275
|
+
if value.is_a?(Hash)
|
|
276
|
+
object = value #: json_object
|
|
277
|
+
return object
|
|
278
|
+
end
|
|
272
279
|
|
|
273
280
|
fail_validation(:invalid_type, path, "expected object", actual: value.class.name)
|
|
274
281
|
end
|
|
275
282
|
module_function :object!
|
|
276
283
|
private_class_method :object!
|
|
277
284
|
|
|
278
|
-
# @rbs (
|
|
285
|
+
# @rbs (json_value value, String path) -> Array[json_value]
|
|
279
286
|
def array!(value, path)
|
|
280
|
-
|
|
287
|
+
if value.is_a?(Array)
|
|
288
|
+
array = value #: Array[json_value]
|
|
289
|
+
return array
|
|
290
|
+
end
|
|
281
291
|
|
|
282
292
|
fail_validation(:invalid_type, path, "expected array", actual: value.class.name)
|
|
283
293
|
end
|
|
284
294
|
module_function :array!
|
|
285
295
|
private_class_method :array!
|
|
286
296
|
|
|
287
|
-
# @rbs (
|
|
297
|
+
# @rbs (json_value value, String path) -> String
|
|
288
298
|
def string!(value, path)
|
|
289
299
|
return value if value.is_a?(String)
|
|
290
300
|
|
|
@@ -293,7 +303,7 @@ module Ibex
|
|
|
293
303
|
module_function :string!
|
|
294
304
|
private_class_method :string!
|
|
295
305
|
|
|
296
|
-
# @rbs (
|
|
306
|
+
# @rbs (json_value value, String path) -> Integer
|
|
297
307
|
def nonnegative_integer!(value, path)
|
|
298
308
|
return value if value.is_a?(Integer) && !value.negative?
|
|
299
309
|
|
|
@@ -302,7 +312,7 @@ module Ibex
|
|
|
302
312
|
module_function :nonnegative_integer!
|
|
303
313
|
private_class_method :nonnegative_integer!
|
|
304
314
|
|
|
305
|
-
# @rbs (
|
|
315
|
+
# @rbs (json_value value, String path) -> Integer
|
|
306
316
|
def positive_integer!(value, path)
|
|
307
317
|
integer = nonnegative_integer!(value, path)
|
|
308
318
|
return integer if integer.positive?
|
|
@@ -312,7 +322,7 @@ module Ibex
|
|
|
312
322
|
module_function :positive_integer!
|
|
313
323
|
private_class_method :positive_integer!
|
|
314
324
|
|
|
315
|
-
# @rbs (
|
|
325
|
+
# @rbs (json_value value, String path) -> Symbol
|
|
316
326
|
def trivia_policy!(value, path)
|
|
317
327
|
policy = string!(value, path).to_sym
|
|
318
328
|
return policy if %i[leading balanced drop].include?(policy)
|
|
@@ -322,7 +332,7 @@ module Ibex
|
|
|
322
332
|
module_function :trivia_policy!
|
|
323
333
|
private_class_method :trivia_policy!
|
|
324
334
|
|
|
325
|
-
# @rbs (
|
|
335
|
+
# @rbs (json_value value, String path) -> Integer
|
|
326
336
|
def flags!(value, path)
|
|
327
337
|
flags = nonnegative_integer!(value, path)
|
|
328
338
|
fail_validation(:invalid_flags, path, "flags contain unknown bits", actual: flags) unless
|
|
@@ -334,7 +344,7 @@ module Ibex
|
|
|
334
344
|
module_function :flags!
|
|
335
345
|
private_class_method :flags!
|
|
336
346
|
|
|
337
|
-
# @rbs (
|
|
347
|
+
# @rbs (json_value value, String path) -> Array[Integer]
|
|
338
348
|
def integer_pair!(value, path)
|
|
339
349
|
pair = array!(value, path)
|
|
340
350
|
fail_validation(:invalid_type, path, "expected two integers") unless pair.length == 2
|
|
@@ -343,7 +353,7 @@ module Ibex
|
|
|
343
353
|
module_function :integer_pair!
|
|
344
354
|
private_class_method :integer_pair!
|
|
345
355
|
|
|
346
|
-
# @rbs (
|
|
356
|
+
# @rbs (json_value value, String path) -> Hash[String, Integer]
|
|
347
357
|
def string_integer_map!(value, path)
|
|
348
358
|
object!(value, path).to_h do |key, item|
|
|
349
359
|
[
|
|
@@ -355,7 +365,7 @@ module Ibex
|
|
|
355
365
|
module_function :string_integer_map!
|
|
356
366
|
private_class_method :string_integer_map!
|
|
357
367
|
|
|
358
|
-
# @rbs (
|
|
368
|
+
# @rbs (json_value value, String path) -> Hash[Integer, Integer]
|
|
359
369
|
def integer_integer_map!(value, path)
|
|
360
370
|
object!(value, path).to_h do |key, item|
|
|
361
371
|
integer_key = Integer(string!(key, "#{path}.<key>"), 10)
|
|
@@ -394,7 +404,7 @@ module Ibex
|
|
|
394
404
|
module_function :validate_kind_range!
|
|
395
405
|
private_class_method :validate_kind_range!
|
|
396
406
|
|
|
397
|
-
# @rbs (
|
|
407
|
+
# @rbs (json_object value, Array[String] expected, String path) -> void
|
|
398
408
|
def exact_keys!(value, expected, path)
|
|
399
409
|
actual = value.keys.sort
|
|
400
410
|
return if actual == expected.sort
|
|
@@ -404,7 +414,7 @@ module Ibex
|
|
|
404
414
|
module_function :exact_keys!
|
|
405
415
|
private_class_method :exact_keys!
|
|
406
416
|
|
|
407
|
-
# @rbs (
|
|
417
|
+
# @rbs (json_object value, String key, json_value expected, String path) -> void
|
|
408
418
|
def value!(value, key, expected, path)
|
|
409
419
|
actual = value.fetch(key)
|
|
410
420
|
return if actual == expected
|
|
@@ -414,7 +424,7 @@ module Ibex
|
|
|
414
424
|
module_function :value!
|
|
415
425
|
private_class_method :value!
|
|
416
426
|
|
|
417
|
-
# @rbs (Symbol code, String path, String message, ?expected:
|
|
427
|
+
# @rbs (Symbol code, String path, String message, ?expected: json_value, ?actual: json_value) -> bot
|
|
418
428
|
def fail_validation(code, path, message, expected: nil, actual: nil)
|
|
419
429
|
raise ValidationError.new(
|
|
420
430
|
code: code, path: path, message: message, expected: expected, actual: actual
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
# rbs_inline: enabled
|
|
3
|
+
|
|
4
|
+
module Ibex
|
|
5
|
+
module Runtime
|
|
6
|
+
# Assembles the installed runtime into one dependency-free Ruby source.
|
|
7
|
+
module EmbeddedSource
|
|
8
|
+
FILES = %w[
|
|
9
|
+
version.rb
|
|
10
|
+
table_format.rb
|
|
11
|
+
location_span.rb
|
|
12
|
+
cst/kind.rb
|
|
13
|
+
cst/annotation.rb
|
|
14
|
+
cst/green/trivia.rb
|
|
15
|
+
cst/green/token.rb
|
|
16
|
+
cst/green/node.rb
|
|
17
|
+
cst/green/cache.rb
|
|
18
|
+
cst/green/builder.rb
|
|
19
|
+
cst/source_text.rb
|
|
20
|
+
cst/syntax_token.rb
|
|
21
|
+
cst/syntax_node.rb
|
|
22
|
+
cst/cursor.rb
|
|
23
|
+
cst/typed_node.rb
|
|
24
|
+
cst/parse_result.rb
|
|
25
|
+
cst/editing.rb
|
|
26
|
+
cst/text_edit.rb
|
|
27
|
+
cst/rewriter.rb
|
|
28
|
+
cst/editor.rb
|
|
29
|
+
cst/diff.rb
|
|
30
|
+
cst/serialized_tree.rb
|
|
31
|
+
cst/validator.rb
|
|
32
|
+
cst/serialize.rb
|
|
33
|
+
cst/incremental/token_memo.rb
|
|
34
|
+
cst/incremental/relexer.rb
|
|
35
|
+
cst/incremental/parse_memo.rb
|
|
36
|
+
cst/incremental/lexed_syntax.rb
|
|
37
|
+
cst/incremental/blender.rb
|
|
38
|
+
cst/incremental/session.rb
|
|
39
|
+
cst.rb
|
|
40
|
+
ast_data.rb
|
|
41
|
+
resource_limits.rb
|
|
42
|
+
event_sanitizer.rb
|
|
43
|
+
syntax_session.rb
|
|
44
|
+
event.rb
|
|
45
|
+
observation.rb
|
|
46
|
+
repair.rb
|
|
47
|
+
repair_priority_queue.rb
|
|
48
|
+
repair_search.rb
|
|
49
|
+
syntax_repair.rb
|
|
50
|
+
parser_sync_recovery.rb
|
|
51
|
+
parser.rb
|
|
52
|
+
lexer_input.rb
|
|
53
|
+
generated_lexer.rb
|
|
54
|
+
event_jsonl_tracer.rb
|
|
55
|
+
../tables/compact.rb
|
|
56
|
+
../tables/compact_actions.rb
|
|
57
|
+
../tables/compact_productions.rb
|
|
58
|
+
].freeze #: Array[String]
|
|
59
|
+
REQUIRE_RELATIVE = /^\s*require_relative\s+["']([^"']+)["']/
|
|
60
|
+
private_constant :FILES, :REQUIRE_RELATIVE
|
|
61
|
+
|
|
62
|
+
# @rbs () -> String
|
|
63
|
+
def self.render
|
|
64
|
+
paths = FILES.map { |relative_path| File.expand_path(relative_path, File.dirname(__FILE__)) }
|
|
65
|
+
validate_manifest!(paths)
|
|
66
|
+
paths.map { |path| source(path) }.join("\n")
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
# @rbs (Array[String] paths) -> void
|
|
70
|
+
def self.validate_manifest!(paths)
|
|
71
|
+
raise "embedded runtime manifest contains duplicate files" unless paths.uniq.length == paths.length
|
|
72
|
+
|
|
73
|
+
positions = paths.each_with_index.to_h
|
|
74
|
+
paths.each_with_index do |path, position|
|
|
75
|
+
raise "embedded runtime source is missing: #{path}" unless File.file?(path)
|
|
76
|
+
|
|
77
|
+
File.foreach(path) do |line|
|
|
78
|
+
match = REQUIRE_RELATIVE.match(line)
|
|
79
|
+
next unless match
|
|
80
|
+
|
|
81
|
+
dependency = File.expand_path("#{match[1]}.rb", File.dirname(path))
|
|
82
|
+
dependency_position = positions[dependency]
|
|
83
|
+
next if dependency_position && dependency_position < position
|
|
84
|
+
|
|
85
|
+
raise "embedded runtime dependency must precede #{path}: #{dependency}"
|
|
86
|
+
end
|
|
87
|
+
end
|
|
88
|
+
end
|
|
89
|
+
private_class_method :validate_manifest!
|
|
90
|
+
|
|
91
|
+
# @rbs (String path) -> String
|
|
92
|
+
def self.source(path)
|
|
93
|
+
File.read(path).lines.reject { |line| line.start_with?("# frozen_string_literal:") }.join.rstrip
|
|
94
|
+
end
|
|
95
|
+
private_class_method :source
|
|
96
|
+
end
|
|
97
|
+
end
|
|
98
|
+
end
|
data/lib/ibex/runtime/event.rb
CHANGED
|
@@ -7,6 +7,9 @@ module Ibex
|
|
|
7
7
|
module Runtime
|
|
8
8
|
# One immutable versioned parser observation.
|
|
9
9
|
class Event
|
|
10
|
+
# @rbs!
|
|
11
|
+
# type json_value = String | Integer | Float | bool | nil | Array[json_value] | Hash[String, json_value]
|
|
12
|
+
|
|
10
13
|
SCHEMA_VERSION = 1 #: Integer
|
|
11
14
|
IDENTIFIER = "runtime-event" #: String
|
|
12
15
|
TYPES = %i[
|
|
@@ -15,9 +18,9 @@ module Ibex
|
|
|
15
18
|
|
|
16
19
|
attr_reader :type #: Symbol
|
|
17
20
|
attr_reader :sequence #: Integer
|
|
18
|
-
attr_reader :data #: Hash[String,
|
|
21
|
+
attr_reader :data #: Hash[String, json_value]
|
|
19
22
|
|
|
20
|
-
# @rbs (type: Symbol, sequence: Integer, data: Hash[
|
|
23
|
+
# @rbs (type: Symbol, sequence: Integer, data: Hash[Object?, Object?]) -> void
|
|
21
24
|
def initialize(type:, sequence:, data:)
|
|
22
25
|
raise ArgumentError, "unknown runtime event type #{type.inspect}" unless TYPES.include?(type)
|
|
23
26
|
raise ArgumentError, "runtime event sequence must be positive" unless sequence.positive?
|
|
@@ -31,11 +34,11 @@ module Ibex
|
|
|
31
34
|
"sequence" => @sequence,
|
|
32
35
|
"event" => @type.to_s.freeze,
|
|
33
36
|
"data" => @data
|
|
34
|
-
}.freeze #: Hash[String,
|
|
37
|
+
}.freeze #: Hash[String, json_value]
|
|
35
38
|
freeze
|
|
36
39
|
end
|
|
37
40
|
|
|
38
|
-
# @rbs () -> Hash[String,
|
|
41
|
+
# @rbs () -> Hash[String, json_value]
|
|
39
42
|
def to_h
|
|
40
43
|
@document
|
|
41
44
|
end
|