Package sc.parser

Class OrderedChoice

  • All Implemented Interfaces:
    java.lang.Cloneable, ILifecycle, IParserConstants
    Direct Known Subclasses:
    IndexedChoice

    public class OrderedChoice
    extends NestedParselet
    A NestedParselet which represents a choice of parselets. You provide the list of child parselets and it matches them in order until one matches. Tha matching parselet's semantic value is used as the semantic value for the choice if it is a scalar. For an array ordered choice, it can successively match children and produce an array of its children.
    • Field Detail

      • NO_MATCH_ERROR

        public static final GenerateError NO_MATCH_ERROR
    • Constructor Detail

      • OrderedChoice

        public OrderedChoice()
      • OrderedChoice

        public OrderedChoice​(int options)
      • OrderedChoice

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

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

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

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

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

      • parse

        public java.lang.Object parse​(Parser parser)
        Description copied from class: Parselet
        The main parse method for the parselet. Use the supplied parser and generate a 'result' either a CharSequence or an IParseNode.
        Specified by:
        parse in class Parselet
      • restore

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

        public void saveParse​(IParseNode oldPN,
                              ISemanticNode oldSN,
                              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
        Specified by:
        saveParse in class Parselet
      • parseRepeatingChoice

        public java.lang.Object parseRepeatingChoice​(Parser parser)
      • reparseRepeatingChoice

        public java.lang.Object reparseRepeatingChoice​(Parser parser,
                                                       Parselet exitParselet,
                                                       java.lang.Object oldParseNode,
                                                       DiffContext dctx,
                                                       boolean forceReparse,
                                                       boolean extendErrors,
                                                       boolean extendedErrorOnly)
      • parseExtendedErrors

        public java.lang.Object parseExtendedErrors​(Parser parser,
                                                    Parselet exitParselet)
        Code copied alert! This is a lot like parseRepeatingChoice but skipping and stopping on exitParselet.
        Overrides:
        parseExtendedErrors in class Parselet
        Returns:
        null if we cannot extend our value. In this case, the parent parselet just uses the value it already has for this match.
      • getMatchingParselets

        protected java.util.List<Parselet> getMatchingParselets​(Parser parser)
      • generate

        public java.lang.Object generate​(GenerateContext ctx,
                                         java.lang.Object value)
        For the OrderedChoice, we have to figure out which choice was gnenerated.
        Specified by:
        generate in class Parselet
      • 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
      • emptyValue

        public boolean emptyValue​(GenerateContext ctx,
                                  java.lang.Object value)
        Description copied from class: NestedParselet
        Determines if there is any semantic information left in the value supplied as determined by the parselet. If the value is null, it is empty. If the parselet sets properties on its parent object during the parse phase, we view that parent as empty if all of the slots are null.

        This method lets us determine when an optional slot has failed... if it is empty a failure is not reported.

        Overrides:
        emptyValue in class NestedParselet
        Returns:
        true if there's no real value.
      • getChildParselet

        public Parselet getChildParselet​(java.lang.Object childParseNode,
                                         int index)
        Description copied from class: NestedParselet
        Best effort at returning the parselet for a given parent parse node with the specified index into the children's array. Works well for Sequence but OrderedChoice must use the data type or context in the parse node and that's not always available
        Specified by:
        getChildParselet in class NestedParselet
      • getChildParseletForIndex

        public Parselet getChildParseletForIndex​(int index)
        Description copied from class: NestedParselet
        Like the above, but returns null when the childParselet cannot be determined solely based on the index (i.e. for any OrderedChoice)
        Specified by:
        getChildParseletForIndex in class NestedParselet
      • elementTypeMatches

        public boolean elementTypeMatches​(java.lang.Object other)
        Returns true if this parselet could have produced the given semanticValue.
        Overrides:
        elementTypeMatches in class Parselet
      • dataTypeMatches

        public boolean dataTypeMatches​(java.lang.Object other)
        Returns true if this parselet could have produced the given semanticValue.
        Overrides:
        dataTypeMatches in class Parselet
      • handlesProperty

        protected boolean handlesProperty​(java.lang.Object selector)
        Description copied from class: NestedParselet
        During generation, to perform an incremental update, we want to find the node which handles a property change - working down the parse tree. If there is a "*" in a slot, we send that change down that path.
        Overrides:
        handlesProperty in class NestedParselet