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
@@ -7,21 +7,21 @@ module Ibex
7
7
  module ParserSyncRecovery
8
8
  ERROR_ACTION: [ :error ]
9
9
 
10
- private def parser_tables: () -> Hash[Symbol, untyped]
10
+ private def parser_tables: () -> Hash[Symbol, Object?]
11
11
 
12
- private def table_lookup: (untyped, Integer, Integer) -> untyped
12
+ private def table_lookup: (Object?, Integer, Integer) -> IR::runtime_action?
13
13
 
14
- private def default_action: (Integer) -> untyped
14
+ private def default_action: (Integer) -> IR::runtime_action?
15
15
 
16
- private def token_to_str: (untyped) -> String
16
+ private def token_to_str: (Object?) -> String
17
17
 
18
18
  private def trace: (String) -> void
19
19
 
20
- private def continue_recovery: () -> untyped
20
+ private def continue_recovery: () -> ([ :continue ] | [ :done, nil ])
21
21
 
22
22
  private def reject_recovery_eof: () -> [ :done, nil ]
23
23
 
24
- private def finish_recovery: (untyped, untyped, untyped, untyped, Integer, Array[untyped], Hash[String, untyped]?, String, Array[Proc]?) -> [ :continue ]
24
+ private def finish_recovery: (Object?, Object?, Object?, Object?, Integer, Array[Object?], Hash[String, Object?]?, String, Array[Proc]?) -> [ :continue ]
25
25
 
26
26
  private
27
27
 
@@ -31,21 +31,21 @@ module Ibex
31
31
  # @rbs () -> bool
32
32
  def sync_recovery_active?: () -> bool
33
33
 
34
- # @rbs (Hash[Symbol, untyped] context, Hash[String, untyped]? token_data,
35
- # Array[Proc]? observers) -> untyped
36
- def begin_sync_recovery: (Hash[Symbol, untyped] context, Hash[String, untyped]? token_data, Array[Proc]? observers) -> untyped
34
+ # @rbs (Hash[Symbol, Object?] context, Hash[String, Object?]? token_data,
35
+ # Array[Proc]? observers) -> ([ :continue ] | [ :done, nil ])
36
+ def begin_sync_recovery: (Hash[Symbol, Object?] context, Hash[String, Object?]? token_data, Array[Proc]? observers) -> ([ :continue ] | [ :done, nil ])
37
37
 
38
- # @rbs () -> untyped
39
- def continue_sync_recovery: () -> untyped
38
+ # @rbs () -> ([ :continue ] | [ :done, nil ])
39
+ def continue_sync_recovery: () -> ([ :continue ] | [ :done, nil ])
40
40
 
41
- # @rbs (untyped token_id) -> bool
42
- def sync_token?: (untyped token_id) -> bool
41
+ # @rbs (Integer token_id) -> bool
42
+ def sync_token?: (Integer token_id) -> bool
43
43
 
44
44
  # @rbs () -> bool
45
45
  def synchronize_for_current_token: () -> bool
46
46
 
47
- # @rbs (Integer state, Integer token_id) -> untyped
48
- def sync_action: (Integer state, Integer token_id) -> untyped
47
+ # @rbs (Integer state, Integer token_id) -> IR::runtime_action
48
+ def sync_action: (Integer state, Integer token_id) -> IR::runtime_action
49
49
 
50
50
  # @rbs () -> [:continue]
51
51
  def finish_sync_recovery: () -> [ :continue ]
@@ -28,6 +28,8 @@ module Ibex
28
28
 
29
29
  # One immutable insertion, deletion, or replacement.
30
30
  class RepairEdit
31
+ type document_value = Symbol | Integer | String
32
+
31
33
  KINDS: Array[Symbol]
32
34
 
33
35
  attr_reader kind: Symbol
@@ -43,8 +45,8 @@ module Ibex
43
45
  # @rbs (kind: Symbol, position: Integer, token_id: Integer, token_name: String, cost: Integer) -> void
44
46
  def initialize: (kind: Symbol, position: Integer, token_id: Integer, token_name: String, cost: Integer) -> void
45
47
 
46
- # @rbs () -> Hash[Symbol, untyped]
47
- def to_h: () -> Hash[Symbol, untyped]
48
+ # @rbs () -> Hash[Symbol, document_value]
49
+ def to_h: () -> Hash[Symbol, document_value]
48
50
  end
49
51
 
50
52
  # Deterministically selected repair.
@@ -58,8 +60,26 @@ module Ibex
58
60
  # @rbs (edits: Array[RepairEdit], configurations: Integer) -> void
59
61
  def initialize: (edits: Array[RepairEdit], configurations: Integer) -> void
60
62
 
61
- # @rbs () -> Hash[Symbol, untyped]
62
- def to_h: () -> Hash[Symbol, untyped]
63
+ # @rbs () -> Hash[Symbol, Integer | Array[Hash[Symbol, RepairEdit::document_value]]]
64
+ def to_h: () -> Hash[Symbol, Integer | Array[Hash[Symbol, RepairEdit::document_value]]]
65
+ end
66
+
67
+ # Closed internal outcome for callers that must distinguish bounded search
68
+ # exhaustion from a complete search with no repair.
69
+ class RepairSearchResult
70
+ STATUSES: Array[Symbol]
71
+
72
+ attr_reader status: Symbol
73
+
74
+ attr_reader plan: RepairPlan?
75
+
76
+ attr_reader configurations: Integer
77
+
78
+ # @rbs (status: Symbol, plan: RepairPlan?, configurations: Integer) -> void
79
+ def initialize: (status: Symbol, plan: RepairPlan?, configurations: Integer) -> void
80
+
81
+ # @rbs () -> bool
82
+ def selected?: () -> bool
63
83
  end
64
84
 
65
85
  # Internal normalized input record retained while repair looks ahead.
@@ -68,12 +88,12 @@ module Ibex
68
88
 
69
89
  attr_reader token_name: String
70
90
 
71
- attr_reader value: untyped
91
+ attr_reader value: Object?
72
92
 
73
- attr_reader location: untyped
93
+ attr_reader location: Object?
74
94
 
75
- # @rbs (token_id: Integer, token_name: String, value: untyped, location: untyped) -> void
76
- def initialize: (token_id: Integer, token_name: String, value: untyped, location: untyped) -> void
95
+ # @rbs (token_id: Integer, token_name: String, value: Object?, location: Object?) -> void
96
+ def initialize: (token_id: Integer, token_name: String, value: Object?, location: Object?) -> void
77
97
 
78
98
  # @rbs () -> bool
79
99
  def eof?: () -> bool
@@ -4,7 +4,9 @@ module Ibex
4
4
  module Runtime
5
5
  # Minimal binary heap ordered by an immutable Array priority.
6
6
  class RepairPriorityQueue
7
- @entries: Array[[ Array[untyped], untyped ]]
7
+ type priority = Array[untyped]
8
+
9
+ @entries: Array[[ priority, Object? ]]
8
10
 
9
11
  # @rbs () -> void
10
12
  def initialize: () -> void
@@ -12,16 +14,16 @@ module Ibex
12
14
  # @rbs () -> bool
13
15
  def empty?: () -> bool
14
16
 
15
- # @rbs (Array[untyped] priority, untyped value) -> void
16
- def push: (Array[untyped] priority, untyped value) -> void
17
+ # @rbs (priority priority, Object? value) -> void
18
+ def push: (priority priority, Object? value) -> void
17
19
 
18
- # @rbs () -> [Array[untyped], untyped]?
19
- def pop: () -> [ Array[untyped], untyped ]?
20
+ # @rbs () -> [priority, Object?]?
21
+ def pop: () -> [ priority, Object? ]?
20
22
 
21
23
  private
22
24
 
23
- # @rbs ([Array[untyped], untyped] left, [Array[untyped], untyped] right) -> Integer
24
- def compare: ([ Array[untyped], untyped ] left, [ Array[untyped], untyped ] right) -> Integer
25
+ # @rbs ([priority, Object?] left, [priority, Object?] right) -> Integer
26
+ def compare: ([ priority, Object? ] left, [ priority, Object? ] right) -> Integer
25
27
  end
26
28
  end
27
29
  end
@@ -5,30 +5,38 @@ module Ibex
5
5
  # Bounded Dijkstra search over LR state stacks. Semantic actions never run.
6
6
  # rubocop:disable Metrics/ClassLength -- queue policy and LR transitions form one bounded search invariant.
7
7
  class RepairSearch
8
+ type configuration_key = [ Array[Integer], Integer, Integer, bool ]
9
+
10
+ type priority = Array[untyped]
11
+
12
+ type lookup_table = Tables::action_table | Tables::goto_table
13
+
14
+ type lookup_value = IR::runtime_action | Integer?
15
+
8
16
  NEED_INPUT: Object
9
17
 
10
18
  LIMIT: Object
11
19
 
12
- class Configuration < Struct[untyped]
13
- attr_accessor stack(): untyped
20
+ class Configuration < Struct[Array[Integer] | Integer | Array[RepairEdit] | bool]
21
+ attr_accessor stack(): Array[Integer]
14
22
 
15
- attr_accessor input_index(): untyped
23
+ attr_accessor input_index(): Integer
16
24
 
17
- attr_accessor shifts(): untyped
25
+ attr_accessor shifts(): Integer
18
26
 
19
- attr_accessor cost(): untyped
27
+ attr_accessor cost(): Integer
20
28
 
21
- attr_accessor edits(): untyped
29
+ attr_accessor edits(): Array[RepairEdit]
22
30
 
23
- attr_accessor goal(): untyped
31
+ attr_accessor goal(): bool
24
32
 
25
- def self.new: (?stack: untyped, ?input_index: untyped, ?shifts: untyped, ?cost: untyped, ?edits: untyped, ?goal: untyped) -> instance
26
- | ({ ?stack: untyped, ?input_index: untyped, ?shifts: untyped, ?cost: untyped, ?edits: untyped, ?goal: untyped }) -> instance
33
+ def self.new: (?stack: Array[Integer], ?input_index: Integer, ?shifts: Integer, ?cost: Integer, ?edits: Array[RepairEdit], ?goal: bool) -> instance
34
+ | ({ ?stack: Array[Integer], ?input_index: Integer, ?shifts: Integer, ?cost: Integer, ?edits: Array[RepairEdit], ?goal: bool }) -> instance
27
35
  end
28
36
 
29
37
  @candidate_ids: Array[Integer]
30
38
 
31
- @best: Hash[Array[untyped], Array[untyped]]
39
+ @best: Hash[configuration_key, priority]
32
40
 
33
41
  @heap: RepairPriorityQueue
34
42
 
@@ -40,15 +48,20 @@ module Ibex
40
48
 
41
49
  @policy: RepairPolicy
42
50
 
43
- @tables: Hash[Symbol, untyped]
51
+ @tables: Hash[Symbol, Object?]
44
52
 
45
- # @rbs (Hash[Symbol, untyped] tables, RepairPolicy policy, Array[RepairInput] tokens,
53
+ # @rbs (Hash[Symbol, Object?] tables, RepairPolicy policy, Array[RepairInput] tokens,
46
54
  # complete: bool) -> void
47
- def initialize: (Hash[Symbol, untyped] tables, RepairPolicy policy, Array[RepairInput] tokens, complete: bool) -> void
55
+ def initialize: (Hash[Symbol, Object?] tables, RepairPolicy policy, Array[RepairInput] tokens, complete: bool) -> void
48
56
 
57
+ # Compatibility projection used by the semantic runtime path.
49
58
  # @rbs (Array[Integer] state_stack) -> (RepairPlan | Object | nil)
50
59
  def search: (Array[Integer] state_stack) -> (RepairPlan | Object | nil)
51
60
 
61
+ # Preserve the bounded outcome for syntax tooling and diagnostics.
62
+ # @rbs (Array[Integer] state_stack) -> RepairSearchResult
63
+ def search_result: (Array[Integer] state_stack) -> RepairSearchResult
64
+
52
65
  private
53
66
 
54
67
  # @rbs (Configuration configuration) -> (RepairPlan | Object | nil)
@@ -79,11 +92,14 @@ module Ibex
79
92
  # @rbs (Array[Integer] states, Integer production_id) -> Array[Integer]?
80
93
  def apply_reduction: (Array[Integer] states, Integer production_id) -> Array[Integer]?
81
94
 
82
- # @rbs (Integer state, Integer token_id) -> untyped
83
- def action_for: (Integer state, Integer token_id) -> untyped
95
+ # @rbs (Integer state, Integer token_id) -> IR::runtime_action
96
+ def action_for: (Integer state, Integer token_id) -> IR::runtime_action
97
+
98
+ # @rbs (Tables::action_table table, Integer row, Integer column) -> IR::runtime_action?
99
+ def action_table_lookup: (Tables::action_table table, Integer row, Integer column) -> IR::runtime_action?
84
100
 
85
- # @rbs (untyped table, Integer row, Integer column) -> untyped
86
- def table_lookup: (untyped table, Integer row, Integer column) -> untyped
101
+ # @rbs (Tables::goto_table table, Integer row, Integer column) -> Integer?
102
+ def goto_table_lookup: (Tables::goto_table table, Integer row, Integer column) -> Integer?
87
103
 
88
104
  # @rbs (Configuration source, ?stack: Array[Integer], ?input_index: Integer, ?shifts: Integer,
89
105
  # ?cost: Integer, ?edits: Array[RepairEdit], ?goal: bool) -> Configuration
@@ -92,6 +108,9 @@ module Ibex
92
108
  # @rbs (Array[RepairEdit] edits) -> RepairPlan
93
109
  def plan: (Array[RepairEdit] edits) -> RepairPlan
94
110
 
111
+ # @rbs (Symbol status, ?plan: RepairPlan?) -> RepairSearchResult
112
+ def outcome: (Symbol status, ?plan: RepairPlan?) -> RepairSearchResult
113
+
95
114
  # @rbs (Integer token_id) -> String
96
115
  def token_name: (Integer token_id) -> String
97
116
 
@@ -101,8 +120,8 @@ module Ibex
101
120
  # @rbs () -> (Configuration | Object)
102
121
  def pop: () -> (Configuration | Object)
103
122
 
104
- # @rbs (Configuration configuration) -> Array[untyped]
105
- def priority_for: (Configuration configuration) -> Array[untyped]
123
+ # @rbs (Configuration configuration) -> priority
124
+ def priority_for: (Configuration configuration) -> priority
106
125
 
107
126
  # Prefer punctuation edits when equal-cost repairs are otherwise
108
127
  # ambiguous; inventing or discarding a word-like token is more likely to
@@ -0,0 +1,177 @@
1
+ # Generated from lib/ibex/runtime/syntax_repair.rb with RBS::Inline
2
+
3
+ module Ibex
4
+ module Runtime
5
+ type syntax_edit_document = { kind: Symbol, position: Integer, token_id: Integer, token_name: String, cost: Integer, start_byte: Integer, end_byte: Integer, original_text: String, replacement_text: String? }
6
+
7
+ # One syntax-only projection of a runtime repair edit. It intentionally
8
+ # carries source bytes and token identity, never an application value.
9
+ class SyntaxRepairEdit
10
+ attr_reader kind: Symbol
11
+
12
+ attr_reader position: Integer
13
+
14
+ attr_reader token_id: Integer
15
+
16
+ attr_reader token_name: String
17
+
18
+ attr_reader cost: Integer
19
+
20
+ attr_reader start_byte: Integer
21
+
22
+ attr_reader end_byte: Integer
23
+
24
+ attr_reader original_text: String
25
+
26
+ attr_reader replacement_text: String?
27
+
28
+ # @rbs (kind: Symbol, position: Integer, token_id: Integer, token_name: String, cost: Integer,
29
+ # start_byte: Integer, end_byte: Integer, original_text: String, replacement_text: String?) -> void
30
+ # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity
31
+ def initialize: (kind: Symbol, position: Integer, token_id: Integer, token_name: String, cost: Integer, start_byte: Integer, end_byte: Integer, original_text: String, replacement_text: String?) -> void
32
+
33
+ # @rbs () -> syntax_edit_document
34
+ def to_h: () -> syntax_edit_document
35
+ end
36
+
37
+ # One selected runtime plan plus its source-oriented edit projection.
38
+ class SyntaxRepairPlan
39
+ attr_reader runtime_plan: RepairPlan
40
+
41
+ attr_reader edits: Array[SyntaxRepairEdit]
42
+
43
+ attr_reader cost: Integer
44
+
45
+ attr_reader configurations: Integer
46
+
47
+ # @rbs (runtime_plan: RepairPlan, edits: Array[SyntaxRepairEdit]) -> void
48
+ # rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
49
+ def initialize: (runtime_plan: RepairPlan, edits: Array[SyntaxRepairEdit]) -> void
50
+ end
51
+
52
+ # Immutable syntax-only repair attempt. There is deliberately no `value`.
53
+ class SyntaxRepairResult
54
+ STATUSES: Array[Symbol]
55
+
56
+ BOUNDED_STATUSES: Array[Symbol]
57
+
58
+ attr_reader status: Symbol
59
+
60
+ attr_reader bounded_status: Symbol
61
+
62
+ attr_reader reason: Symbol?
63
+
64
+ attr_reader plan: SyntaxRepairPlan?
65
+
66
+ attr_reader text_edits: Array[CST::TextEdit]
67
+
68
+ attr_reader syntax_root: CST::SyntaxNode
69
+
70
+ attr_reader diagnostics: Array[SyntaxSessionDiagnostic]
71
+
72
+ attr_reader updated_source: CST::SourceText?
73
+
74
+ attr_reader validation: SyntaxSessionResult?
75
+
76
+ # @rbs (status: Symbol, bounded_status: Symbol, reason: Symbol?, plan: SyntaxRepairPlan?,
77
+ # text_edits: Array[CST::TextEdit], syntax_root: CST::SyntaxNode,
78
+ # diagnostics: Array[SyntaxSessionDiagnostic], updated_source: CST::SourceText?,
79
+ # validation: SyntaxSessionResult?) -> void
80
+ # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity
81
+ def initialize: (status: Symbol, bounded_status: Symbol, reason: Symbol?, plan: SyntaxRepairPlan?, text_edits: Array[CST::TextEdit], syntax_root: CST::SyntaxNode, diagnostics: Array[SyntaxSessionDiagnostic], updated_source: CST::SourceText?, validation: SyntaxSessionResult?) -> void
82
+
83
+ # @rbs () -> bool
84
+ def accepted?: () -> bool
85
+
86
+ # @rbs () -> bool
87
+ def progress?: () -> bool
88
+
89
+ private
90
+
91
+ # @rbs (Symbol, Symbol, Symbol?, SyntaxRepairPlan?, Array[CST::TextEdit], CST::SourceText?,
92
+ # SyntaxSessionResult?) -> void
93
+ # rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
94
+ def validate_result_shape!: (Symbol, Symbol, Symbol?, SyntaxRepairPlan?, Array[CST::TextEdit], CST::SourceText?, SyntaxSessionResult?) -> void
95
+ end
96
+
97
+ # Executes one fresh syntax-only repair attempt without mutating its source
98
+ # SyntaxSession. Generated lexer actions retain the acknowledged trust
99
+ # profile; parser production actions remain suppressed.
100
+ class SyntaxRepairer
101
+ # @rbs (Class parser_class, CST::SourceText source, SyntaxSessionResult baseline,
102
+ # execution_profile: Symbol, resource_limits: ResourceLimits, limits: SyntaxSessionLimits,
103
+ # cancellation: CancellationToken?, policy: RepairPolicy, token_text: Hash[String, String]) -> void
104
+ def initialize: (Class parser_class, CST::SourceText source, SyntaxSessionResult baseline, execution_profile: Symbol, resource_limits: ResourceLimits, limits: SyntaxSessionLimits, cancellation: CancellationToken?, policy: RepairPolicy, token_text: Hash[String, String]) -> void
105
+
106
+ # @rbs () -> SyntaxRepairResult
107
+ def call: () -> SyntaxRepairResult
108
+
109
+ private
110
+
111
+ # @rbs (Parser parser) -> Array[[RepairPlan, Array[RepairInput]]]
112
+ def install_capture: (Parser parser) -> Array[[ RepairPlan, Array[RepairInput] ]]
113
+
114
+ # @rbs ([RepairPlan, Array[RepairInput]] capture, CST::SyntaxResult parsed,
115
+ # Array[SyntaxSessionDiagnostic] diagnostics) -> SyntaxRepairResult
116
+ def build_selected: ([ RepairPlan, Array[RepairInput] ] capture, CST::SyntaxResult parsed, Array[SyntaxSessionDiagnostic] diagnostics) -> SyntaxRepairResult
117
+
118
+ # @rbs (RepairPlan plan, Array[RepairInput] inputs) -> Array[SyntaxRepairEdit]
119
+ def project_edits: (RepairPlan plan, Array[RepairInput] inputs) -> Array[SyntaxRepairEdit]
120
+
121
+ # @rbs (RepairInput input) -> [Integer, Integer]
122
+ def input_range: (RepairInput input) -> [ Integer, Integer ]
123
+
124
+ # @rbs (RepairEdit edit) -> String?
125
+ def replacement_text: (RepairEdit edit) -> String?
126
+
127
+ # @rbs (String name) -> String?
128
+ def punctuation_literal: (String name) -> String?
129
+
130
+ # @rbs (Integer start_byte, Integer end_byte) -> String
131
+ def original_text: (Integer start_byte, Integer end_byte) -> String
132
+
133
+ # @rbs (Array[SyntaxRepairEdit] edits) -> Array[CST::TextEdit]
134
+ def normalize_text_edits: (Array[SyntaxRepairEdit] edits) -> Array[CST::TextEdit]
135
+
136
+ # @rbs (Array[CST::TextEdit] edits) -> void
137
+ def validate_edit_limits!: (Array[CST::TextEdit] edits) -> void
138
+
139
+ # @rbs (CST::SourceText source) -> SyntaxSessionResult
140
+ def fresh_validation: (CST::SourceText source) -> SyntaxSessionResult
141
+
142
+ # @rbs (SyntaxSessionResult validation, CST::SourceText source) -> Symbol
143
+ def validation_status: (SyntaxSessionResult validation, CST::SourceText source) -> Symbol
144
+
145
+ # @rbs (SyntaxSessionResult result) -> Integer?
146
+ def first_diagnostic_byte: (SyntaxSessionResult result) -> Integer?
147
+
148
+ # @rbs (Symbol status, Symbol reason, CST::SyntaxResult parsed,
149
+ # Array[SyntaxSessionDiagnostic] diagnostics) -> SyntaxRepairResult
150
+ def bounded_failure: (Symbol status, Symbol reason, CST::SyntaxResult parsed, Array[SyntaxSessionDiagnostic] diagnostics) -> SyntaxRepairResult
151
+
152
+ # @rbs (Symbol reason, CST::SyntaxResult parsed, Array[SyntaxSessionDiagnostic] diagnostics,
153
+ # ?plan: SyntaxRepairPlan?) -> SyntaxRepairResult
154
+ def unavailable: (Symbol reason, CST::SyntaxResult parsed, Array[SyntaxSessionDiagnostic] diagnostics, ?plan: SyntaxRepairPlan?) -> SyntaxRepairResult
155
+
156
+ # @rbs (Array[Object] diagnostics) -> Array[SyntaxSessionDiagnostic]
157
+ def immutable_diagnostics: (Array[Object] diagnostics) -> Array[SyntaxSessionDiagnostic]
158
+
159
+ # @rbs (Object location, Symbol key) -> Object?
160
+ # @rbs (untyped location, Symbol key) -> untyped
161
+ def location_value: (Object location, Symbol key) -> Object?
162
+ | (untyped location, Symbol key) -> untyped
163
+
164
+ # @rbs (RepairPolicy policy) -> RepairPolicy
165
+ def validate_policy: (RepairPolicy policy) -> RepairPolicy
166
+
167
+ # @rbs (Hash[String, String] value) -> Hash[String, String]
168
+ def validate_token_text: (Hash[String, String] value) -> Hash[String, String]
169
+
170
+ # @rbs (Symbol resource, Integer limit, Integer observed) -> void
171
+ def enforce_limit!: (Symbol resource, Integer limit, Integer observed) -> void
172
+
173
+ # @rbs () -> void
174
+ def cancellation_checkpoint!: () -> void
175
+ end
176
+ end
177
+ end
@@ -0,0 +1,186 @@
1
+ # Generated from lib/ibex/runtime/syntax_session.rb with RBS::Inline
2
+
3
+ module Ibex
4
+ module Runtime
5
+ class Parser
6
+ def self.syntax_execution_profile: () -> Symbol
7
+
8
+ def self.syntax_session: (String | CST::SourceText source, ?execution_profile: Symbol?, ?resource_limits: ResourceLimits?, ?limits: SyntaxSessionLimits?, ?cancellation: CancellationToken?, ?blender: bool) -> SyntaxSession
9
+ end
10
+
11
+ # Raised when a caller has not acknowledged the generated artifact's
12
+ # execution profile.
13
+ class SyntaxSessionTrustError < ArgumentError
14
+ end
15
+
16
+ # Raised cooperatively at syntax-session operation boundaries and parser
17
+ # observation checkpoints after cancellation is requested.
18
+ class SyntaxSessionCancelled < StandardError
19
+ end
20
+
21
+ # Raised when a syntax-service-specific resource bound is exceeded.
22
+ class SyntaxSessionResourceLimitError < StandardError
23
+ attr_reader resource: Symbol
24
+
25
+ attr_reader limit: Integer
26
+
27
+ attr_reader observed: Integer
28
+
29
+ # @rbs (resource: Symbol, limit: Integer, observed: Integer) -> void
30
+ def initialize: (resource: Symbol, limit: Integer, observed: Integer) -> void
31
+ end
32
+
33
+ # Thread-safe cooperative cancellation state for one or more operations.
34
+ class CancellationToken
35
+ # @rbs () -> void
36
+ def initialize: () -> void
37
+
38
+ # @rbs () -> true
39
+ # rubocop:disable Naming/PredicateMethod -- command mutation convention.
40
+ def cancel!: () -> true
41
+
42
+ # @rbs () -> bool
43
+ def cancelled?: () -> bool
44
+ end
45
+
46
+ # Immutable syntax-service bounds layered over parser ResourceLimits.
47
+ class SyntaxSessionLimits
48
+ DEFAULT_MAX_SOURCE_BYTES: Integer
49
+
50
+ DEFAULT_MAX_EDITS_PER_OPERATION: Integer
51
+
52
+ DEFAULT_MAX_INSERTED_BYTES: Integer
53
+
54
+ attr_reader max_source_bytes: Integer
55
+
56
+ attr_reader max_edits_per_operation: Integer
57
+
58
+ attr_reader max_inserted_bytes: Integer
59
+
60
+ # @rbs (?max_source_bytes: Integer, ?max_edits_per_operation: Integer,
61
+ # ?max_inserted_bytes: Integer) -> void
62
+ def initialize: (?max_source_bytes: Integer, ?max_edits_per_operation: Integer, ?max_inserted_bytes: Integer) -> void
63
+
64
+ private
65
+
66
+ # @rbs (Object? value, Symbol name) -> void
67
+ def validate_positive_integer: (Object? value, Symbol name) -> void
68
+
69
+ # @rbs (Object? value, Symbol name) -> void
70
+ def validate_nonnegative_integer: (Object? value, Symbol name) -> void
71
+ end
72
+
73
+ # Immutable evidence from one completed syntax-session operation.
74
+ class SyntaxSessionMetrics
75
+ attr_reader reused_ratio: Float
76
+
77
+ attr_reader reused_tokens: Integer
78
+
79
+ attr_reader token_count: Integer
80
+
81
+ attr_reader fallback_reasons: Array[Symbol]
82
+
83
+ # @rbs (reused_ratio: Float, reused_tokens: Integer, token_count: Integer,
84
+ # fallback_reasons: Array[Symbol]) -> void
85
+ def initialize: (reused_ratio: Float, reused_tokens: Integer, token_count: Integer, fallback_reasons: Array[Symbol]) -> void
86
+
87
+ # @rbs () -> bool
88
+ def fallback?: () -> bool
89
+ end
90
+
91
+ # Immutable, data-only copy of one parser diagnostic. Application-owned
92
+ # values and locations are sanitized rather than retained by identity.
93
+ class SyntaxSessionDiagnostic
94
+ attr_reader kind: Symbol
95
+
96
+ attr_reader data: Hash[String, EventSanitizer::json_value]
97
+
98
+ # @rbs (kind: Symbol, data: Hash[Object?, Object?]) -> void
99
+ def initialize: (kind: Symbol, data: Hash[Object?, Object?]) -> void
100
+
101
+ # @rbs () -> Hash[String, EventSanitizer::json_value]
102
+ def to_h: () -> Hash[String, EventSanitizer::json_value]
103
+ end
104
+
105
+ # Immutable public snapshot of one completed syntax-session operation.
106
+ class SyntaxSessionResult
107
+ attr_reader revision: Integer
108
+
109
+ attr_reader syntax_root: CST::SyntaxNode
110
+
111
+ attr_reader diagnostics: Array[SyntaxSessionDiagnostic]
112
+
113
+ attr_reader expected_tokens: Array[String]
114
+
115
+ attr_reader metrics: SyntaxSessionMetrics
116
+
117
+ attr_reader status: Symbol
118
+
119
+ # @rbs (revision: Integer, syntax_root: CST::SyntaxNode, diagnostics: Array[SyntaxSessionDiagnostic],
120
+ # expected_tokens: Array[String], metrics: SyntaxSessionMetrics, status: Symbol) -> void
121
+ def initialize: (revision: Integer, syntax_root: CST::SyntaxNode, diagnostics: Array[SyntaxSessionDiagnostic], expected_tokens: Array[String], metrics: SyntaxSessionMetrics, status: Symbol) -> void
122
+
123
+ # @rbs () -> bool
124
+ def success?: () -> bool
125
+ end
126
+
127
+ # Generated-language syntax boundary backed by the existing Red/Green CST
128
+ # incremental engine. It does not execute parser production actions.
129
+ class SyntaxSession
130
+ TRUSTED_PROFILE: Symbol
131
+
132
+ attr_reader execution_profile: Symbol
133
+
134
+ attr_reader limits: SyntaxSessionLimits
135
+
136
+ # @rbs (Class parser_class, String | CST::SourceText source,
137
+ # execution_profile: Symbol?, ?resource_limits: ResourceLimits?,
138
+ # ?limits: SyntaxSessionLimits?, ?cancellation: CancellationToken?, ?blender: bool) -> void
139
+ def initialize: (Class parser_class, String | CST::SourceText source, execution_profile: Symbol?, ?resource_limits: ResourceLimits?, ?limits: SyntaxSessionLimits?, ?cancellation: CancellationToken?, ?blender: bool) -> void
140
+
141
+ # @rbs () -> CST::SourceText
142
+ def source_text: () -> CST::SourceText
143
+
144
+ # @rbs () -> SyntaxSessionResult
145
+ def result: () -> SyntaxSessionResult
146
+
147
+ # Apply byte-oriented edits against the current source.
148
+ # @rbs (Array[CST::TextEdit] edits) -> SyntaxSessionResult
149
+ def apply_edits: (Array[CST::TextEdit] edits) -> SyntaxSessionResult
150
+
151
+ # Propose byte edits through the existing bounded repair search, then
152
+ # validate them with a fresh syntax-only parse. The session is unchanged.
153
+ # @rbs (?policy: RepairPolicy, ?token_text: Hash[String, String]) -> SyntaxRepairResult
154
+ def repair: (?policy: RepairPolicy, ?token_text: Hash[String, String]) -> SyntaxRepairResult
155
+
156
+ private
157
+
158
+ # @rbs (Array[CST::TextEdit] edits) -> SyntaxSessionResult
159
+ def apply_edits_locked: (Array[CST::TextEdit] edits) -> SyntaxSessionResult
160
+
161
+ # @rbs (Class parser_class, Symbol? acknowledged) -> Symbol
162
+ def validate_execution_profile: (Class parser_class, Symbol? acknowledged) -> Symbol
163
+
164
+ # @rbs (String | CST::SourceText source) -> CST::SourceText
165
+ def normalize_source: (String | CST::SourceText source) -> CST::SourceText
166
+
167
+ # @rbs (Symbol resource, Integer limit, Integer observed) -> void
168
+ def enforce_limit!: (Symbol resource, Integer limit, Integer observed) -> void
169
+
170
+ # @rbs () -> void
171
+ def cancellation_checkpoint!: () -> void
172
+
173
+ # @rbs (Event event, Parser parser) -> void
174
+ def handle_runtime_event: (Event event, Parser parser) -> void
175
+
176
+ # @rbs () -> void
177
+ def reset_operation_evidence: () -> void
178
+
179
+ # @rbs (CST::SyntaxResult parsed) -> SyntaxSessionResult
180
+ def snapshot: (CST::SyntaxResult parsed) -> SyntaxSessionResult
181
+
182
+ # @rbs (Array[Object?] diagnostics) -> Array[SyntaxSessionDiagnostic]
183
+ def immutable_diagnostics: (Array[Object?] diagnostics) -> Array[SyntaxSessionDiagnostic]
184
+ end
185
+ end
186
+ end