示例#1
0
 public void Create2Nodes()
 {
     var node = new StringNode("a");
     node.AddFirst(new StringNode("b"));
     node.ToString().Should().Be("a\n  b\n".NormalizeNewLine());
     string.Join("", node.Descendants().Select(n => n.Value)).Should().Be("b");
 }
示例#2
0
            /// <inheritdoc/>
            public override (Node Head, Node Tail) Insert(Int32 index, String element)
            {
                Node head;
                Node tail;

                if (index == 0)
                {
                    tail          = this;
                    head          = new StringNode(element, previous: null, next: tail);
                    tail.Previous = head;
                }
                else if (index == Count)
                {
                    head      = this;
                    tail      = new StringNode(element, previous: head, next: null);
                    head.Next = tail;
                }
                else
                {
                    head = Slice(0, index);
                    tail = Slice(index, Count - index);
                    Node mid = new StringNode(element, previous: head, next: tail);
                    head.Next     = mid;
                    tail.Previous = mid;
                }
                return(head, tail);
            }
示例#3
0
 public void Visit(StringNode node)
 {
     if (!scope.IsDefinedType("String", out node.StaticType))
     {
         errors.Add(SemanticError.NotDeclaredType(new TypeNode(node.Line, node.Column, "Int")));
     }
 }
示例#4
0
        /*
        ** Garbage collection function.
        ** This function traverse the string list freeing unindexed strings
        */
        public static Long lua_strcollector()
        {
            StringNode curr = string_root, prev = null;
            Long       counter = 0;

            while (curr != null)
            {
                StringNode next = curr.next;
                if ((char)0 == curr.ts.marked)
                {
                    if (prev == null)
                    {
                        string_root = next;
                    }
                    else
                    {
                        prev.next = next;
                    }
                    luaI_free_StringNode(ref curr);
                    ++counter;
                }
                else
                {
                    curr.ts.marked = (char)0;
                    prev           = curr;
                }
                curr = next;
            }
            return(counter);
        }
        public static void SimpleSmokeTest()
        {
            IParser <AstNode> parser = GrammarParser.CreateParser(@"
<bool> ::= <true> | <false>
<true> ::= ""true""
<false> ::= ""false""
");

            string  input = @"true";
            AstNode node  = parser.Parse(input);

            AssertThat(node).IsExactlyInstanceOf <ObjectNode>();
            ObjectNode obj = node as ObjectNode;

            AssertThat(obj.Type).IsEqualTo("bool");
            AssertThat(obj.Children).HasSize(1);
            AstNode child = obj.Children[0];

            AssertThat(child).IsExactlyInstanceOf <ObjectNode>();
            ObjectNode childObj = child as ObjectNode;

            AssertThat(childObj.Type).IsEqualTo("true");
            AssertThat(childObj.Children).HasSize(1);
            AstNode innerChild = childObj.Children[0];

            AssertThat(innerChild).IsExactlyInstanceOf <StringNode>();
            StringNode innerChildStr = innerChild as StringNode;

            AssertThat(innerChildStr.Value).IsEqualTo("true");
            AssertThat(node.ToString()).IsEqualTo(@"bool(true(""true""))");
        }
示例#6
0
 // Token: 0x0600002C RID: 44 RVA: 0x00002830 File Offset: 0x00000A30
 private void ReadInDictionary(IDictionary <string, PNode> node, int nodeLength, BinaryFormatReader.ReaderState readerState)
 {
     byte[] array  = new byte[nodeLength * readerState.IndexSize];
     byte[] array2 = new byte[nodeLength * readerState.IndexSize];
     if (readerState.Stream.Read(array, 0, array.Length) != array.Length)
     {
         throw new PListFormatException();
     }
     if (readerState.Stream.Read(array2, 0, array2.Length) != array2.Length)
     {
         throw new PListFormatException();
     }
     for (int i = 0; i < nodeLength; i++)
     {
         short      elemIdx    = (readerState.IndexSize == 1) ? ((short)array[i]) : EndianConverter.NetworkToHostOrder(BitConverter.ToInt16(array, 2 * i));
         StringNode stringNode = this.ReadInternal(readerState, (int)elemIdx) as StringNode;
         if (stringNode == null)
         {
             throw new PListFormatException("Key is not a string");
         }
         elemIdx = ((readerState.IndexSize == 1) ? ((short)array2[i]) : EndianConverter.NetworkToHostOrder(BitConverter.ToInt16(array2, 2 * i)));
         PNode value = this.ReadInternal(readerState, (int)elemIdx);
         node.Add(stringNode.Value, value);
     }
 }
示例#7
0
        public string Pop()
        {
            string lastItem = tailPointer.Str.ToString();
            StringNode nodeWalker = headPointer;
            //StringNode nodeToDelete = tailPointer;

            if (headPointer == null)
            {
                // if pop is called on empty stack
                throw new NullReferenceException("Can't call Pop on an empty Stack");
            }

            if (nodeWalker != tailPointer)
            {
                while (nodeWalker.Next != tailPointer)
                {
                    nodeWalker = nodeWalker.Next;
                }
                tailPointer = nodeWalker;
            }
            else
            {
                headPointer = null;
                tailPointer = null;
            }

            return lastItem;
        }
        public void VisitStringNode(StringNode stringNode)
        {
            if (!this._isScriptTag)
            {
                if (this._isPreTag)
                {
                    this._results.Append(stringNode.GetText());
                }
                else
                {
                    String text = Translate.Decode(stringNode.GetText());

                    if (this.GetReplaceNonBreakingSpace())
                    {
                        text = text.Replace('\a', ' ');
                    }
                    if (this.GetCollapse())
                    {
                        this.Collapse(this._results, text);
                    }
                    else
                    {
                        this._results.Append(text);
                    }
                }
            }
        }
示例#9
0
 public static List <string> GetStringArrayValueFromPList(PNode rootNode, string key)
 {
     if (rootNode is DictionaryNode)
     {
         PNode value;
         if (((DictionaryNode)rootNode).TryGetValue(key, out value))
         {
             if (value is ArrayNode)
             {
                 ArrayNode     array  = (ArrayNode)value;
                 List <string> result = new List <string>();
                 foreach (PNode node in array)
                 {
                     StringNode stringNode = node as StringNode;
                     if (stringNode != null)
                     {
                         result.Add(stringNode.Value);
                     }
                 }
                 return(result);
             }
         }
     }
     return(null);
 }
示例#10
0
    protected override void OnTriggerEnter2D(Collider2D other)
    {
        base.OnTriggerEnter2D(other);

        if (other.CompareTag("Node"))
        {
            StringNode node = other.GetComponentInParent <StringNode>();

            if (!node.hasTarget)
            {
                // go to the string node and stay at it
                canFollow    = false;
                pingLocation = other.transform.position;
                LevelManager.levelManager.player.RemoveFollower(this);

                coll.isTrigger = true;
                node.hasTarget = true;
                other.enabled  = false;

                Instantiate(pingRing, transform.position, Quaternion.identity)
                .GetComponent <PingRing>().Init(2f, 4f, 0.2f, nodeColor.WithA(0.5f));
                audioSource.PlayOneShot(pingClip);
            }
        }
    }
示例#11
0
        public override void VisitStringNode(StringNode node)
        {
            var literal = LiteralExpression(SyntaxKind.StringLiteralExpression, Literal(node.Text));

            literal = GetNodeWithAnnotation(literal, node.Location) as LiteralExpressionSyntax;
            expressions.Push(literal);
        }
示例#12
0
        /// <summary> Finds a string node, however embedded it might be, and returns
        /// it. The string node will retain links to its parents, so
        /// further navigation is possible.
        /// </summary>
        /// <param name="">searchText
        /// </param>
        /// <returns> The list of string nodes (recursively) found.
        ///
        /// </returns>
        public virtual StringNode[] DigupStringNode(string searchText)
        {
            NodeList nodeList    = SearchFor(searchText);
            NodeList stringNodes = new NodeList();

            for (int i = 0; i < nodeList.Size; i++)
            {
                Node node = nodeList[i];
                if (node is StringNode)
                {
                    stringNodes.Add(node);
                }
                else
                {
                    if (node is CompositeTag)
                    {
                        CompositeTag ctag  = (CompositeTag)node;
                        StringNode[] nodes = ctag.DigupStringNode(searchText);
                        foreach (Node nestedNode in nodes)
                        {
                            stringNodes.Add(nestedNode);
                        }
                    }
                }
            }
            StringNode[] stringNode = new StringNode[stringNodes.Size];
            for (int i = 0; i < stringNode.Length; i++)
            {
                stringNode[i] = (StringNode)stringNodes[i];
            }
            return(stringNode);
        }
示例#13
0
        ExpressionNode Input(ExpressionNode type, Context context)
        {
            var data   = new StringNode(Console.ReadLine());
            var result = interpreter.Run(type, data);

            return(result);
        }
示例#14
0
        public void Accept(StringNode node)
        {
            string symbol = nextSymbol();

            append("pushi .{0}", symbol);
            strings.Add(symbol, node.String);
        }
示例#15
0
        public void GenerateCode(StringNode node, ICIL_CodeGenerator codeGenerator)
        {
            #region .DATA

            var data = CIL_Factory.DefineData(node.Text);
            CIL_Factory.AddData(data);

            #endregion

            #region .CODE

            var str = codeGenerator.DefineVariable();

            codeGenerator.AddLocalVariable(
                new CIL_LocalVariable(str));

            codeGenerator.AddInstruction(new Load(str, data));

            //strObj
            node.Holder = codeGenerator.DefineVariable();

            codeGenerator.AddInstruction(
                new Allocate((Variable)node.Holder, $"{BuiltIn.String}"));

            codeGenerator.AddLocalVariable(
                new CIL_LocalVariable((Variable)node.Holder));


            codeGenerator.AddInstruction(
                new SetAttr((Variable)node.Holder,
                            $"{Attribute.String_value}",
                            str));
            #endregion
        }
示例#16
0
        public void Should_evaluate_true_for_non_empty_string_node()
        {
            var inputNode = new StringNode("abc");
            var evaluator = new BooleanEvaluator();
            var result    = evaluator.Eval(inputNode);

            result.ShouldBeOfType <TrueNode>();
        }
示例#17
0
 public void Visit(StringNode node)
 {
     IC.Add(new AssignmentStringToVariable(VariableManager.PeekVariableCounter(), node.Text));
     if (special_object_return_type)
     {
         SetReturnType("String");
     }
 }
 public void Visit(StringNode node)
 {
     Code.Add(new AssignStrToVarCodeLine(VariableManager.PeekVariableCounter(), node.Value));
     if (object_return_type)
     {
         Code.Add(new AssignStrToVarCodeLine(return_type, "String"));
     }
 }
示例#19
0
    public void ToNodes(ICodeNode parentNode)
    {
        HighlightableButton highlightableButton = (GameObjectHelper.HasComponent <HighlightableButton>(this.gameObject)) ? this.GetComponent <HighlightableButton>() : null;
        StringNode          stringNode          = new StringNode(highlightableButton, GetValue());

        stringNode.NodeName = GetName();
        parentNode.AddChildNode(stringNode);
    }
示例#20
0
        public void Should_evaluate_false_for_null_string_node()
        {
            var inputNode = new StringNode(null);
            var evaluator = new BooleanEvaluator();
            var result    = evaluator.Eval(inputNode);

            result.ShouldBeOfType <FalseNode>();
        }
        public StringNode String(string value)
        {
            StringNode stringNode = new StringNode();

            Match(TokenType.STRING);
            stringNode.Value = value;
            return(stringNode);
        }
示例#22
0
        public void Deserialize_String_Test(string source)
        {
            var node = new StringNode(source);
            var res  = _deserializer.Deserialize <string>(node);

            Assert.That(res, Is.TypeOf <string>());
            Assert.AreEqual(source, res);
        }
示例#23
0
        private StringNode ParseString()
        {
            Expect(TokenType.STRING, TokenType.HERE_STRING);
            var str = new StringNode(Position(), Current().Text);

            Next();
            return(str);
        }
示例#24
0
        private StringNode parseString()
        {
            expect(TokenType.STRING);
            var str = new StringNode(current().Data);

            next();
            return(str);
        }
示例#25
0
        public void StringParser_Null()
        {
            StringParser parser = new StringParser();
            string       token  = "ok";

            StringNode node = (StringNode)parser.Parse(token);

            Assert.IsNull(node);
        }
示例#26
0
        public void StringParser_EscapedQuote()
        {
            StringParser parser = new StringParser();
            string       token  = "\"\\\"\"";

            StringNode node = (StringNode)parser.Parse(token);

            Assert.AreEqual("\"", node.Value());
        }
示例#27
0
        public void StringParser_Interpolated()
        {
            StringParser parser = new StringParser();
            string       token  = "\"hello {{{world}}}\"";

            StringNode node = (StringNode)parser.Parse(token);

            Assert.IsTrue(node.Interpolated);
        }
示例#28
0
    public static GraphNode ToGraphNode(StringNode node)
    {
        var output = new GraphNode(node.GetHashCode(), "\"'" + node.Representation.Replace(@"\", @"\\").Replace("'", @"\'").Replace("\"", "\\\"") + "'\"");

        output.AddProperty("color", "orange");
        output.AddProperty("tooltip", nameof(StringNode));

        return(output);
    }
示例#29
0
        public void StringParser_ShortString()
        {
            StringParser parser = new StringParser();
            string       token  = "\"true\"";

            StringNode node = (StringNode)parser.Parse(token);

            Assert.AreEqual("true", node.Value());
        }
示例#30
0
        public void StringParser_ListOfTwoShouldNotBeAString()
        {
            StringParser parser = new StringParser();
            string       token  = "('hello' 'world')";

            StringNode node = (StringNode)parser.Parse(token);

            Assert.IsNull(node);
        }
示例#31
0
        public void StringParser_MismatchedQuotes()
        {
            StringParser parser = new StringParser();
            string       token  = "ok\"";

            StringNode node = (StringNode)parser.Parse(token);

            Assert.IsNull(node);
        }
示例#32
0
 public ExpressionNode Run(ExpressionNode node, StringNode data)
 {
     return(Evaluate(new FunctionCallNode
     {
         Argument = data,
         CalleeExpression = node,
         Context = globalContext
     }, globalContext));
 }
示例#33
0
        public int FindMaximumChainLength(string[] lines)
        {
            if (lines.Length == 1)
            {
                return 0;
            }

            var words = new HashSet<string>(lines);
            var wordsMapping = new Dictionary<string, StringNode>();

            for (int i = 1; i < lines.Length; i++)
            {
                string word = lines[i];

                if (!wordsMapping.ContainsKey(word))
                {
                    var wordNode = new StringNode(word);
                    wordsMapping[word] = wordNode;
                }

                for (int j = 0; j < word.Length; j++)
                {
                    var newWord = word.Remove(j, 1);
                    if (words.Contains(newWord))
                    {
                        if (!wordsMapping.ContainsKey(newWord))
                        {
                            wordsMapping.Add(newWord, new StringNode(newWord));
                        }
                        var newWordNode = wordsMapping[newWord];
                        wordsMapping[word].Children.Add(newWordNode);
                    }
                }
            }

            var nodes = wordsMapping.Values;
            var visited = new HashSet<StringNode>();
            int maxDepth = 1;

            foreach (var node in nodes)
            {
                visited.Clear();
                visited.Add(node);
                int currentDepth = ExpandNode(node, visited, 1);
                if (currentDepth > maxDepth)
                {
                    maxDepth = currentDepth;
                }
            }

            return maxDepth;
        }
示例#34
0
        StringNode tailPointer; // = null;

        #endregion Fields

        #region Constructors

        public Stack()
        {
            headPointer = null;
            tailPointer = null;
        }
示例#35
0
 protected bool Equals(StringNode other)
 {
     return string.Equals(Value, other.Value);
 }
示例#36
0
 public void Push(string newString)
 {
     StringNode newNode = new StringNode(newString);
     /*if (!(newString is string))
     {
         throw new ArgumentException("Argument passed in is invalid");
     }*/
     if (headPointer == null)
     {
         headPointer = newNode;
         tailPointer = newNode;
     }
     else
     {
         tailPointer.Next = newNode;
         tailPointer = newNode;
     }
 }
示例#37
0
 public StringNode(StringNode rhs)
     : base(rhs)
 {
     Value = rhs.Value;
 }
示例#38
0
        public void RangeNodeTest_IncompatibleTypes()
        {
            StreamLocation expectedLocation = new StreamLocation(3, 2, 1);
            SimpleValueNode testLowBound = new NumberNode("1", new StreamLocation());
            SimpleValueNode testUpperBound = new StringNode("10", new StreamLocation());
            bool testInclusiveLeft = true;
            bool testInclusiveRight = true;

            RangeNode sut = new RangeNode(testLowBound, testInclusiveLeft, testUpperBound, testInclusiveRight, expectedLocation);
        }
示例#39
0
        private int ExpandNode(StringNode node, HashSet<StringNode> visited, int depth)
        {
            int maxDepth = depth;
            foreach (var child in node.Children)
            {
                if (!visited.Contains(child))
                {
                    visited.Add(child);
                    int currentDepth = ExpandNode(child, visited, depth + 1);
                    if (currentDepth > maxDepth)
                    {
                        maxDepth = currentDepth;
                    }
                }
            }

            return maxDepth;
        }
示例#40
0
    // throws RecognitionException [1]
    // $ANTLR end "expr_dm"
    // $ANTLR start "expr"
    // C:\\Users\\Danaice\\Desktop\\lastversion\\Dany_gramatica tiger ANTLR oficial\\tiger_grammar.g:167:1: expr returns [TigerNode exp] : ( STR | INT | id1= ID ( ( COR_A expr_or COR_C OF )=> COR_A idexp1= expr_or COR_C OF idexp= expr_or | idp4= ptocor ida1= asig | LLAV_A fieldlist LLAV_C idp1= ptocor | PAR_A exprlist PAR_C idp3= ptocor ) | MENOS expr_or | BREAK | NIL | PAR_A exprseq PAR_C idp9= ptocor | IF idif= expr_or THEN idthen= expr_or ifthenelse | WHILE idexp3= expr_or DO iddo= expr_or | FOR id5= ID ASIG idasig= expr_or TO idto= expr_or DO iddo= expr_or | LET decllist IN exprseq END );
    public TigerNode expr()
    {
        TigerNode exp = null;

        IToken id1 = null;
        IToken id5 = null;
        IToken STR14 = null;
        IToken INT15 = null;
        IToken MENOS19 = null;
        IToken BREAK20 = null;
        IToken NIL21 = null;
        IToken PAR_A23 = null;
        IToken IF25 = null;
        IToken WHILE26 = null;
        IToken FOR27 = null;
        IToken LET30 = null;
        TigerNode idexp1 = null;

        TigerNode idexp = null;

        List<Access> idp4 = null;

        AssingmentNode ida1 = null;

        List<Access> idp1 = null;

        List<Access> idp3 = null;

        List<Access> idp9 = null;

        TigerNode idif = null;

        TigerNode idthen = null;

        TigerNode idexp3 = null;

        TigerNode iddo = null;

        TigerNode idasig = null;

        TigerNode idto = null;

        tiger_grammarParser.fieldlist_return fieldlist16 = null;

        List<TigerNode> exprlist17 = null;

        TigerNode expr_or18 = null;

        List<TigerNode> exprseq22 = null;

        TigerNode ifthenelse24 = null;

        List<DeclarationNode> decllist28 = null;

        List<TigerNode> exprseq29 = null;

        try
        {
            // C:\\Users\\Danaice\\Desktop\\lastversion\\Dany_gramatica tiger ANTLR oficial\\tiger_grammar.g:167:30: ( STR | INT | id1= ID ( ( COR_A expr_or COR_C OF )=> COR_A idexp1= expr_or COR_C OF idexp= expr_or | idp4= ptocor ida1= asig | LLAV_A fieldlist LLAV_C idp1= ptocor | PAR_A exprlist PAR_C idp3= ptocor ) | MENOS expr_or | BREAK | NIL | PAR_A exprseq PAR_C idp9= ptocor | IF idif= expr_or THEN idthen= expr_or ifthenelse | WHILE idexp3= expr_or DO iddo= expr_or | FOR id5= ID ASIG idasig= expr_or TO idto= expr_or DO iddo= expr_or | LET decllist IN exprseq END )
            int alt8 = 11;
            switch ( input.LA(1) )
            {
            case STR:
                {
                alt8 = 1;
                }
                break;
            case INT:
                {
                alt8 = 2;
                }
                break;
            case ID:
                {
                alt8 = 3;
                }
                break;
            case MENOS:
                {
                alt8 = 4;
                }
                break;
            case BREAK:
                {
                alt8 = 5;
                }
                break;
            case NIL:
                {
                alt8 = 6;
                }
                break;
            case PAR_A:
                {
                alt8 = 7;
                }
                break;
            case IF:
                {
                alt8 = 8;
                }
                break;
            case WHILE:
                {
                alt8 = 9;
                }
                break;
            case FOR:
                {
                alt8 = 10;
                }
                break;
            case LET:
                {
                alt8 = 11;
                }
                break;
                default:
                    if ( state.backtracking > 0 ) {state.failed = true; return exp;}
                    NoViableAltException nvae_d8s0 =
                        new NoViableAltException("", 8, 0, input);

                    throw nvae_d8s0;
            }

            switch (alt8)
            {
                case 1 :
                    // C:\\Users\\Danaice\\Desktop\\lastversion\\Dany_gramatica tiger ANTLR oficial\\tiger_grammar.g:168:13: STR
                    {
                        STR14=(IToken)Match(input,STR,FOLLOW_STR_in_expr1153); if (state.failed) return exp;
                        if ( (state.backtracking==0) )
                        {

                                               string s = STR14.Text;
                                               string[] t = s.Split('"');
                                      	     exp =  new StringNode(t[1]);
                                      	     exp.Col=STR14.CharPositionInLine;
                                      	     exp.Row=STR14.Line;
                        }

                    }
                    break;
                case 2 :
                    // C:\\Users\\Danaice\\Desktop\\lastversion\\Dany_gramatica tiger ANTLR oficial\\tiger_grammar.g:175:13: INT
                    {
                        INT15=(IToken)Match(input,INT,FOLLOW_INT_in_expr1172); if (state.failed) return exp;
                        if ( (state.backtracking==0) )
                        {

                                               exp =  new IntNode(int.Parse(INT15.Text));
                                               exp.Col=INT15.CharPositionInLine;
                                               exp.Row=INT15.Line;
                        }

                    }
                    break;
                case 3 :
                    // C:\\Users\\Danaice\\Desktop\\lastversion\\Dany_gramatica tiger ANTLR oficial\\tiger_grammar.g:180:13: id1= ID ( ( COR_A expr_or COR_C OF )=> COR_A idexp1= expr_or COR_C OF idexp= expr_or | idp4= ptocor ida1= asig | LLAV_A fieldlist LLAV_C idp1= ptocor | PAR_A exprlist PAR_C idp3= ptocor )
                    {
                        id1=(IToken)Match(input,ID,FOLLOW_ID_in_expr1204); if (state.failed) return exp;
                        // C:\\Users\\Danaice\\Desktop\\lastversion\\Dany_gramatica tiger ANTLR oficial\\tiger_grammar.g:180:20: ( ( COR_A expr_or COR_C OF )=> COR_A idexp1= expr_or COR_C OF idexp= expr_or | idp4= ptocor ida1= asig | LLAV_A fieldlist LLAV_C idp1= ptocor | PAR_A exprlist PAR_C idp3= ptocor )
                        int alt7 = 4;
                        alt7 = dfa7.Predict(input);
                        switch (alt7)
                        {
                            case 1 :
                                // C:\\Users\\Danaice\\Desktop\\lastversion\\Dany_gramatica tiger ANTLR oficial\\tiger_grammar.g:181:24: ( COR_A expr_or COR_C OF )=> COR_A idexp1= expr_or COR_C OF idexp= expr_or
                                {
                                    Match(input,COR_A,FOLLOW_COR_A_in_expr1245); if (state.failed) return exp;
                                    PushFollow(FOLLOW_expr_or_in_expr1249);
                                    idexp1 = expr_or();
                                    state.followingStackPointer--;
                                    if (state.failed) return exp;
                                    Match(input,COR_C,FOLLOW_COR_C_in_expr1251); if (state.failed) return exp;
                                    Match(input,OF,FOLLOW_OF_in_expr1253); if (state.failed) return exp;
                                    PushFollow(FOLLOW_expr_or_in_expr1257);
                                    idexp = expr_or();
                                    state.followingStackPointer--;
                                    if (state.failed) return exp;
                                    if ( (state.backtracking==0) )
                                    {

                                                                         exp =  new ArrayNode(id1.Text,idexp1,idexp);
                                                                         exp.Col=id1.CharPositionInLine; exp.Row=id1.Line;

                                    }

                                }
                                break;
                            case 2 :
                                // C:\\Users\\Danaice\\Desktop\\lastversion\\Dany_gramatica tiger ANTLR oficial\\tiger_grammar.g:186:24: idp4= ptocor ida1= asig
                                {
                                    PushFollow(FOLLOW_ptocor_in_expr1318);
                                    idp4 = ptocor();
                                    state.followingStackPointer--;
                                    if (state.failed) return exp;
                                    PushFollow(FOLLOW_asig_in_expr1322);
                                    ida1 = asig();
                                    state.followingStackPointer--;
                                    if (state.failed) return exp;
                                    if ( (state.backtracking==0) )
                                    {

                                                  		       if(idp4.Count > 0 && ida1 !=null)
                                                  		       {
                                                  		           exp =  ida1;
                                                  		           ((AssingmentNode)exp).LeftExpr = new ListLValueNode(new VariableNode(id1.Text),idp4);
                                                  		           exp.Col=id1.CharPositionInLine; exp.Row=id1.Line;
                                                  		       }
                                                  		       else if(idp4.Count > 0)
                                                  		       {
                                                  		           exp =  new ListLValueNode(new VariableNode(id1.Text),idp4);
                                                  		           exp.Col=id1.CharPositionInLine; exp.Row=id1.Line;
                                                  		       }
                                                  		       else if(ida1 !=null)
                                                  		       {
                                                  		           exp =  ida1;
                                                  		           ((AssingmentNode)exp).LeftExpr = new VariableNode(id1.Text);
                                                  		           exp.Col=id1.CharPositionInLine; exp.Row=id1.Line;
                                                  		       }
                                                  		       else
                                                  		       {
                                                  		           exp =  new VariableNode(id1.Text);
                                                  		           exp.Col=id1.CharPositionInLine;
                                                  		           exp.Row=id1.Line;
                                                  		       }

                                    }

                                }
                                break;
                            case 3 :
                                // C:\\Users\\Danaice\\Desktop\\lastversion\\Dany_gramatica tiger ANTLR oficial\\tiger_grammar.g:211:23: LLAV_A fieldlist LLAV_C idp1= ptocor
                                {
                                    Match(input,LLAV_A,FOLLOW_LLAV_A_in_expr1349); if (state.failed) return exp;
                                    PushFollow(FOLLOW_fieldlist_in_expr1351);
                                    fieldlist16 = fieldlist();
                                    state.followingStackPointer--;
                                    if (state.failed) return exp;
                                    Match(input,LLAV_C,FOLLOW_LLAV_C_in_expr1353); if (state.failed) return exp;
                                    PushFollow(FOLLOW_ptocor_in_expr1357);
                                    idp1 = ptocor();
                                    state.followingStackPointer--;
                                    if (state.failed) return exp;
                                    if ( (state.backtracking==0) )
                                    {

                                                                   if(idp1.Count > 0)
                                                                   {
                                                                       exp =  new ListLValueNode(new RecordNode(id1.Text, ((fieldlist16 != null) ? fieldlist16.listid : null), ((fieldlist16 != null) ? fieldlist16.listexp : null)),idp1);
                                                                       exp.Col=id1.CharPositionInLine; exp.Row=id1.Line;
                                                                   }
                                                                        else{ exp =  new RecordNode(id1.Text, ((fieldlist16 != null) ? fieldlist16.listid : null), ((fieldlist16 != null) ? fieldlist16.listexp : null));
                                                                              exp.Col=id1.CharPositionInLine; exp.Row=id1.Line;
                                                                            }

                                    }

                                }
                                break;
                            case 4 :
                                // C:\\Users\\Danaice\\Desktop\\lastversion\\Dany_gramatica tiger ANTLR oficial\\tiger_grammar.g:221:22: PAR_A exprlist PAR_C idp3= ptocor
                                {
                                    Match(input,PAR_A,FOLLOW_PAR_A_in_expr1382); if (state.failed) return exp;
                                    PushFollow(FOLLOW_exprlist_in_expr1384);
                                    exprlist17 = exprlist();
                                    state.followingStackPointer--;
                                    if (state.failed) return exp;
                                    Match(input,PAR_C,FOLLOW_PAR_C_in_expr1386); if (state.failed) return exp;
                                    PushFollow(FOLLOW_ptocor_in_expr1390);
                                    idp3 = ptocor();
                                    state.followingStackPointer--;
                                    if (state.failed) return exp;
                                    if ( (state.backtracking==0) )
                                    {

                                                                  if(idp3.Count > 0)
                                                                  {
                                                                      exp =  new ListLValueNode(new CallFunctionNode(id1.Text, exprlist17),idp3);
                                                                      exp.Col=id1.CharPositionInLine; exp.Row=id1.Line;
                                                                  }
                                                                  else{ exp =  new CallFunctionNode(id1.Text, exprlist17);
                                                                        exp.Col=id1.CharPositionInLine; exp.Row=id1.Line;
                                                                  }

                                    }

                                }
                                break;

                        }

                    }
                    break;
                case 4 :
                    // C:\\Users\\Danaice\\Desktop\\lastversion\\Dany_gramatica tiger ANTLR oficial\\tiger_grammar.g:233:13: MENOS expr_or
                    {
                        MENOS19=(IToken)Match(input,MENOS,FOLLOW_MENOS_in_expr1446); if (state.failed) return exp;
                        PushFollow(FOLLOW_expr_or_in_expr1448);
                        expr_or18 = expr_or();
                        state.followingStackPointer--;
                        if (state.failed) return exp;
                        if ( (state.backtracking==0) )
                        {

                                                     exp =  new MinusUnaryNode(expr_or18);
                                                     exp.Col=MENOS19.CharPositionInLine;
                                                     exp.Row = MENOS19.Line;

                        }

                    }
                    break;
                case 5 :
                    // C:\\Users\\Danaice\\Desktop\\lastversion\\Dany_gramatica tiger ANTLR oficial\\tiger_grammar.g:239:13: BREAK
                    {
                        BREAK20=(IToken)Match(input,BREAK,FOLLOW_BREAK_in_expr1478); if (state.failed) return exp;
                        if ( (state.backtracking==0) )
                        {

                                                 exp =  new BreakNode();
                                                 exp.Col=BREAK20.CharPositionInLine;
                                                 exp.Row = BREAK20.Line;

                        }

                    }
                    break;
                case 6 :
                    // C:\\Users\\Danaice\\Desktop\\lastversion\\Dany_gramatica tiger ANTLR oficial\\tiger_grammar.g:245:13: NIL
                    {
                        NIL21=(IToken)Match(input,NIL,FOLLOW_NIL_in_expr1508); if (state.failed) return exp;
                        if ( (state.backtracking==0) )
                        {

                                                 exp =  new NilNode();
                                                 exp.Col=NIL21.CharPositionInLine;
                                                 exp.Row = NIL21.Line;

                        }

                    }
                    break;
                case 7 :
                    // C:\\Users\\Danaice\\Desktop\\lastversion\\Dany_gramatica tiger ANTLR oficial\\tiger_grammar.g:251:13: PAR_A exprseq PAR_C idp9= ptocor
                    {
                        PAR_A23=(IToken)Match(input,PAR_A,FOLLOW_PAR_A_in_expr1538); if (state.failed) return exp;
                        PushFollow(FOLLOW_exprseq_in_expr1540);
                        exprseq22 = exprseq();
                        state.followingStackPointer--;
                        if (state.failed) return exp;
                        Match(input,PAR_C,FOLLOW_PAR_C_in_expr1542); if (state.failed) return exp;
                        PushFollow(FOLLOW_ptocor_in_expr1546);
                        idp9 = ptocor();
                        state.followingStackPointer--;
                        if (state.failed) return exp;
                        if ( (state.backtracking==0) )
                        {

                                      			if(idp9.Count > 0)
                                                          {
                                                             exp =  new ListLValueNode(new ExprSeqNode(exprseq22),idp9);
                                                             exp.Col=PAR_A23.CharPositionInLine;
                                                             exp.Row = PAR_A23.Line;
                                                          }
                                                          else{
                                                             exp =  new ExprSeqNode(exprseq22);
                                                             exp.Col=PAR_A23.CharPositionInLine;
                                                             exp.Row = PAR_A23.Line;
                                                             }

                        }

                    }
                    break;
                case 8 :
                    // C:\\Users\\Danaice\\Desktop\\lastversion\\Dany_gramatica tiger ANTLR oficial\\tiger_grammar.g:265:13: IF idif= expr_or THEN idthen= expr_or ifthenelse
                    {
                        IF25=(IToken)Match(input,IF,FOLLOW_IF_in_expr1577); if (state.failed) return exp;
                        PushFollow(FOLLOW_expr_or_in_expr1581);
                        idif = expr_or();
                        state.followingStackPointer--;
                        if (state.failed) return exp;
                        Match(input,THEN,FOLLOW_THEN_in_expr1583); if (state.failed) return exp;
                        PushFollow(FOLLOW_expr_or_in_expr1587);
                        idthen = expr_or();
                        state.followingStackPointer--;
                        if (state.failed) return exp;
                        PushFollow(FOLLOW_ifthenelse_in_expr1589);
                        ifthenelse24 = ifthenelse();
                        state.followingStackPointer--;
                        if (state.failed) return exp;
                        if ( (state.backtracking==0) )
                        {

                                      		if(ifthenelse24!=null)
                                      		{
                                      			exp =  new IfThenElseNode(idif, idthen, ifthenelse24);
                                      		}
                                      		else{
                                      		        exp =  new IfThenNode(idif, idthen);
                                      		    }

                                      		exp.Col = IF25.CharPositionInLine;
                                      		exp.Row = IF25.Line;

                        }

                    }
                    break;
                case 9 :
                    // C:\\Users\\Danaice\\Desktop\\lastversion\\Dany_gramatica tiger ANTLR oficial\\tiger_grammar.g:278:13: WHILE idexp3= expr_or DO iddo= expr_or
                    {
                        WHILE26=(IToken)Match(input,WHILE,FOLLOW_WHILE_in_expr1627); if (state.failed) return exp;
                        PushFollow(FOLLOW_expr_or_in_expr1631);
                        idexp3 = expr_or();
                        state.followingStackPointer--;
                        if (state.failed) return exp;
                        Match(input,DO,FOLLOW_DO_in_expr1633); if (state.failed) return exp;
                        PushFollow(FOLLOW_expr_or_in_expr1637);
                        iddo = expr_or();
                        state.followingStackPointer--;
                        if (state.failed) return exp;
                        if ( (state.backtracking==0) )
                        {
                           exp =  new WhileNode(idexp3,iddo);
                                                                      exp.Col = WHILE26.CharPositionInLine;
                                      				    exp.Row = WHILE26.Line;

                        }

                    }
                    break;
                case 10 :
                    // C:\\Users\\Danaice\\Desktop\\lastversion\\Dany_gramatica tiger ANTLR oficial\\tiger_grammar.g:283:13: FOR id5= ID ASIG idasig= expr_or TO idto= expr_or DO iddo= expr_or
                    {
                        FOR27=(IToken)Match(input,FOR,FOLLOW_FOR_in_expr1665); if (state.failed) return exp;
                        id5=(IToken)Match(input,ID,FOLLOW_ID_in_expr1669); if (state.failed) return exp;
                        Match(input,ASIG,FOLLOW_ASIG_in_expr1671); if (state.failed) return exp;
                        PushFollow(FOLLOW_expr_or_in_expr1675);
                        idasig = expr_or();
                        state.followingStackPointer--;
                        if (state.failed) return exp;
                        Match(input,TO,FOLLOW_TO_in_expr1677); if (state.failed) return exp;
                        PushFollow(FOLLOW_expr_or_in_expr1681);
                        idto = expr_or();
                        state.followingStackPointer--;
                        if (state.failed) return exp;
                        Match(input,DO,FOLLOW_DO_in_expr1683); if (state.failed) return exp;
                        PushFollow(FOLLOW_expr_or_in_expr1687);
                        iddo = expr_or();
                        state.followingStackPointer--;
                        if (state.failed) return exp;
                        if ( (state.backtracking==0) )
                        {

                                                                      exp =  new ForNode(id5.Text,idasig,idto,iddo);
                                                                      exp.Col = FOR27.CharPositionInLine;
                                      				    exp.Row = FOR27.Line;

                        }

                    }
                    break;
                case 11 :
                    // C:\\Users\\Danaice\\Desktop\\lastversion\\Dany_gramatica tiger ANTLR oficial\\tiger_grammar.g:289:13: LET decllist IN exprseq END
                    {
                        LET30=(IToken)Match(input,LET,FOLLOW_LET_in_expr1716); if (state.failed) return exp;
                        PushFollow(FOLLOW_decllist_in_expr1718);
                        decllist28 = decllist();
                        state.followingStackPointer--;
                        if (state.failed) return exp;
                        Match(input,IN,FOLLOW_IN_in_expr1720); if (state.failed) return exp;
                        PushFollow(FOLLOW_exprseq_in_expr1722);
                        exprseq29 = exprseq();
                        state.followingStackPointer--;
                        if (state.failed) return exp;
                        Match(input,END,FOLLOW_END_in_expr1725); if (state.failed) return exp;
                        if ( (state.backtracking==0) )
                        {

                                                                     exp =  new LetNode(decllist28,exprseq29);
                                      				   exp.Col= LET30.CharPositionInLine;
                                      				   exp.Row = LET30.Line;

                        }

                    }
                    break;

            }
        }
        catch (RecognitionException re)
        {
            ReportError(re);
            Recover(input,re);
        }
        finally
        {
        }
        return exp;
    }
示例#41
0
 public static Node NewString(string s)
 {
     StringNode node = new StringNode(s);
     return node;
 }
示例#42
0
 public void OperateRoot()
 {
     var root = new StringNode("a");
     root.PrevsFromFirst().Should().HaveCount(0);
     root.NextsFromSelf().Should().HaveCount(0);
     root.PrevsFromFirstAndSelf().Should().Equal(Enumerable.Repeat(root, 1));
     root.NextsFromSelfAndSelf().Should().Equal(Enumerable.Repeat(root, 1));
     root.PrevsFromSelf().Should().HaveCount(0);
     root.NextsFromLast().Should().HaveCount(0);
     root.PrevsFromSelfAndSelf().Should().Equal(Enumerable.Repeat(root, 1));
     root.NextsFromLastAndSelf().Should().Equal(Enumerable.Repeat(root, 1));
 }
示例#43
0
 public StringNode(StringNode rhs)
     : base(rhs)
 {
     value = rhs.value;
 }
示例#44
0
 public void Replace()
 {
     var a = new StringNode("a");
     var b = new StringNode("b");
     var c = new StringNode("c");
     // a - b - c
     a.AddFirst(b);
     b.AddFirst(c);
     b.Replace(new StringNode("d"));
     string.Join("", a.DescendantsAndSelf().Select(n => n.Value)).Should().Be("ad");
 }
示例#45
0
        public void TraverseSingles()
        {
            var a = new StringNode("a");
            var b = new StringNode("b");
            var c = new StringNode("c");
            var d = new StringNode("d");
            var e = new StringNode("e");
            var f = new StringNode("f");
            var g = new StringNode("g");
            // a - b - c - d - e
            //   - g         - f
            a.AddFirst(b);
            a.AddLast(g);
            b.AddFirst(c);
            c.AddFirst(d);
            d.AddFirst(e);
            d.AddLast(f);

            string.Join("", b.DescendantsOfSingle().Select(n => n.Value)).Should()
                    .Be("cd");
            string.Join("", b.DescendantsOfSingleAndSelf().Select(n => n.Value)).Should()
                    .Be("bcd");
            string.Join("", c.DescendantsOfSingle().Select(n => n.Value)).Should()
                    .Be("d");
            string.Join("", c.DescendantsOfSingleAndSelf().Select(n => n.Value)).Should()
                    .Be("cd");

            string.Join("", b.AncestorsWithSingleChild().Select(n => n.Value)).Should()
                    .Be("");
            string.Join("", b.AncestorsWithSingleChildAndSelf().Select(n => n.Value)).Should()
                    .Be("b");
            string.Join("", c.AncestorsWithSingleChild().Select(n => n.Value)).Should()
                    .Be("b");
            string.Join("", c.AncestorsWithSingleChildAndSelf().Select(n => n.Value)).Should()
                    .Be("cb");
            string.Join("", d.AncestorsWithSingleChild().Select(n => n.Value)).Should()
                    .Be("cb");
            string.Join("", d.AncestorsWithSingleChildAndSelf().Select(n => n.Value)).Should()
                    .Be("dcb");
            string.Join("", e.AncestorsWithSingleChild().Select(n => n.Value)).Should()
                    .Be("");
            string.Join("", e.AncestorsWithSingleChildAndSelf().Select(n => n.Value)).Should()
                    .Be("e");
        }
示例#46
0
        private SwitchCase ProcessNode(DeserializerTypeContext ctx, StringNode node)
        {
            var bodyExpressions = new List<Expression>();

              var callExtractString = Expression.Call(null, _extractString, ctx.IteratorVar, ctx.StringParam);

              var accessMember = Expression.MakeMemberAccess(ctx.InstanceVar, node.Member);

              var assignMember = Expression.Assign(accessMember, callExtractString);

              //var assignToSubStr = Expression.Assign(ctx.SubStringVar, callExtractString);

              bodyExpressions.Add(assignMember);
              bodyExpressions.Add(Expression.Empty());

              var body = Expression.Block(bodyExpressions);

              var @case = Expression.SwitchCase(body, GetSwitchConstant(ctx, node));

              return @case;
        }
 private static void UpdateLogList(TreeNodeCollection nodes, string targetServer = null)
 {
     if (Logs == null)
     {
         Logs = new StringNode(null);
         // Add standard nodes
         StringNode std = new StringNode(EditorProperties.Resources.EventLogParentStandard);
         string[] stdLogs = new string[] { "Application", "Security", "Setup", "System", "ForwardedEvents" };
         foreach (string s in stdLogs)
             std.Nodes.Add(new StringNode(s, s));
         std.LastChild.Text = "Forwarded Events";
         Logs.Nodes.Add(std);
         // Get all event logs and remove standard ones
         var list = new List<string>(SystemEventEnumerator.GetEventLogs(targetServer));
         list.Sort();
         foreach (string s in stdLogs)
             list.Remove(s);
         // Add app nodes
         StringNode lastParent = null, curCompare = null, appNode = new StringNode(EditorProperties.Resources.EventLogParentApps);
         Logs.Nodes.Add(appNode);
         int max = 0;
         var partList = list.ConvertAll<string[]>(delegate(string s) { var a = s.Split('-', '/', '\\'); max = Math.Max(max, a.Length); return a; });
         for (int i = 0; i < partList.Count; i++)
         {
             lastParent = appNode;
             for (int j = 0; j < partList[i].Length; j++)
             {
                 if (curCompare != null && string.Compare(curCompare, partList[i][j], true) == 0)
                 {
                     lastParent = curCompare;
                     curCompare = curCompare.LastChild;
                 }
                 else
                 {
                     var sn = new StringNode(partList[i][j]);
                     if (j == partList[i].Length - 1)
                         sn.Path = list[i];
                     lastParent.Nodes.Add(sn);
                     lastParent = sn;
                 }
             }
             curCompare = appNode.LastChild;
         }
     }
     Logs.UpdateTreeView(nodes);
 }
示例#48
0
        public void CreateTreeAndTraverse()
        {
            var a = new StringNode("a"); // 1
            var b = a.AddFirst(new StringNode("b")); // 2
            var c = a.AddLast(new StringNode("c")); // 2
            var d = a.AddFirst(new StringNode("d")); // 2
            var e = a.AddFirst(new StringNode("e")); // 2
            var f = b.AddFirst(new StringNode("f")); // 3
            var g = b.AddFirst(new StringNode("g")); // 3
            var h = g.AddLast("h"); // 4
            var i = f.AddLast("i"); // 4
            var j = h.AddNext("j"); // 4
            var k = h.AddPrevious("k"); // 4
            var l = i.AddPrevious("l"); // 4
            var m = i.AddNext("m"); // 4
            a.ToString()
                    .Should()
                    .Be(
                            "a\n  e\n  d\n  b\n    g\n      k\n      h\n      j\n    f\n      l\n      i\n      m\n  c\n"
                                    .NormalizeNewLine());

            Assert.That(a.LengthFromDeepestChild, Is.EqualTo(3));
            Assert.That(b.LengthFromDeepestChild, Is.EqualTo(2));
            Assert.That(c.LengthFromDeepestChild, Is.EqualTo(0));
            Assert.That(d.LengthFromDeepestChild, Is.EqualTo(0));
            Assert.That(e.LengthFromDeepestChild, Is.EqualTo(0));
            Assert.That(f.LengthFromDeepestChild, Is.EqualTo(1));
            Assert.That(g.LengthFromDeepestChild, Is.EqualTo(1));
            Assert.That(h.LengthFromDeepestChild, Is.EqualTo(0));
            Assert.That(i.LengthFromDeepestChild, Is.EqualTo(0));
            Assert.That(j.LengthFromDeepestChild, Is.EqualTo(0));
            Assert.That(k.LengthFromDeepestChild, Is.EqualTo(0));
            Assert.That(l.LengthFromDeepestChild, Is.EqualTo(0));
            Assert.That(m.LengthFromDeepestChild, Is.EqualTo(0));

            string.Join("", a.Descendants().Select(n => n.Value)).Should().Be("edbgkhjflimc");
            string.Join("", e.Descendants().Select(n => n.Value)).Should().Be("");
            string.Join("", d.Descendants().Select(n => n.Value)).Should().Be("");
            string.Join("", b.Descendants().Select(n => n.Value)).Should().Be("gkhjflim");
            string.Join("", c.Descendants().Select(n => n.Value)).Should().Be("");

            string.Join("", a.DescendantsAndSelf().Select(n => n.Value)).Should()
                    .Be("aedbgkhjflimc");
            string.Join("", e.DescendantsAndSelf().Select(n => n.Value)).Should().Be("e");
            string.Join("", d.DescendantsAndSelf().Select(n => n.Value)).Should().Be("d");
            string.Join("", b.DescendantsAndSelf().Select(n => n.Value)).Should().Be("bgkhjflim");
            string.Join("", c.DescendantsAndSelf().Select(n => n.Value)).Should().Be("c");

            string.Join("", a.Descendants(2).Select(n => n.Value)).Should().Be("edbgfc");
            string.Join("", e.Descendants(2).Select(n => n.Value)).Should().Be("");
            string.Join("", d.Descendants(2).Select(n => n.Value)).Should().Be("");
            string.Join("", b.Descendants(2).Select(n => n.Value)).Should().Be("gkhjflim");
            string.Join("", c.Descendants(2).Select(n => n.Value)).Should().Be("");
            string.Join("", b.Descendants(0).Select(n => n.Value)).Should().Be("");

            string.Join("", a.DescendantsAndSelf(2).Select(n => n.Value)).Should()
                    .Be("aedbgfc");
            string.Join("", e.DescendantsAndSelf(2).Select(n => n.Value)).Should().Be("e");
            string.Join("", d.DescendantsAndSelf(2).Select(n => n.Value)).Should().Be("d");
            string.Join("", b.DescendantsAndSelf(2).Select(n => n.Value)).Should().Be("bgkhjflim");
            string.Join("", c.DescendantsAndSelf(2).Select(n => n.Value)).Should().Be("c");
            string.Join("", b.DescendantsAndSelf(0).Select(n => n.Value)).Should().Be("b");

            string.Join("", a.Siblings().Select(n => n.Value)).Should().Be("");
            string.Join("", k.Siblings().Select(n => n.Value)).Should().Be("hj");
            string.Join("", h.Siblings().Select(n => n.Value)).Should().Be("kj");
            string.Join("", j.Siblings().Select(n => n.Value)).Should().Be("kh");
            string.Join("", i.Siblings().Select(n => n.Value)).Should().Be("lm");

            string.Join("", a.SiblingsAndSelf().Select(n => n.Value)).Should().Be("a");
            string.Join("", k.SiblingsAndSelf().Select(n => n.Value)).Should().Be("khj");
            string.Join("", h.SiblingsAndSelf().Select(n => n.Value)).Should().Be("khj");
            string.Join("", j.SiblingsAndSelf().Select(n => n.Value)).Should().Be("khj");
            string.Join("", i.SiblingsAndSelf().Select(n => n.Value)).Should().Be("lim");

            string.Join("", a.Siblings(1).Select(n => n.Value)).Should().Be("");
            string.Join("", k.Siblings(1).Select(n => n.Value)).Should().Be("h");
            string.Join("", h.Siblings(1).Select(n => n.Value)).Should().Be("kj");
            string.Join("", j.Siblings(1).Select(n => n.Value)).Should().Be("h");
            string.Join("", i.Siblings(1).Select(n => n.Value)).Should().Be("lm");
            string.Join("", i.Siblings(0).Select(n => n.Value)).Should().Be("");

            string.Join("", a.SiblingsAndSelf(1).Select(n => n.Value)).Should().Be("a");
            string.Join("", k.SiblingsAndSelf(1).Select(n => n.Value)).Should().Be("kh");
            string.Join("", h.SiblingsAndSelf(1).Select(n => n.Value)).Should().Be("khj");
            string.Join("", j.SiblingsAndSelf(1).Select(n => n.Value)).Should().Be("hj");
            string.Join("", i.SiblingsAndSelf(1).Select(n => n.Value)).Should().Be("lim");
            string.Join("", i.SiblingsAndSelf(0).Select(n => n.Value)).Should().Be("i");

            string.Join("", i.Ancestors().Select(n => n.Value)).Should().Be("fba");
            string.Join("", i.Ancestors(3).Select(n => n.Value)).Should().Be("fba");
            string.Join("", i.Ancestors(2).Select(n => n.Value)).Should().Be("fb");
            string.Join("", i.Ancestors(1).Select(n => n.Value)).Should().Be("f");
            string.Join("", i.Ancestors(0).Select(n => n.Value)).Should().Be("");

            string.Join("", i.AncestorsAndSelf().Select(n => n.Value)).Should().Be("ifba");
            string.Join("", i.AncestorsAndSelf(3).Select(n => n.Value)).Should().Be("ifba");
            string.Join("", i.AncestorsAndSelf(2).Select(n => n.Value)).Should().Be("ifb");
            string.Join("", i.AncestorsAndSelf(1).Select(n => n.Value)).Should().Be("if");
            string.Join("", i.AncestorsAndSelf(0).Select(n => n.Value)).Should().Be("i");

            string.Join("", f.AncestorsAndSiblingsAfterSelf().Select(n => n.Value)).Should().Be("c");
            string.Join("", f.AncestorsAndSiblingsAfterSelfAndSelf().Select(n => n.Value))
                    .Should()
                    .Be("fc");
            string.Join("", f.AncestorsAndSiblingsBeforeSelf().Select(n => n.Value))
                    .Should()
                    .Be("gbdea");
            string.Join("", f.AncestorsAndSiblingsBeforeSelfAndSelf().Select(n => n.Value))
                    .Should()
                    .Be("fgbdea");

            string.Join("", h.AncestorsAndSiblingsAfterSelf().Select(n => n.Value))
                    .Should()
                    .Be("jfc");
            string.Join("", h.AncestorsAndSiblingsAfterSelfAndSelf().Select(n => n.Value))
                    .Should()
                    .Be("hjfc");
            string.Join("", h.AncestorsAndSiblingsBeforeSelf().Select(n => n.Value))
                    .Should()
                    .Be("kgbdea");
            string.Join("", h.AncestorsAndSiblingsBeforeSelfAndSelf().Select(n => n.Value))
                    .Should()
                    .Be("hkgbdea");

            Assert.That(b.Ancestors(), Is.EqualTo(new[] { a }));
            Assert.That(b.AncestorsAndSelf(), Is.EqualTo(new[] { b, a }));
            Assert.That(b.Children(), Is.EqualTo(new[] { g, f }));
            Assert.That(b.ReverseChildren(), Is.EqualTo(b.Children().Reverse()));
            Assert.That(b.ChildrenCount, Is.EqualTo(2));
            Assert.That(b.NextsFromSelf(), Is.EqualTo(new[] { c }));
            Assert.That(b.NextsFromSelfAndSelf(), Is.EqualTo(new[] { b, c }));
            Assert.That(b.NextsFromLast(), Is.EqualTo(new[] { c }));
            Assert.That(b.NextsFromLastAndSelf(), Is.EqualTo(new[] { c, b }));
            Assert.That(b.PrevsFromFirst(), Is.EqualTo(new[] { e, d }));
            Assert.That(b.PrevsFromFirstAndSelf(), Is.EqualTo(new[] { e, d, b }));
            Assert.That(b.PrevsFromSelf(), Is.EqualTo(new[] { d, e }));
            Assert.That(b.PrevsFromSelfAndSelf(), Is.EqualTo(new[] { b, d, e }));
            Assert.That(b.DescendantsOfFirstChild(), Is.EqualTo(new[] { g, k }));
            Assert.That(b.DescendantsOfFirstChildAndSelf(), Is.EqualTo(new[] { b, g, k }));

            Assert.That(e.Ancestors(), Is.EqualTo(new[] { a }));
            Assert.That(e.AncestorsAndSelf(), Is.EqualTo(new[] { e, a }));
            Assert.That(e.Children(), Is.EqualTo(new StringNode[0]));
            Assert.That(e.ReverseChildren(), Is.EqualTo(e.Children().Reverse()));
            Assert.That(e.ChildrenCount, Is.EqualTo(0));
            Assert.That(e.NextsFromSelf(), Is.EqualTo(new[] { d, b, c }));
            Assert.That(e.NextsFromSelfAndSelf(), Is.EqualTo(new[] { e, d, b, c }));
            Assert.That(e.NextsFromLast(), Is.EqualTo(new[] { c, b, d }));
            Assert.That(e.NextsFromLastAndSelf(), Is.EqualTo(new[] { c, b, d, e }));
            Assert.That(e.PrevsFromFirst(), Is.EqualTo(new StringNode[0]));
            Assert.That(e.PrevsFromFirstAndSelf(), Is.EqualTo(new[] { e }));
            Assert.That(e.PrevsFromSelf(), Is.EqualTo(new StringNode[0]));
            Assert.That(e.PrevsFromSelfAndSelf(), Is.EqualTo(new[] { e }));
            Assert.That(e.DescendantsOfFirstChild(), Is.EqualTo(new StringNode[0]));
            Assert.That(e.DescendantsOfFirstChildAndSelf(), Is.EqualTo(new[] { e }));

            var restoreG = g.RemoveRecoverably();
            Assert.That(restoreG, Is.Not.Null);
            Assert.That(string.Join("", a.Descendants().Select(n => n.Value)),
                    Is.EqualTo("edbflimc"));

            var restoreF = f.RemoveRecoverably();
            Assert.That(restoreF, Is.Not.Null);
            Assert.That(string.Join("", a.Descendants().Select(n => n.Value)), Is.EqualTo("edbc"));

            var anotherRestoreF = f.RemoveRecoverably();
            restoreF();
            anotherRestoreF();
            restoreF();
            Assert.That(string.Join("", a.Descendants().Select(n => n.Value)),
                    Is.EqualTo("edbflimc"));
            var anotherRestoreG = g.RemoveRecoverably();
            restoreG();
            anotherRestoreG();
            restoreG();
            Assert.That(string.Join("", a.Descendants().Select(n => n.Value)),
                    Is.EqualTo("edbgkhjflimc"));

            foreach (var node in a.Descendants()) {
                var restore = node.RemoveRecoverably();
                Assert.That(restore, Is.Not.Null);
                Assert.That(string.Join("", a.Descendants().Select(n => n.Value)),
                        Is.Not.StringContaining(node.Value));
                restore();
                Assert.That(string.Join("", a.Descendants().Select(n => n.Value)),
                        Is.EqualTo("edbgkhjflimc"));
            }

            h.Replace(new StringNode("1"));
                Assert.That(string.Join("", a.Descendants().Select(n => n.Value)),
                        Is.EqualTo("edbgk1jflimc"));
            i.Replace(new StringNode("2"));
                Assert.That(string.Join("", a.Descendants().Select(n => n.Value)),
                        Is.EqualTo("edbgk1jfl2mc"));
            j.Replace(new StringNode("3"));
                Assert.That(string.Join("", a.Descendants().Select(n => n.Value)),
                        Is.EqualTo("edbgk13fl2mc"));
            k.Replace(new StringNode("4"));
                Assert.That(string.Join("", a.Descendants().Select(n => n.Value)),
                        Is.EqualTo("edbg413fl2mc"));
            l.Replace(new StringNode("5"));
                Assert.That(string.Join("", a.Descendants().Select(n => n.Value)),
                        Is.EqualTo("edbg413f52mc"));
            m.Replace(new StringNode("6"));
                Assert.That(string.Join("", a.Descendants().Select(n => n.Value)),
                        Is.EqualTo("edbg413f526c"));

            f.Replace(new StringNode("7"));
                Assert.That(string.Join("", a.Descendants().Select(n => n.Value)),
                        Is.EqualTo("edbg4137c"));
            g.Replace(new StringNode("8"));
                Assert.That(string.Join("", a.Descendants().Select(n => n.Value)),
                        Is.EqualTo("edb87c"));

            b.Replace(new StringNode("9"));
                Assert.That(string.Join("", a.Descendants().Select(n => n.Value)),
                        Is.EqualTo("ed9c"));
            c.Replace(new StringNode("0"));
                Assert.That(string.Join("", a.Descendants().Select(n => n.Value)),
                        Is.EqualTo("ed90"));
            d.Replace(new StringNode("1"));
                Assert.That(string.Join("", a.Descendants().Select(n => n.Value)),
                        Is.EqualTo("e190"));
            e.Replace(new StringNode("2"));
                Assert.That(string.Join("", a.Descendants().Select(n => n.Value)),
                        Is.EqualTo("2190"));
        }
示例#49
0
        public void StringNodeTest()
        {
            StreamLocation expectedLocation = new StreamLocation(3, 2, 1);
            string testString = "hello world";

            ValueNode sut = new StringNode(testString, expectedLocation);

            Assert.AreEqual(TNode.STRING, sut.NodeType);
            Assert.AreEqual(expectedLocation, sut.Location);
            Assert.IsTrue(sut.Description.Contains("STRING"));
            Assert.AreEqual(FieldValueType.TEXT, sut.ValueType);
            Assert.IsInstanceOfType(sut.SubExpression, typeof(ConstantExpression));
            Assert.AreEqual(ExpressionType.Constant, sut.SubExpression.NodeType);
            Assert.AreEqual(typeof(string), sut.SubExpression.Type);
            Assert.AreEqual(testString, ((ConstantExpression)sut.SubExpression).Value);
        }