Beispiel #1
0
        public LetNode(ITokenReader tokenReader, INodeReader nodeReader, string directiveName = null, Location location = null)
            : base(directiveName, location)
        {
            var startLocation = tokenReader.CurrentLocation;

            Token token = tokenReader.ReadToken();

            if(token == null) {
                throw new MissingDataException("Variable name", startLocation);
            }

            if(token.TokenType != TokenType.Identifier) {
                throw new MissingDataException("Variable name", token.Location);
            }

            Variable = token.Value.ToString();

            var shorthand = ReadShorthandNode(tokenReader);

            if(shorthand != null) {
                ChildrenNodes = new List<NodeBase> { shorthand };
            } else {
                ChildrenNodes = new List<NodeBase>(nodeReader.TakeWhile((node) => !IsEndDirective(node, DirectiveName)));
            }
        }
Beispiel #2
0
        // TODO Clean up.
        public IfNode(ITokenReader tokenReader, INodeReader nodeReader, string directiveName = null, Location location = null)
            : base(directiveName, location)
        {
            Conditions = new List<ConditionSet>();

            var condition = ExpressionRewriter.Rewrite(tokenReader);
            var curConditionSet = new ConditionSet(condition);

            Conditions.Add(curConditionSet);

            var childrenNodes = nodeReader.TakeWhile((node) => !IsEndDirective(node, DirectiveName));

            foreach(var node in childrenNodes) {
                bool isConditional;
                var newCondition = GetConditionFromNode(node, out isConditional);

                if(isConditional) {
                    if(newCondition != null && curConditionSet.Condition == null) {
                        throw new BadDataException("Can't have an elseif node after an else node", node.Location);
                    }

                    curConditionSet = new ConditionSet(newCondition);

                    Conditions.Add(curConditionSet);

                    continue;
                }

                curConditionSet.ChildrenNodes.Add(node);
            }
        }
Beispiel #3
0
        public EachNode(ITokenReader tokenReader, INodeReader nodeReader, string directiveName = null, Location location = null)
            : base(directiveName, location)
        {
            var startLocation = tokenReader.CurrentLocation;

            Token token = tokenReader.ReadToken();

            if(token == null) {
                throw new MissingDataException("Variable name", startLocation);
            }

            if(token.TokenType != TokenType.Identifier) {
                throw new MissingDataException("Variable name", token.Location);
            }

            Variable = token.Value.ToString();

            Values = ExpressionRewriter.Rewrite(tokenReader);

            ChildrenNodes = new List<NodeBase>(nodeReader.TakeWhile((node) => {
                var endDirective = node as EndDirectiveNode;

                if(endDirective != null && endDirective.TargetDirectiveName == DirectiveName) {
                    return false;
                }

                return true;
            }));
        }
Beispiel #4
0
        public ForNode(ITokenReader tokenReader, INodeReader nodeReader, string directiveName = null, Location location = null)
            : this(directiveName, location)
        {
            var parameters = ExpressionRewriter.Rewrite(tokenReader);

            if(!parameters.Token.IsSymbol(",")) {
                throw new DataTypeException("Expected comma-separated list", this);
            }

            var children = parameters.ChildrenTokenNodes;

            if(children.Count < 3 || children.Count > 4) {
                throw new MissingDataException("#for directive requires 3 to 4 parameters", location);
            }

            if(children[0].Token.TokenType != TokenType.Identifier) {
                throw new MissingDataException("Identifier", children[0].Location);
            }

            Variable = children[0].Token.ToString();
            Start = children[1];
            End = children[2];
            Step = children.Count > 3 ? children[3] : null;

            ChildrenNodes = new List<NodeBase>(nodeReader.TakeWhile((node) => !IsEndDirective(node, DirectiveName)));
        }
Beispiel #5
0
        public RepNode(ITokenReader tokenReader, INodeReader nodeReader, string directiveName = null, Location location = null)
            : base(directiveName, location)
        {
            Value = ExpressionRewriter.Rewrite(tokenReader);

            ChildrenNodes = new List<NodeBase>(nodeReader.TakeWhile((node) => !IsEndDirective(node, DirectiveName)));
        }
Beispiel #6
0
        public DefineNode(ITokenReader tokenReader, INodeReader nodeReader, string directiveName = null, Location location = null)
            : this(directiveName, location)
        {
            var startLocation = tokenReader.CurrentLocation;

            Token variable = tokenReader.ReadToken();

            if(variable == null) {
                throw new MissingDataException("Variable name", startLocation);
            }

            if(variable.TokenType != TokenType.Identifier) {
                throw new MissingDataException("Variable name", variable.Location);
            }

            Variable = variable.ToString();

            // TODO Extract method.
            var functionParameters = new List<string>();
            FunctionParameters = functionParameters;

            Token token = tokenReader.ReadToken();

            if(token != null && token.IsSymbol("(")) {
                while(token != null && !token.IsSymbol(")")) {
                    token = tokenReader.ReadToken();

                    if(token.TokenType == TokenType.Identifier) {
                        functionParameters.Add(token.Value.ToString());
                    }
                }

                if(token == null) {
                    throw new MissingDataException("Closing parentheses");
                }

                token = null;
            }

            var shorthand = ReadShorthandNode(tokenReader, token);

            if(shorthand != null) {
                ChildrenNodes = new List<NodeBase> { shorthand };
            } else {
                ChildrenNodes = new List<NodeBase>(nodeReader.TakeWhile((node) => !IsEndDirective(node, DirectiveName)));
            }
        }