예제 #1
0
        void parseTemplateArgument()
        {
            currentTokenKind = TokenKind.VALUE;

            Token name = tokens[cursor += 1];

            if (name.type != TT.IDENTIFIER)
            {
                Jolly.unexpected(name);
            }
            AST_Template node     = new AST_Template(name.location);
            AST_Node     typeFrom = null;

            if (prevTokenKind == TokenKind.VALUE)
            {
                if (defineMode != DefineMode.TEMPLATE)
                {
                    throw Jolly.unexpected(token);
                }
                typeFrom = values.Pop();
                Debug.Assert(typeFrom != null);
            }

            DefineMode inferrableDefineMode = (DefineMode.TEMPLATE | DefineMode.ARGUMENT) & defineMode;

            if (canDefine && inferrableDefineMode != 0)
            {
                if (scope.template.TryGetValue(name.text, out node.item))
                {
                    if ((node.item.canBeInferredBy & defineMode) == DefineMode.TEMPLATE)
                    {
                        throw Jolly.addError(name.location, "Trying to redefine template argument ${0}".fill(name.text));
                    }
                    node.item.canBeInferredBy |= inferrableDefineMode;
                }
                else
                {
                    scope.template.Add(name.text, node.item = new TemplateItem {
                        canBeInferredBy = inferrableDefineMode,
                        constantValue   = typeFrom,
                        location        = node.location,
                        defineIndex     = defineIndex++,
                    });
                }
            }
            else
            {
                node.name = name.text;
            }

            values.Push(node);
            ast.Add(node);
        }
예제 #2
0
 public ExpressionParser(SharedParseData parseData, Token.Type terminator, SymbolTable scope, DefineMode defineMode, int end)
 {
     contextStack.Push(new Context(parseData.ast.Count, Context.Kind.STATEMENT));
     this.terminator = terminator;
     this.parseData  = parseData;
     this.defineMode = defineMode;
     this.canDefine  = true;
     this.scope      = scope;
     this.end        = end;
 }