Class: Ibex::Runtime::SyntaxSession
- Inherits:
-
Object
- Object
- Ibex::Runtime::SyntaxSession
- Defined in:
- lib/json5/generated_parser.rb
Overview
Generated-language syntax boundary backed by the existing Red/Green CST incremental engine. It does not execute parser production actions.
Constant Summary collapse
- TRUSTED_PROFILE =
:trusted_application_code
Instance Attribute Summary collapse
- #execution_profile ⇒ Object readonly
- #limits ⇒ Object readonly
Instance Method Summary collapse
-
#apply_edits(edits) ⇒ Object
Apply byte-oriented edits against the current source.
-
#initialize(parser_class, source, execution_profile:, resource_limits: nil, limits: nil, cancellation: nil, blender: true) ⇒ SyntaxSession
constructor
A new instance of SyntaxSession.
-
#repair(policy: RepairPolicy.new, token_text: {}) ⇒ Object
Propose byte edits through the existing bounded repair search, then validate them with a fresh syntax-only parse.
- #result ⇒ Object
- #source_text ⇒ Object
Constructor Details
#initialize(parser_class, source, execution_profile:, resource_limits: nil, limits: nil, cancellation: nil, blender: true) ⇒ SyntaxSession
Returns a new instance of SyntaxSession.
4139 4140 4141 4142 4143 4144 4145 4146 4147 4148 4149 4150 4151 4152 4153 4154 4155 4156 4157 4158 4159 4160 4161 4162 4163 4164 4165 4166 4167 4168 4169 4170 4171 4172 4173 4174 4175 4176 4177 4178 4179 |
# File 'lib/json5/generated_parser.rb', line 4139 def initialize( parser_class, source, execution_profile:, resource_limits: nil, limits: nil, cancellation: nil, blender: true ) @execution_profile = validate_execution_profile(parser_class, execution_profile) @limits = limits || SyntaxSessionLimits.new #: SyntaxSessionLimits unless @limits.is_a?(SyntaxSessionLimits) raise ArgumentError, "limits must be an Ibex::Runtime::SyntaxSessionLimits" end unless cancellation.nil? || cancellation.is_a?(CancellationToken) raise ArgumentError, "cancellation must be an Ibex::Runtime::CancellationToken or nil" end @cancellation = cancellation #: CancellationToken? @parser_class = parser_class #: Class @resource_limits = resource_limits || ResourceLimits.new #: ResourceLimits @mutex = Mutex.new #: Mutex @revision = 0 #: Integer @operation_expected_tokens = [] #: Array[String] @operation_fallback_reasons = [] #: Array[Symbol] source_text = normalize_source(source) enforce_limit!(:source_bytes, @limits.max_source_bytes, source_text.bytesize) cancellation_checkpoint! event_observer = ->(event, parser) { handle_runtime_event(event, parser) } #: Proc @incremental = CST::IncrementalParseSession.new( parser_class, source_text, resource_limits: @resource_limits, blender: blender, event_observer: event_observer ) #: CST::IncrementalParseSession @result = snapshot(@incremental.result) #: SyntaxSessionResult rescue ResourceLimitError => e raise SyntaxSessionResourceLimitError.new(resource: e.resource, limit: e.limit, observed: e.observed), cause: e end |
Instance Attribute Details
#execution_profile ⇒ Object (readonly)
4133 4134 4135 |
# File 'lib/json5/generated_parser.rb', line 4133 def execution_profile @execution_profile end |
#limits ⇒ Object (readonly)
4134 4135 4136 |
# File 'lib/json5/generated_parser.rb', line 4134 def limits @limits end |
Instance Method Details
#apply_edits(edits) ⇒ Object
Apply byte-oriented edits against the current source.
4193 4194 4195 |
# File 'lib/json5/generated_parser.rb', line 4193 def apply_edits(edits) @mutex.synchronize { apply_edits_locked(edits) } end |
#repair(policy: RepairPolicy.new, token_text: {}) ⇒ Object
Propose byte edits through the existing bounded repair search, then validate them with a fresh syntax-only parse. The session is unchanged.
4200 4201 4202 4203 4204 4205 4206 4207 4208 |
# File 'lib/json5/generated_parser.rb', line 4200 def repair(policy: RepairPolicy.new, token_text: {}) @mutex.synchronize do SyntaxRepairer.new( @parser_class, @incremental.source_text, @result, execution_profile: @execution_profile, resource_limits: @resource_limits, limits: @limits, cancellation: @cancellation, policy: policy, token_text: token_text ).call end end |
#result ⇒ Object
4187 4188 4189 |
# File 'lib/json5/generated_parser.rb', line 4187 def result @mutex.synchronize { @result } end |
#source_text ⇒ Object
4182 4183 4184 |
# File 'lib/json5/generated_parser.rb', line 4182 def source_text @mutex.synchronize { @incremental.source_text } end |