예제 #1
0
        public static EnumDefNode Parse(Lexer lex)
        {
            EnumDefNode n = new EnumDefNode();

            lex.Dequeue("enum");
            var tkn = lex.Dequeue(TokenType.Identifier);

            n.Identifier = tkn.Value;

            lex.Dequeue(TokenType.LBrace);
            bool isLast = false;

            while (EnumEntryNode.IsPresent(lex))
            {
                if (isLast)
                {
                    throw ExceptionProvider.Syntax(tkn.Cursor, "Expected ',' or end of enum");
                }

                n.Entries.Add(EnumEntryNode.Parse(lex));

                if (!lex.DequeueIf(TokenType.Comma, out tkn))
                {
                    isLast = true;
                }
            }
            lex.Dequeue(TokenType.RBrace);

            return(n);
        }
예제 #2
0
        public static EnumEntryNode Parse(Lexer lex)
        {
            EnumEntryNode n = new EnumEntryNode();

            var tkn = lex.Dequeue(TokenType.Identifier);

            n.Identifier = tkn.Value;

            if (lex.DequeueIf(TokenType.Assign, out tkn))
            {
                n.Value = ConstExprNode.Parse(lex);
            }

            return(n);
        }