コード例 #1
0
    EnumAst Enum(string[] metadata, Visibility visibility)
    {
        Match(TokenKind.EnumKeyword);
        Token name = Match(TokenKind.Identifier);

        TypeAst type = new BaseTypeAst(new Token(TokenKind.Identifier, "int", 0, 0));

        if (current.kind is TokenKind.Colon)
        {
            Next();
            type = Type();
        }

        Match(TokenKind.LeftBrace);

        List <EnumValueAst> values = new List <EnumValueAst>();

        while (current.kind is not TokenKind.Eof and not TokenKind.RightBrace)
        {
            values.Add(EnumValue(name.text));

            if (current.kind is not TokenKind.RightBrace)
            {
                Match(TokenKind.Comma);
            }
        }

        Match(TokenKind.RightBrace);

        return(new EnumAst(metadata, visibility, name, type, values.ToArray()));
    }
コード例 #2
0
    TypeAst Type()
    {
        Token   typeBase = Match(TokenKind.Identifier);
        TypeAst baseType = new BaseTypeAst(typeBase);

        return(TypeExt(baseType));
    }