static void DeclareVariable(ParseNode functionBody, ParseNode typeNameNode, ParseNode variableNameNode)
        {
            var nodesToAdd = new List<ParseNode>
                {
                    typeNameNode.Clone(),
                    TokenKind.Space.BuildTokenFromId(" "),
                    variableNameNode.Clone(),
                    TokenKind.SemiColon.BuildTokenFromId()
                };

            var declarationNode = new ParseNode(RuleKind.DeclareVariable);
            declarationNode.AddRange(nodesToAdd);
            functionBody.Insert(1, declarationNode);
            if (typeNameNode.Parent.Rule == RuleKind.DeclareVariable)
            {
                typeNameNode.Parent.Rule = RuleKind.InstructionCode;
            }
            typeNameNode.RemoveFromParent();
        }
Ejemplo n.º 2
0
        void ExtractArrayParameter(ParseNode typeNode, CleanupAstNodeStates states, int startPos,
                                           int lastPosition, ParseNode functionBlockNode)
        {
            var declarationNode = RuleKind.DeclareVariable.NewNodeOfRule();
            declarationNode.AddRange(new[]
                {
                    typeNode.Clone(),
                    TokenKind.Space.BuildTokenFromId(" "),
                });
            Enumerable.Range(startPos, lastPosition - startPos + 1).Each(
                i => declarationNode.Add(states[i].Clone()));

            for (var i = startPos; i < lastPosition; i++)
            {
                var mappedNode = states[i];
                if (mappedNode.Token == TokenKind.Identifier)
                    break;
                TypeData.ValidateToken(mappedNode);
            }

            declarationNode.Add(TokenKind.SemiColon.BuildTokenFromId());
            functionBlockNode.Insert(1, declarationNode);
            FixRuleProblem(declarationNode);
        }