Package sc.parser

Class ChainedResultSequence

  • All Implemented Interfaces:
    java.lang.Cloneable, ILifecycle, IParserConstants

    public class ChainedResultSequence
    extends Sequence
    A ChainedResultSequence is a special type of Sequence that always has 2 children. The second child is always parsed as 'optional'. If the second child is not parsed, the sequence just passes through the semantic value of the first child - the specific property mapping of this parselet is ignored. If the second child is parsed, the normal rules for a Sequence are used to produce the semantic value are applied.
    • Constructor Detail

      • ChainedResultSequence

        public ChainedResultSequence​(java.lang.String id,
                                     int options)
      • ChainedResultSequence

        public ChainedResultSequence​(int options)
      • ChainedResultSequence

        public ChainedResultSequence​(java.lang.String id,
                                     Parselet... toAdd)
      • ChainedResultSequence

        public ChainedResultSequence​(Parselet... toAdd)
      • ChainedResultSequence

        public ChainedResultSequence​(java.lang.String id,
                                     int options,
                                     Parselet... toAdd)
      • ChainedResultSequence

        public ChainedResultSequence​(int options,
                                     Parselet... toAdd)
    • Method Detail

      • addResultToParent

        public boolean addResultToParent​(java.lang.Object node,
                                         ParentParseNode parent,
                                         int index,
                                         Parser parser)
        Description copied from class: NestedParselet
        Adds the supplied result node produced by this parselet to the parent parse node. We are also provided the index of this parselet in the parent's sequence. Basically, this handles parselet specific options which handle how the result's value is produced. You might override this method if you want to determine how a particular parselet's result is merged into the parent pareselet's result.

        If you are skipping "node" in the results, you instead directly add children nodes to the parent. When you add a child node, it is important to specificy the value of the "skipsemanticValue" flag. This determines whether or not this element's value is included in the semantic value produced by the parent node.

        Overrides:
        addResultToParent in class NestedParselet
        Parameters:
        node - the result value for this parselet - usually a ParseNode or a ParentParseNode or some subclass of those.
        parent - the parent parse node we are added this result into.
        index - the position of this parselet in the parent's sequence
        Returns:
        true if we are to add "node" directly to the parent and false if this method took care already of propagating node to the parent.
      • setResultOnParent

        public boolean setResultOnParent​(java.lang.Object node,
                                         ParentParseNode parent,
                                         int index,
                                         Parser parser)
        Description copied from class: Parselet
        This method replicates the functionality of addResultToParent for the special case where we are parsing errors and we've reparsed the value of a node and need to replace it in it's parent before returning. It only handles a few of the semantic value mappings so far... another approach would be to throw away and rebuild the parent's value entirely. The key here is that when we update the parse node for a child, we also update the semantic value so the two are consistent.
        Overrides:
        setResultOnParent in class NestedParselet
      • propagateResult

        public java.lang.Object propagateResult​(java.lang.Object node)
        Description copied from class: Parselet
        Overridden in ChainResultSequence to do post-processing that would ordinarily be done in addResultToParent for a nested sequence
        Overrides:
        propagateResult in class Parselet
      • getSemanticValueSlotClass

        public java.lang.Class getSemanticValueSlotClass()
        If there is a propagated element we'll only apply the mappings to that guy.
        Overrides:
        getSemanticValueSlotClass in class Parselet
        Returns:
        the class for the semantic value for this slot.
      • semanticPropertyChanged

        public boolean semanticPropertyChanged​(java.lang.Object parentParseNode,
                                               java.lang.Object semanticValue,
                                               java.lang.Object selector,
                                               java.lang.Object value)
        Description copied from class: NestedParselet
        For a given parse node which we generated (or null). Returns false if the parselet is unable to handle the change. For a choice, this might be a signal to try another alternative.
        Overrides:
        semanticPropertyChanged in class NestedParselet
      • dataTypeMatches

        public boolean dataTypeMatches​(java.lang.Object other)
        Description copied from class: Sequence
        When we are trying to determine if a given node is produced by a given parselet, we use this method. It returns true if this parselet could have produced this data type.
        Overrides:
        dataTypeMatches in class Sequence
      • getReparseChildNode

        protected java.lang.Object getReparseChildNode​(java.lang.Object oldParseNode,
                                                       int ix,
                                                       boolean forceReparse)
        Overrides:
        getReparseChildNode in class Sequence
      • disableExtendedErrors

        protected boolean disableExtendedErrors()
        In partial values mode, if we get an error on slot 1, that's a match of slot 0 so even if there's a way to extend the error, do not do so
        Overrides:
        disableExtendedErrors in class Sequence
      • getSlotSemanticValue

        protected java.lang.Object getSlotSemanticValue​(int slotIx,
                                                        ISemanticNode semanticValue,
                                                        SaveRestoreCtx rctx)
        Description copied from class: Sequence
        For restoring the parseNode tree onto oldNode, for this sequence figure out which child node was produced by the the given slot index
        Overrides:
        getSlotSemanticValue in class Sequence
      • saveParse

        public void saveParse​(IParseNode pn,
                              ISemanticNode oldNode,
                              SaveParseCtx sctx)
        Description copied from class: Parselet
        The parselet method to save parselet ids, offsets, string-lengths etc. The info that when augmented by a de-serialized semantic node quickly reproduces the parse-node tree and attaches it to the model
        Overrides:
        saveParse in class Sequence
      • restore

        public java.lang.Object restore​(Parser parser,
                                        ISemanticNode oldNode,
                                        RestoreCtx rctx,
                                        boolean inherited)
        Description copied from class: Parselet
        The parselet method to re-create the parse node tree given the resulting model.
        Overrides:
        restore in class Sequence