Class: Ibex::Runtime::SyntaxSession
- Inherits:
-
Object
- Object
- Ibex::Runtime::SyntaxSession
- Defined in:
- lib/ibex/runtime/syntax_session.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 =
: Symbol
:trusted_application_code
Instance Attribute Summary collapse
-
#execution_profile ⇒ Object
readonly
: Symbol.
-
#limits ⇒ Object
readonly
: SyntaxSessionLimits.
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.
215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 |
# File 'lib/ibex/runtime/syntax_session.rb', line 215 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)
: Symbol
209 210 211 |
# File 'lib/ibex/runtime/syntax_session.rb', line 209 def execution_profile @execution_profile end |
#limits ⇒ Object (readonly)
: SyntaxSessionLimits
210 211 212 |
# File 'lib/ibex/runtime/syntax_session.rb', line 210 def limits @limits end |
Instance Method Details
#apply_edits(edits) ⇒ Object
Apply byte-oriented edits against the current source.
269 270 271 |
# File 'lib/ibex/runtime/syntax_session.rb', line 269 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.
276 277 278 279 280 281 282 283 284 |
# File 'lib/ibex/runtime/syntax_session.rb', line 276 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
263 264 265 |
# File 'lib/ibex/runtime/syntax_session.rb', line 263 def result @mutex.synchronize { @result } end |
#source_text ⇒ Object
258 259 260 |
# File 'lib/ibex/runtime/syntax_session.rb', line 258 def source_text @mutex.synchronize { @incremental.source_text } end |