Method: PredictionContextFunctions::Methods#mergeRoot
- Defined in:
- lib/antlr4/PredictionContext.rb
#mergeRoot(a, b, rootIsWildcard) ⇒ Object
Handle case where at least one of a or b is #EMPTY. In the following diagrams, the symbol $ is used to represent #EMPTY.
<h2>Local-Context Merges</h2>
<p>These local-context merge operations are used when rootIsWildcard is true.</p>
<p>#EMPTY is superset of any graph; return #EMPTY.
<embed src=“images/LocalMerge_EmptyRoot.svg” type=“image/svg+xml”/></p>
<p>#EMPTY and anything is #EMPTY, so merged parent is #EMPTY; return left graph.
<embed src=“images/LocalMerge_EmptyParent.svg” type=“image/svg+xml”/></p>
<p>Special case of last merge if local context.
<embed src=“images/LocalMerge_DiffRoots.svg” type=“image/svg+xml”/></p>
<h2>Full-Context Merges</h2>
<p>These full-context merge operations are used when rootIsWildcard is false.</p>
<p><embed src=“images/FullMerge_EmptyRoots.svg” type=“image/svg+xml”/></p>
<p>Must keep all contexts; #EMPTY in array is a special value (and null parent).
<embed src=“images/FullMerge_EmptyRoot.svg” type=“image/svg+xml”/></p>
<p><embed src=“images/FullMerge_SameRoot.svg” type=“image/svg+xml”/></p>
otherwise false to indicate a full-context merge / def mergeRoot(a:SingletonPredictionContext, b:SingletonPredictionContext, rootIsWildcard:bool):
456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 |
# File 'lib/antlr4/PredictionContext.rb', line 456 def mergeRoot(a, b, rootIsWildcard) if rootIsWildcard return PredictionContext.EMPTY if PredictionContext.EMPTY == a ## + b =# return PredictionContext.EMPTY if PredictionContext.EMPTY == b # a +# =# else if PredictionContext.EMPTY == a and PredictionContext.EMPTY == b then return PredictionContext.EMPTY # $ + $ = $ elsif PredictionContext.EMPTY == a # $ + x = [$,x] payloads = [ b.returnState, PredictionContext::EMPTY_RETURN_STATE ] parents = [ b.parentCtx, nil ] return ArrayPredictionContext.new(parents, payloads) elsif PredictionContext.EMPTY == b # x + $ = [$,x] ($ is always first if present) payloads = [ a.returnState, PredictionContext::EMPTY_RETURN_STATE ] parents = [ a.parentCtx, nil ] return ArrayPredictionContext.new(parents, payloads) end end return nil end |