Пример #1
0
        public static InterfaceEntryNode Parse(Lexer lex)
        {
            InterfaceEntryNode n = new InterfaceEntryNode();

            Token tkn;

            n.IsVirtual = lex.DequeueIf("virtual", out tkn);
            n.IsUnsafe  = lex.DequeueIf("unsafe", out tkn);

            n.TypeName = TypeNode.Parse(lex);

            if (GenericParamNode.IsPresent(lex))
            {
                n.GenericParams = GenericParamNode.Parse(lex);
            }

            tkn          = lex.Dequeue(TokenType.Identifier);
            n.Identifier = tkn.Value;

            if (InterfaceFunctionNode.IsPresent(lex))
            {
                n.Entry = InterfaceFunctionNode.Parse(lex);
            }
            else if (InterfacePropertyNode.IsPresent(lex))
            {
                n.Entry = InterfacePropertyNode.Parse(lex);
            }
            else
            {
                throw ExceptionProvider.Syntax(lex.Peek().Cursor, "Unrecognized definition");
            }
            return(n);
        }
        public static InterfacePropertyNode Parse(Lexer lex)
        {
            InterfacePropertyNode n = new InterfacePropertyNode();

            lex.Dequeue(TokenType.LBrace);

            Token tkn;

            for (int i = 0; i < 2; i++)
            {
                string vis = "public";
                if (VisibilitySet.Match(lex))
                {
                    tkn = lex.Dequeue();
                    vis = tkn.Value;
                }

                if (lex.DequeueIf("get", out tkn))
                {
                    n.Getter           = true;
                    n.GetterVisibility = vis;
                    lex.Dequeue(TokenType.Semi);

                    if (lex.DequeueIf(TokenType.RBrace, out tkn))
                    {
                        break;
                    }
                }
                else if (lex.DequeueIf("set", out tkn))
                {
                    n.Setter           = true;
                    n.SetterVisibility = vis;
                    lex.Dequeue(TokenType.Semi);

                    if (lex.DequeueIf(TokenType.RBrace, out tkn))
                    {
                        break;
                    }
                }
                else
                {
                    throw ExceptionProvider.Syntax(tkn.Cursor, "Expected getter/setter declaration");
                }
            }

            return(n);
        }