Class: Ibex::Runtime::CST::IncrementalParseSession
- Inherits:
-
Object
- Object
- Ibex::Runtime::CST::IncrementalParseSession
- Defined in:
- lib/json5/generated_parser.rb
Overview
A mutable, single-owner session around immutable source and syntax results.
Instance Attribute Summary collapse
- #last_blender ⇒ Object readonly
- #last_relex_result ⇒ Object readonly
- #parse_memo ⇒ Object readonly
- #result ⇒ Object readonly
- #source_text ⇒ Object readonly
- #token_memo ⇒ Object readonly
Instance Method Summary collapse
-
#edit(edits) ⇒ Object
Apply edits expressed against the current source and return syntax only.
-
#initialize(parser_class, source_text, resource_limits: nil, blender: true, event_observer: nil) ⇒ IncrementalParseSession
constructor
A new instance of IncrementalParseSession.
-
#last_full_fallback? ⇒ Boolean
Whether the last completed edit discarded all incremental reuse and reparsed the current source from a fresh token stream.
-
#observe(&observer) ⇒ Object
Observe parser and incremental runtime events.
- #unobserve(subscription) ⇒ Object
Constructor Details
#initialize(parser_class, source_text, resource_limits: nil, blender: true, event_observer: nil) ⇒ IncrementalParseSession
Returns a new instance of IncrementalParseSession.
3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 |
# File 'lib/json5/generated_parser.rb', line 3300 def initialize(parser_class, source_text, resource_limits: nil, blender: true, event_observer: nil) unless source_text.is_a?(SourceText) raise ArgumentError, "incremental_session requires an Ibex::Runtime::CST::SourceText" end @resource_limits = resource_limits || ResourceLimits.new #: ResourceLimits @parser = parser_class.__send__(:new, resource_limits: @resource_limits) #: Parser validate_parser! @parser.observe { |event| event_observer.call(event, @parser) } if event_observer @cache = NodeCache.new #: NodeCache @source_text = source_text @last_relex_result = nil #: RelexResult? @last_blender = nil #: Blender? @last_full_fallback = false #: bool @blender_enabled = blender @mutex = Mutex.new @result, @token_memo, @parse_memo = parse_current(0.0) enforce_memo_budget! end |
Instance Attribute Details
#last_blender ⇒ Object (readonly)
3290 3291 3292 |
# File 'lib/json5/generated_parser.rb', line 3290 def last_blender @last_blender end |
#last_relex_result ⇒ Object (readonly)
3289 3290 3291 |
# File 'lib/json5/generated_parser.rb', line 3289 def last_relex_result @last_relex_result end |
#parse_memo ⇒ Object (readonly)
3288 3289 3290 |
# File 'lib/json5/generated_parser.rb', line 3288 def parse_memo @parse_memo end |
#result ⇒ Object (readonly)
3286 3287 3288 |
# File 'lib/json5/generated_parser.rb', line 3286 def result @result end |
#source_text ⇒ Object (readonly)
3285 3286 3287 |
# File 'lib/json5/generated_parser.rb', line 3285 def source_text @source_text end |
#token_memo ⇒ Object (readonly)
3287 3288 3289 |
# File 'lib/json5/generated_parser.rb', line 3287 def token_memo @token_memo end |
Instance Method Details
#edit(edits) ⇒ Object
Apply edits expressed against the current source and return syntax only.
3322 3323 3324 |
# File 'lib/json5/generated_parser.rb', line 3322 def edit(edits) @mutex.synchronize { edit_locked(TextEdit.normalize(edits)) } end |
#last_full_fallback? ⇒ Boolean
Whether the last completed edit discarded all incremental reuse and reparsed the current source from a fresh token stream.
3340 |
# File 'lib/json5/generated_parser.rb', line 3340 def last_full_fallback? = @last_full_fallback |
#observe(&observer) ⇒ Object
Observe parser and incremental runtime events.
3328 3329 3330 |
# File 'lib/json5/generated_parser.rb', line 3328 def observe(&observer) @parser.observe(&observer) end |
#unobserve(subscription) ⇒ Object
3333 3334 3335 |
# File 'lib/json5/generated_parser.rb', line 3333 def unobserve(subscription) @parser.unobserve(subscription) end |