ibex-runtime 0.2.0 → 0.4.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.
Files changed (71) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +100 -272
  3. data/lib/ibex/runtime/cst/green/node.rb +1 -1
  4. data/lib/ibex/runtime/cst/green/token.rb +1 -1
  5. data/lib/ibex/runtime/cst/green/trivia.rb +1 -1
  6. data/lib/ibex/runtime/cst/incremental/blender.rb +1 -1
  7. data/lib/ibex/runtime/cst/incremental/lexed_syntax.rb +2 -2
  8. data/lib/ibex/runtime/cst/incremental/parse_memo.rb +2 -2
  9. data/lib/ibex/runtime/cst/incremental/relexer.rb +3 -0
  10. data/lib/ibex/runtime/cst/incremental/session.rb +26 -2
  11. data/lib/ibex/runtime/cst/parse_result.rb +7 -7
  12. data/lib/ibex/runtime/cst/serialize.rb +6 -3
  13. data/lib/ibex/runtime/cst/syntax_node.rb +4 -4
  14. data/lib/ibex/runtime/cst/syntax_token.rb +5 -5
  15. data/lib/ibex/runtime/cst/typed_node.rb +1 -1
  16. data/lib/ibex/runtime/cst/validator.rb +40 -30
  17. data/lib/ibex/runtime/embedded_source.rb +98 -0
  18. data/lib/ibex/runtime/event.rb +7 -4
  19. data/lib/ibex/runtime/event_jsonl_tracer.rb +1 -1
  20. data/lib/ibex/runtime/event_sanitizer.rb +32 -26
  21. data/lib/ibex/runtime/generated_lexer.rb +23 -16
  22. data/lib/ibex/runtime/lexer_input.rb +1 -1
  23. data/lib/ibex/runtime/location_span.rb +15 -15
  24. data/lib/ibex/runtime/observation.rb +1 -1
  25. data/lib/ibex/runtime/parser.rb +309 -191
  26. data/lib/ibex/runtime/parser_sync_recovery.rb +19 -15
  27. data/lib/ibex/runtime/repair.rb +36 -5
  28. data/lib/ibex/runtime/repair_priority_queue.rb +10 -6
  29. data/lib/ibex/runtime/repair_search.rb +92 -29
  30. data/lib/ibex/runtime/syntax_repair.rb +490 -0
  31. data/lib/ibex/runtime/syntax_session.rb +416 -0
  32. data/lib/ibex/runtime/table_format.rb +1 -1
  33. data/lib/ibex/runtime/version.rb +1 -1
  34. data/lib/ibex/runtime.rb +2 -1
  35. data/lib/ibex/tables/compact.rb +16 -12
  36. data/lib/ibex/tables/compact_actions.rb +45 -33
  37. data/lib/ibex/tables/compact_productions.rb +18 -15
  38. data/sig/ibex/runtime/cst/green/node.rbs +2 -2
  39. data/sig/ibex/runtime/cst/green/token.rbs +2 -2
  40. data/sig/ibex/runtime/cst/green/trivia.rbs +2 -2
  41. data/sig/ibex/runtime/cst/incremental/blender.rbs +2 -2
  42. data/sig/ibex/runtime/cst/incremental/lexed_syntax.rbs +3 -3
  43. data/sig/ibex/runtime/cst/incremental/parse_memo.rbs +4 -4
  44. data/sig/ibex/runtime/cst/incremental/session.rbs +8 -2
  45. data/sig/ibex/runtime/cst/parse_result.rbs +9 -9
  46. data/sig/ibex/runtime/cst/serialize.rbs +8 -6
  47. data/sig/ibex/runtime/cst/syntax_node.rbs +6 -6
  48. data/sig/ibex/runtime/cst/syntax_token.rbs +10 -10
  49. data/sig/ibex/runtime/cst/typed_node.rbs +2 -2
  50. data/sig/ibex/runtime/cst/validator.rbs +46 -42
  51. data/sig/ibex/runtime/embedded_source.rbs +21 -0
  52. data/sig/ibex/runtime/event.rbs +7 -5
  53. data/sig/ibex/runtime/event_jsonl_tracer.rbs +1 -1
  54. data/sig/ibex/runtime/event_sanitizer.rbs +50 -44
  55. data/sig/ibex/runtime/generated_lexer.rbs +31 -24
  56. data/sig/ibex/runtime/lexer_input.rbs +2 -2
  57. data/sig/ibex/runtime/location_span.rbs +28 -28
  58. data/sig/ibex/runtime/observation.rbs +2 -2
  59. data/sig/ibex/runtime/parser.rbs +266 -252
  60. data/sig/ibex/runtime/parser_sync_recovery.rbs +15 -15
  61. data/sig/ibex/runtime/repair.rbs +28 -8
  62. data/sig/ibex/runtime/repair_priority_queue.rbs +9 -7
  63. data/sig/ibex/runtime/repair_search.rbs +38 -19
  64. data/sig/ibex/runtime/syntax_repair.rbs +177 -0
  65. data/sig/ibex/runtime/syntax_session.rbs +186 -0
  66. data/sig/ibex/tables/compact.rbs +12 -12
  67. data/sig/ibex/tables/compact_actions.rbs +10 -17
  68. data/sig/ibex/tables/compact_productions.rbs +19 -19
  69. metadata +12 -6
  70. data/lib/ibex/runtime/jsonl_tracer.rb +0 -75
  71. data/sig/ibex/runtime/jsonl_tracer.rbs +0 -42
@@ -28,18 +28,18 @@ module Ibex
28
28
 
29
29
  attr_reader offsets: Array[Integer]
30
30
 
31
- attr_reader values: Array[untyped]
31
+ attr_reader values: Array[Object?]
32
32
 
33
33
  attr_reader checks: Array[Integer?]
34
34
 
35
35
  attr_reader row_count: Integer
36
36
 
37
- attr_reader dense_values: Array[untyped]?
37
+ attr_reader dense_values: Array[Object?]?
38
38
 
39
39
  attr_reader dense_width: Integer?
40
40
 
41
- # @rbs (Array[Hash[Integer, untyped]] rows, ?dense: bool) -> Compact
42
- def self.build: (Array[Hash[Integer, untyped]] rows, ?dense: bool) -> Compact
41
+ # @rbs (Array[Hash[Integer, Object?]] rows, ?dense: bool) -> Compact
42
+ def self.build: (Array[Hash[Integer, Object?]] rows, ?dense: bool) -> Compact
43
43
 
44
44
  # @rbs (String offsets, String values, String checks, row_count: Integer,
45
45
  # ?dense_width: Integer?) -> Compact
@@ -48,23 +48,23 @@ module Ibex
48
48
  # @rbs (Array[Integer] columns, Array[Integer?] checks, Hash[Array[Integer], Integer] next_offsets) -> Integer
49
49
  private def self.find_offset: (Array[Integer] columns, Array[Integer?] checks, Hash[Array[Integer], Integer] next_offsets) -> Integer
50
50
 
51
- # @rbs (offsets: Array[Integer], values: Array[untyped], checks: Array[Integer?],
51
+ # @rbs (offsets: Array[Integer], values: Array[Object?], checks: Array[Integer?],
52
52
  # row_count: Integer, ?dense_width: Integer?) -> void
53
- def self?.initialize: (offsets: Array[Integer], values: Array[untyped], checks: Array[Integer?], row_count: Integer, ?dense_width: Integer?) -> void
53
+ def initialize: (offsets: Array[Integer], values: Array[Object?], checks: Array[Integer?], row_count: Integer, ?dense_width: Integer?) -> void
54
54
 
55
55
  # Keep predicate dispatch out of this lookup because every parser action
56
56
  # and goto crosses it.
57
57
  # rubocop:disable Style/NumericPredicate
58
- # @rbs (Integer row, Integer column) -> untyped
59
- def self?.lookup: (Integer row, Integer column) -> untyped
58
+ # @rbs (Integer row, Integer column) -> Object?
59
+ def lookup: (Integer row, Integer column) -> Object?
60
60
 
61
- # @rbs (Integer row) -> Hash[Integer, untyped]
62
- def self?.row: (Integer row) -> Hash[Integer, untyped]
61
+ # @rbs (Integer row) -> Hash[Integer, Object?]
62
+ def row: (Integer row) -> Hash[Integer, Object?]
63
63
 
64
64
  private
65
65
 
66
- # @rbs (Integer? dense_width) -> Array[untyped]?
67
- def self?.dense_layout: (Integer? dense_width) -> Array[untyped]?
66
+ # @rbs (Integer? dense_width) -> Array[Object?]?
67
+ def dense_layout: (Integer? dense_width) -> Array[Object?]?
68
68
  end
69
69
  end
70
70
  end
@@ -13,40 +13,33 @@ module Ibex
13
13
 
14
14
  REDUCE_BASE: Integer
15
15
 
16
- LEGACY_ERROR_CODE: Integer
17
-
18
- LEGACY_SHIFT_BASE: Integer
19
-
20
- LEGACY_REDUCE_BASE: Integer
21
-
22
16
  attr_reader codes: Array[Integer?]
23
17
 
24
18
  attr_reader dense_codes: Array[Integer?]?
25
19
 
26
20
  attr_reader column_count: Integer?
27
21
 
28
- # @rbs (Array[Hash[Integer, untyped]] rows) -> CompactActions
29
- def self.build: (Array[Hash[Integer, untyped]] rows) -> CompactActions
22
+ # @rbs (Array[Hash[Integer, IR::runtime_action]] rows) -> CompactActions
23
+ def self.build: (Array[Hash[Integer, IR::runtime_action]] rows) -> CompactActions
30
24
 
31
25
  # @rbs (String offsets, String codes, String checks, row_count: Integer,
32
26
  # ?encoding: Symbol, ?column_count: Integer?) -> CompactActions
33
27
  def self.packed: (String offsets, String codes, String checks, row_count: Integer, ?encoding: Symbol, ?column_count: Integer?) -> CompactActions
34
28
 
35
- # @rbs (untyped action) -> Integer?
36
- def self.pack: (untyped action) -> Integer?
29
+ # @rbs (IR::runtime_action? action) -> Integer?
30
+ def self.pack: (IR::runtime_action? action) -> Integer?
37
31
 
38
- # @rbs (Integer? code) -> untyped
39
- def self.unpack: (Integer? code) -> untyped
40
-
41
- # Convert codes emitted before signed compact actions without changing
42
- # their generated table literals.
43
- # @rbs (Integer? code) -> Integer?
44
- def self.legacy_to_signed: (Integer? code) -> Integer?
32
+ # @rbs (Integer? code) -> IR::runtime_action?
33
+ def self.unpack: (Integer? code) -> IR::runtime_action?
45
34
 
46
35
  # @rbs (offsets: Array[Integer], codes: Array[Integer?], checks: Array[Integer?],
47
36
  # row_count: Integer, ?encoding: Symbol, ?column_count: Integer?) -> void
48
37
  def initialize: (offsets: Array[Integer], codes: Array[Integer?], checks: Array[Integer?], row_count: Integer, ?encoding: Symbol, ?column_count: Integer?) -> void
49
38
 
39
+ # @rbs (Integer row) -> Hash[Integer, IR::runtime_action]
40
+ # rubocop:disable Lint/UselessMethodDefinition -- narrows the inherited row contract for typed parser actions.
41
+ def row: (Integer row) -> Hash[Integer, IR::runtime_action]
42
+
50
43
  private
51
44
 
52
45
  # @rbs (Array[Integer] offsets, Array[Integer?] codes, Array[Integer?] checks,
@@ -4,7 +4,7 @@ module Ibex
4
4
  module Tables
5
5
  # Production metadata with parallel primitive arrays for the direct parser
6
6
  # and a compatible Array-of-Hash surface for generic runtime consumers.
7
- class CompactProductions < Array[Hash[Symbol, untyped]]
7
+ class CompactProductions < Array[Hash[Symbol, Object?]]
8
8
  VALUES_ACTION: Integer
9
9
 
10
10
  BORROWED_VALUES_ACTION: Integer
@@ -27,42 +27,42 @@ module Ibex
27
27
 
28
28
  attr_reader flags: Array[Integer]
29
29
 
30
- # @rbs (Array[Hash[Symbol, untyped]] productions) -> CompactProductions
31
- def self.build: (Array[Hash[Symbol, untyped]] productions) -> CompactProductions
30
+ # @rbs (Array[Hash[Symbol, Object?]] productions) -> CompactProductions
31
+ def self.build: (Array[Hash[Symbol, Object?]] productions) -> CompactProductions
32
32
 
33
33
  # @rbs (String lhs_ids, String lengths, String flags,
34
- # ?metadata: Hash[Integer, Hash[Symbol, untyped]]) -> CompactProductions
35
- def self.packed: (String lhs_ids, String lengths, String flags, ?metadata: Hash[Integer, Hash[Symbol, untyped]]) -> CompactProductions
34
+ # ?metadata: Hash[Integer, Hash[Symbol, Object?]]) -> CompactProductions
35
+ def self.packed: (String lhs_ids, String lengths, String flags, ?metadata: Hash[Integer, Hash[Symbol, Object?]]) -> CompactProductions
36
36
 
37
- # @rbs (Hash[Symbol, untyped] production) -> Integer
38
- private def self.flags_for: (Hash[Symbol, untyped] production) -> Integer
37
+ # @rbs (Hash[Symbol, Object?] production) -> Integer
38
+ private def self.flags_for: (Hash[Symbol, Object?] production) -> Integer
39
39
 
40
40
  # @rbs (lhs_ids: Array[Integer], lengths: Array[Integer], actions: Array[Symbol?],
41
- # flags: Array[Integer], ?metadata: Hash[Integer, Hash[Symbol, untyped]]) -> void
42
- def initialize: (lhs_ids: Array[Integer], lengths: Array[Integer], actions: Array[Symbol?], flags: Array[Integer], ?metadata: Hash[Integer, Hash[Symbol, untyped]]) -> void
41
+ # flags: Array[Integer], ?metadata: Hash[Integer, Hash[Symbol, Object?]]) -> void
42
+ def initialize: (lhs_ids: Array[Integer], lengths: Array[Integer], actions: Array[Symbol?], flags: Array[Integer], ?metadata: Hash[Integer, Hash[Symbol, Object?]]) -> void
43
43
 
44
44
  # @rbs () -> bool
45
45
  def direct_values?: () -> bool
46
46
 
47
47
  private
48
48
 
49
- # @rbs (untyped value, String name) -> Integer
50
- def nonnegative_integer!: (untyped value, String name) -> Integer
49
+ # @rbs (Object? value, String name) -> Integer
50
+ def nonnegative_integer!: (Object? value, String name) -> Integer
51
51
 
52
- # @rbs (untyped value) -> Symbol?
53
- def action!: (untyped value) -> Symbol?
52
+ # @rbs (Object? value) -> Symbol?
53
+ def action!: (Object? value) -> Symbol?
54
54
 
55
- # @rbs (untyped value) -> Integer
56
- def flags!: (untyped value) -> Integer
55
+ # @rbs (Object? value) -> Integer
56
+ def flags!: (Object? value) -> Integer
57
57
 
58
58
  # @rbs () -> void
59
59
  def validate_markers!: () -> void
60
60
 
61
- # @rbs (Hash[Integer, Hash[Symbol, untyped]] metadata, Integer size) -> void
62
- def validate_metadata!: (Hash[Integer, Hash[Symbol, untyped]] metadata, Integer size) -> void
61
+ # @rbs (Hash[Integer, Hash[Symbol, Object?]] metadata, Integer size) -> void
62
+ def validate_metadata!: (Hash[Integer, Hash[Symbol, Object?]] metadata, Integer size) -> void
63
63
 
64
- # @rbs (Integer index, Hash[Symbol, untyped]? metadata) -> Hash[Symbol, untyped]
65
- def decode: (Integer index, Hash[Symbol, untyped]? metadata) -> Hash[Symbol, untyped]
64
+ # @rbs (Integer index, Hash[Symbol, Object?]? metadata) -> Hash[Symbol, Object?]
65
+ def decode: (Integer index, Hash[Symbol, Object?]? metadata) -> Hash[Symbol, Object?]
66
66
  end
67
67
  end
68
68
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ibex-runtime
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yudai Takada
@@ -49,11 +49,11 @@ files:
49
49
  - lib/ibex/runtime/cst/text_edit.rb
50
50
  - lib/ibex/runtime/cst/typed_node.rb
51
51
  - lib/ibex/runtime/cst/validator.rb
52
+ - lib/ibex/runtime/embedded_source.rb
52
53
  - lib/ibex/runtime/event.rb
53
54
  - lib/ibex/runtime/event_jsonl_tracer.rb
54
55
  - lib/ibex/runtime/event_sanitizer.rb
55
56
  - lib/ibex/runtime/generated_lexer.rb
56
- - lib/ibex/runtime/jsonl_tracer.rb
57
57
  - lib/ibex/runtime/lexer_input.rb
58
58
  - lib/ibex/runtime/location_span.rb
59
59
  - lib/ibex/runtime/observation.rb
@@ -63,6 +63,8 @@ files:
63
63
  - lib/ibex/runtime/repair_priority_queue.rb
64
64
  - lib/ibex/runtime/repair_search.rb
65
65
  - lib/ibex/runtime/resource_limits.rb
66
+ - lib/ibex/runtime/syntax_repair.rb
67
+ - lib/ibex/runtime/syntax_session.rb
66
68
  - lib/ibex/runtime/table_format.rb
67
69
  - lib/ibex/runtime/version.rb
68
70
  - lib/ibex/tables/compact.rb
@@ -98,11 +100,11 @@ files:
98
100
  - sig/ibex/runtime/cst/text_edit.rbs
99
101
  - sig/ibex/runtime/cst/typed_node.rbs
100
102
  - sig/ibex/runtime/cst/validator.rbs
103
+ - sig/ibex/runtime/embedded_source.rbs
101
104
  - sig/ibex/runtime/event.rbs
102
105
  - sig/ibex/runtime/event_jsonl_tracer.rbs
103
106
  - sig/ibex/runtime/event_sanitizer.rbs
104
107
  - sig/ibex/runtime/generated_lexer.rbs
105
- - sig/ibex/runtime/jsonl_tracer.rbs
106
108
  - sig/ibex/runtime/lexer_input.rbs
107
109
  - sig/ibex/runtime/location_span.rbs
108
110
  - sig/ibex/runtime/observation.rbs
@@ -112,17 +114,21 @@ files:
112
114
  - sig/ibex/runtime/repair_priority_queue.rbs
113
115
  - sig/ibex/runtime/repair_search.rbs
114
116
  - sig/ibex/runtime/resource_limits.rbs
117
+ - sig/ibex/runtime/syntax_repair.rbs
118
+ - sig/ibex/runtime/syntax_session.rbs
115
119
  - sig/ibex/runtime/table_format.rbs
116
120
  - sig/ibex/runtime/version.rbs
117
121
  - sig/ibex/tables/compact.rbs
118
122
  - sig/ibex/tables/compact_actions.rbs
119
123
  - sig/ibex/tables/compact_productions.rbs
120
- homepage: https://github.com/ydah/ibex
124
+ homepage: https://ydah.github.io/ibex/
121
125
  licenses:
122
126
  - MIT
123
127
  metadata:
124
- homepage_uri: https://github.com/ydah/ibex
125
- source_code_uri: https://github.com/ydah/ibex/tree/main
128
+ homepage_uri: https://ydah.github.io/ibex/
129
+ source_code_uri: https://github.com/ydah/ibex
130
+ documentation_uri: https://ydah.github.io/ibex/api/
131
+ bug_tracker_uri: https://github.com/ydah/ibex/issues
126
132
  rubygems_mfa_required: 'true'
127
133
  rdoc_options: []
128
134
  require_paths:
@@ -1,75 +0,0 @@
1
- # frozen_string_literal: true
2
- # rbs_inline: enabled
3
-
4
- require "json"
5
-
6
- module Ibex
7
- module Runtime
8
- # Emits committed parser observer events as JSON Lines.
9
- module JSONLTracer
10
- # @rbs!
11
- # interface _TraceOutput
12
- # def puts: (String) -> untyped
13
- # end
14
-
15
- # Hook layer installed on an individual parser's singleton class.
16
- module Hooks
17
- # @rbs!
18
- # def token_to_str: (Integer) -> String
19
-
20
- # @rbs @ibex_jsonl_trace_output: _TraceOutput?
21
-
22
- # @rbs (Integer token_id, untyped value, Integer state) -> void
23
- def on_shift(token_id, value, state)
24
- write_trace(event: "shift", token_id: token_id, token: token_to_str(token_id),
25
- value: safe_inspect(value), state: state)
26
- super
27
- end
28
-
29
- # @rbs (Integer production_id, Array[untyped] values, untyped result) -> void
30
- def on_reduce(production_id, values, result)
31
- write_trace(event: "reduce", production_id: production_id, values: values.map { |value| safe_inspect(value) },
32
- result: safe_inspect(result))
33
- super
34
- end
35
-
36
- # @rbs (Integer token_id, untyped value, Array[untyped] value_stack) -> void
37
- def on_error_recover(token_id, value, value_stack)
38
- write_trace(event: "error_recover", token_id: token_id, token: token_to_str(token_id),
39
- value: safe_inspect(value), value_stack: value_stack.map { |item| safe_inspect(item) })
40
- super
41
- end
42
-
43
- private
44
-
45
- # @rbs (_TraceOutput output) -> void
46
- def ibex_jsonl_trace_output=(output)
47
- @ibex_jsonl_trace_output = output
48
- end
49
-
50
- # @rbs (**untyped event) -> void
51
- def write_trace(**event)
52
- @ibex_jsonl_trace_output&.puts(JSON.generate(event))
53
- rescue StandardError
54
- nil
55
- end
56
-
57
- # @rbs (untyped value) -> String
58
- def safe_inspect(value)
59
- value.inspect.encode(Encoding::UTF_8, invalid: :replace, undef: :replace)
60
- rescue StandardError
61
- "<inspect failed>"
62
- end
63
- end
64
-
65
- # @rbs [P < Parser] (P parser, io: _TraceOutput) -> P
66
- def self.attach(parser, io:)
67
- singleton = parser.singleton_class
68
- singleton.prepend(Hooks) unless singleton.ancestors.include?(Hooks)
69
- Object.instance_method(:instance_variable_set).bind_call(parser, :@runtime_fast_path, false)
70
- parser.__send__(:ibex_jsonl_trace_output=, io)
71
- parser
72
- end
73
- end
74
- end
75
- end
@@ -1,42 +0,0 @@
1
- # Generated from lib/ibex/runtime/jsonl_tracer.rb with RBS::Inline
2
-
3
- module Ibex
4
- module Runtime
5
- # Emits committed parser observer events as JSON Lines.
6
- module JSONLTracer
7
- interface _TraceOutput
8
- def puts: (String) -> untyped
9
- end
10
-
11
- # Hook layer installed on an individual parser's singleton class.
12
- module Hooks
13
- def token_to_str: (Integer) -> String
14
-
15
- @ibex_jsonl_trace_output: _TraceOutput?
16
-
17
- # @rbs (Integer token_id, untyped value, Integer state) -> void
18
- def on_shift: (Integer token_id, untyped value, Integer state) -> void
19
-
20
- # @rbs (Integer production_id, Array[untyped] values, untyped result) -> void
21
- def on_reduce: (Integer production_id, Array[untyped] values, untyped result) -> void
22
-
23
- # @rbs (Integer token_id, untyped value, Array[untyped] value_stack) -> void
24
- def on_error_recover: (Integer token_id, untyped value, Array[untyped] value_stack) -> void
25
-
26
- private
27
-
28
- # @rbs (_TraceOutput output) -> void
29
- def ibex_jsonl_trace_output=: (_TraceOutput output) -> void
30
-
31
- # @rbs (**untyped event) -> void
32
- def write_trace: (**untyped event) -> void
33
-
34
- # @rbs (untyped value) -> String
35
- def safe_inspect: (untyped value) -> String
36
- end
37
-
38
- # @rbs [P < Parser] (P parser, io: _TraceOutput) -> P
39
- def self.attach: [P < Parser] (P parser, io: _TraceOutput) -> P
40
- end
41
- end
42
- end