Esempio n. 1
0
        /// <summary>
        /// Visits an event or machine declaration.
        /// </summary>
        /// <param name="parentNode">Node</param>
        /// <param name="tokenRange">The range of accumulated tokens</param>
        private void VisitEventOrMachineDeclaration(NamespaceDeclaration parentNode, TokenRange tokenRange)
        {
            ModifierSet modSet = ModifierSet.CreateDefault();

            while (!this.TokenStream.Done &&
                   this.TokenStream.Peek().Type != TokenType.EventDecl &&
                   this.TokenStream.Peek().Type != TokenType.MachineDecl &&
                   this.TokenStream.Peek().Type != TokenType.MonitorDecl)
            {
                new ModifierVisitor(this.TokenStream).Visit(modSet);

                this.TokenStream.Index++;
                this.TokenStream.SkipWhiteSpaceAndCommentTokens();
            }

            if (this.TokenStream.Done ||
                (this.TokenStream.Peek().Type != TokenType.EventDecl &&
                 this.TokenStream.Peek().Type != TokenType.MachineDecl &&
                 this.TokenStream.Peek().Type != TokenType.MonitorDecl))
            {
                throw new ParsingException("Expected event, machine or monitor declaration.", this.TokenStream.Peek(),
                                           TokenType.EventDecl,
                                           TokenType.MachineDecl,
                                           TokenType.MonitorDecl);
            }

            if (this.TokenStream.Peek().Type == TokenType.EventDecl)
            {
                new EventDeclarationVisitor(this.TokenStream).Visit(parentNode, null, modSet);
            }
            else if (this.TokenStream.Peek().Type == TokenType.MachineDecl)
            {
                new MachineDeclarationVisitor(this.TokenStream).Visit(parentNode, false, modSet, tokenRange.Start());
            }
            else if (this.TokenStream.Peek().Type == TokenType.MonitorDecl)
            {
                new MachineDeclarationVisitor(this.TokenStream).Visit(parentNode, true, modSet, tokenRange.Start());
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Visits the next intra-namespace declration.
        /// </summary>
        /// <param name="node">Node</param>
        private void VisitNextIntraNamespaceDeclaration(NamespaceDeclaration node)
        {
            var tokenRange = new TokenRange(this.TokenStream);

            if (this.TokenStream.Done)
            {
                throw new ParsingException("Expected \"}\".", this.TokenStream.Last(),
                                           TokenType.Internal,
                                           TokenType.Public,
                                           TokenType.Partial,
                                           TokenType.Abstract,
                                           TokenType.Virtual,
                                           TokenType.ExternDecl,
                                           TokenType.EventDecl,
                                           TokenType.MachineDecl,
                                           TokenType.MonitorDecl,
                                           TokenType.LeftSquareBracket,
                                           TokenType.RightCurlyBracket);
            }

            bool fixpoint = false;
            var  token    = this.TokenStream.Peek();

            switch (token.Type)
            {
            case TokenType.WhiteSpace:
            case TokenType.Comment:
            case TokenType.NewLine:
                this.TokenStream.Index++;
                break;

            case TokenType.CommentLine:
            case TokenType.Region:
                this.TokenStream.SkipWhiteSpaceAndCommentTokens();
                break;

            case TokenType.CommentStart:
                this.TokenStream.SkipWhiteSpaceAndCommentTokens();
                break;

            case TokenType.ExternDecl:
                new EventDeclarationVisitor(this.TokenStream).VisitExternDeclaration(node, null);
                this.TokenStream.Index++;
                break;

            case TokenType.EventDecl:
            case TokenType.MachineDecl:
            case TokenType.MonitorDecl:
            case TokenType.Internal:
            case TokenType.Public:
            case TokenType.Private:
            case TokenType.Protected:
            case TokenType.Partial:
            case TokenType.Abstract:
            case TokenType.Virtual:
                this.VisitEventOrMachineDeclaration(node, tokenRange.Start());
                this.TokenStream.Index++;
                break;

            case TokenType.LeftSquareBracket:
                this.TokenStream.Index++;
                this.TokenStream.SkipWhiteSpaceAndCommentTokens();
                new AttributeListVisitor(this.TokenStream).Visit();
                this.TokenStream.Index++;
                break;

            case TokenType.RightCurlyBracket:
                node.RightCurlyBracketToken = this.TokenStream.Peek();
                fixpoint = true;
                this.TokenStream.Index++;
                break;

            default:
                throw new ParsingException("Unexpected token.", token,
                                           TokenType.EventDecl,
                                           TokenType.MachineDecl,
                                           TokenType.MonitorDecl,
                                           TokenType.Internal,
                                           TokenType.Public,
                                           TokenType.Private,
                                           TokenType.Protected,
                                           TokenType.Partial,
                                           TokenType.Abstract,
                                           TokenType.Virtual);
            }

            if (!fixpoint)
            {
                this.VisitNextIntraNamespaceDeclaration(node);
            }
        }