Package sc.parser

Class NestedParselet

    • Field Detail

      • suppressSpacing

        public boolean suppressSpacing
      • enableSpacing

        public boolean enableSpacing
      • disableTagMode

        public boolean disableTagMode
      • enableTagMode

        public boolean enableTagMode
      • suppressNewlines

        public boolean suppressNewlines
      • pushIndent

        public boolean pushIndent
      • popIndent

        public boolean popIndent
      • parselets

        public java.util.ArrayList<Parselet> parselets
      • allowNullElements

        public boolean allowNullElements
      • allowEmptyPartialElements

        public boolean allowEmptyPartialElements
      • complexStringType

        public boolean complexStringType
        From the IDE's perspective, by default a tree element
      • skipOnErrorParselet

        public Parselet skipOnErrorParselet
        Set this to a parselet to use when we want to try and reparse an element after skipping over error text. This parselet is applied whenever we encounter an error. As long as it matches
    • Constructor Detail

      • NestedParselet

        public NestedParselet()
      • NestedParselet

        public NestedParselet​(java.lang.String name,
                              int options)
      • NestedParselet

        public NestedParselet​(int options)
      • NestedParselet

        public NestedParselet​(java.lang.String name,
                              Parselet... toAdd)
      • NestedParselet

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

        public NestedParselet​(java.lang.String name,
                              int options,
                              Parselet... toAdd)
      • NestedParselet

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

      • set

        public void set​(Parselet... toAdd)
      • set

        public void set​(java.lang.String name,
                        Parselet... toAdd)
      • set

        public void set​(int ix,
                        Parselet toSet)
      • add

        public void add​(int ix,
                        Parselet toSet)
      • remove

        public void remove​(int ix)
      • removeParselet

        public void removeParselet​(Parselet p)
      • clear

        protected void clear()
      • add

        public void add​(Parselet... toAdd)
      • setResultClass

        public void setResultClass​(java.lang.Class c)
        Overrides:
        setResultClass in class Parselet
      • initParameterMapping

        protected void initParameterMapping()
      • resolveParameterMapping

        protected void resolveParameterMapping()
      • setParameterType

        protected void setParameterType​(sc.parser.NestedParselet.ParameterType type)
      • handlesProperty

        protected boolean handlesProperty​(java.lang.Object selector)
        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.
      • semanticPropertyChanged

        public boolean semanticPropertyChanged​(java.lang.Object parentParseNode,
                                               java.lang.Object semanticValue,
                                               java.lang.Object selector,
                                               java.lang.Object value)
        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.
      • arrayElementChanged

        public boolean arrayElementChanged​(java.lang.Object parseNode,
                                           java.util.List semanticValue,
                                           int index,
                                           java.lang.Object element,
                                           NestedParselet.ChangeType changeType)
      • arrayElementChanged

        public boolean arrayElementChanged​(java.lang.Object parseNode,
                                           java.util.List semanticValue,
                                           int startIndex,
                                           int index,
                                           java.lang.Object element,
                                           NestedParselet.ChangeType changeType)
        We are propagating an array value change through the hierarchy. If we can handle and update the parse tree we return true otherwise, we return false. We could regenerate the entire tree at this point but that would mean it was impossible to insert into a list incrementally.
      • regenerateIfTracking

        public boolean regenerateIfTracking​(ParentParseNode pnode,
                                            boolean finalGen)
      • regenerate

        public boolean regenerate​(IParseNode resNode,
                                  boolean finalGen)
      • getSeparatorSymbol

        public abstract java.lang.String getSeparatorSymbol()
      • toHeaderString

        public java.lang.String toHeaderString​(java.util.Map<Parselet,​java.lang.Integer> visited)
        Overrides:
        toHeaderString in class Parselet
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • toStringInternal

        protected java.lang.String toStringInternal​(java.util.Map<Parselet,​java.lang.Integer> visited)
      • getDebugName

        public java.lang.String getDebugName()
      • createInstance

        public java.lang.Object createInstance​(Parser parser,
                                               java.lang.Class theClass)
      • setSemanticValue

        public int setSemanticValue​(ParentParseNode parent,
                                    java.lang.Object node,
                                    int childIndex,
                                    int slotIndex,
                                    boolean skipSemanticValue,
                                    Parser parser,
                                    boolean replaceValue,
                                    boolean reparse,
                                    java.lang.Object replacedValue)
      • removeFromSemanticValue

        public boolean removeFromSemanticValue​(ParentParseNode parent,
                                               java.lang.Object node,
                                               int svCount,
                                               int childIndex,
                                               int slotIndex,
                                               boolean skipSemanticValue,
                                               Parser parser,
                                               boolean replaceValue,
                                               boolean reparse)
      • processSlotMappings

        public void processSlotMappings​(int startIx,
                                        ParentParseNode srcNode,
                                        java.lang.Object dstNode,
                                        boolean recurse,
                                        int childIndex,
                                        boolean reparse)
      • skipSemanticValue

        public boolean skipSemanticValue​(int index)
      • addResultToParent

        public boolean addResultToParent​(java.lang.Object node,
                                         ParentParseNode parent,
                                         int index,
                                         Parser parser)
        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 Parselet
        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.
      • addReparseResultToParent

        public boolean addReparseResultToParent​(java.lang.Object node,
                                                ParentParseNode parent,
                                                int svIndex,
                                                int childIndex,
                                                int slotIndex,
                                                Parser parser,
                                                java.lang.Object oldChildParseNode,
                                                DiffContext dctx,
                                                boolean removeExtraNodes,
                                                boolean parseArray)
        Overrides:
        addReparseResultToParent in class Parselet
      • 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 Parselet
      • newGeneratedSimpleParseNode

        protected ParseNode newGeneratedSimpleParseNode​(java.lang.Object value,
                                                        Parselet childParselet)
        Taking a short cut to the generation process. When we have a string for a distinct generated value, we can use the string as the generated output. We do have to account for any formatting parse nodes, i.e. spacing, newlines, etc. inserted automatically. We gather those up so that they are applied during the format method just as they would ordinarily be if we generated individual parse nodes for each child parselet.
      • newGeneratedSimpleParseNodeNoFormatting

        protected ParseNode newGeneratedSimpleParseNodeNoFormatting​(java.lang.Object value,
                                                                    Parselet childParselet)
      • emptyValue

        public boolean emptyValue​(GenerateContext ctx,
                                  java.lang.Object value)
        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 Parselet
        Parameters:
        ctx -
        value -
        Returns:
        true if there's no real value.
      • generateElement

        public abstract java.lang.Object generateElement​(GenerateContext ctx,
                                                         java.lang.Object value,
                                                         boolean isArray)
      • getChildParselet

        public abstract Parselet getChildParselet​(java.lang.Object parseNode,
                                                  int index)
        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
      • getChildParseletForIndex

        public abstract Parselet getChildParseletForIndex​(int index)
        Like the above, but returns null when the childParselet cannot be determined solely based on the index (i.e. for any OrderedChoice)
      • clone

        public java.lang.Object clone()
        Overrides:
        clone in class Parselet
      • format

        public void format​(FormatContext ctx,
                           IParseNode node)
        Description copied from class: Parselet
        The generate phase generate parse nodes in the output. The formatting phase turns these gene into string values. The parselet steers both of these operations through its generate and fo
        Overrides:
        format in class Parselet
      • isStringParameterMapping

        public boolean isStringParameterMapping()
      • isComplexStringType

        public boolean isComplexStringType()
        Description copied from class: Parselet
        From the IDE's perspective,
        Overrides:
        isComplexStringType in class Parselet
      • getParseletSlotIx

        public int getParseletSlotIx​(Parselet parseNodeChild)
        In the reparse case, we might need to determine which child parselet produced a given parsenode. We can only do this when we have a parse-node child unfortunately
      • getParseletSlotIxFromType

        public int getParseletSlotIxFromType​(java.lang.Object semValue)
      • acceptTree

        protected java.lang.String acceptTree​(SemanticContext ctx,
                                              java.lang.Object value,
                                              int startIx,
                                              int endIx)
        Description copied from class: Parselet
        Like accept but for hierarchical nodes, performs the 'accept' operation on children in the tree. We use this when accepting a cached or reparsed value, or generating a value. But during the parse operation, the accept is run on each node as part of the parse so we do not have to recurse to children.
        Overrides:
        acceptTree in class Parselet