Exemplo n.º 1
0
        public IEnumerable <IASTNode> Parse()
        {
            List <ASTAnnotation> annotations = new List <ASTAnnotation>();
            List <ASTDirective>  directives  = new List <ASTDirective>();

            while (HasNext())
            {
                if (Current.TokenType == TokenType.KW_Type)
                {
                    var(errors, t) = ASTType.Parse(this, annotations, directives);
                    this.Errors.AddRange(errors);
                    yield return(t);
                }
                else if (Current.TokenType == TokenType.KW_Alias)
                {
                    yield return(new ASTAlias(this));
                }
                else if (Current.TokenType == TokenType.KW_Choice)
                {
                    yield return(new ASTChoice(this));
                }
                else if (Current.TokenType == TokenType.Annotation)
                {
                    annotations = ASTAnnotation.Parse(this).ToList();
                }
                else if (Current.TokenType == TokenType.Directive)
                {
                    directives = ASTDirective.Parse(this).ToList();
                }
                else
                {
                    Next();
                }
            }
            yield break;
        }
Exemplo n.º 2
0
        public IEnumerable <IASTNode> Parse()
        {
            var annotations = new List <ASTAnnotation>();
            var directives  = new List <ASTDirective>();

            while (HasNext() && Current.TokenType != TokenType.EndOfFile)
            {
                if (Current.TokenType == TokenType.KW_Type)
                {
                    var(errors, t) = ASTType.Parse(this, annotations, directives);
                    Errors.AddRange(errors);
                    annotations = new List <ASTAnnotation>();
                    directives  = new List <ASTDirective>();
                    yield return(t);
                }
                else if (Current.TokenType == TokenType.KW_Alias)
                {
                    var(errors, alias) = ASTAlias.Parse(this, annotations, directives);
                    Errors.AddRange(errors);
                    annotations = new List <ASTAnnotation>();
                    directives  = new List <ASTDirective>();
                    yield return(alias);
                }
                else if (Current.TokenType == TokenType.KW_Choice)
                {
                    var(errors, result) = ASTChoice.Parse(this);
                    Errors.AddRange(errors);
                    yield return(result);

                    annotations = new List <ASTAnnotation>();
                    directives  = new List <ASTDirective>();
                }
                else if (Current.TokenType == TokenType.KW_Data)
                {
                    var(errors, data) = ASTData.Parse(this, annotations, directives);
                    Errors.AddRange(errors);
                    yield return(data);

                    annotations = new List <ASTAnnotation>();
                    directives  = new List <ASTDirective>();
                }
                else if (Current.TokenType == TokenType.KW_View)
                {
                    var(errors, data) = ASTView.Parse(this, annotations, directives);
                    Errors.AddRange(errors);
                    yield return(data);

                    annotations = new List <ASTAnnotation>();
                    directives  = new List <ASTDirective>();
                }
                else if (Current.TokenType == TokenType.KW_Open)
                {
                    var(errors, data) = ASTImport.Parse(this);
                    Errors.AddRange(errors);
                    yield return(data);

                    annotations = new List <ASTAnnotation>();
                    directives  = new List <ASTDirective>();
                }
                else if (Current.TokenType == TokenType.KW_Flow)
                {
                    var(errors, data) = ASTFlow.Parse(this);
                    Errors.AddRange(errors);
                    yield return(data);

                    annotations = new List <ASTAnnotation>();
                    directives  = new List <ASTDirective>();
                }
                else if (Current.TokenType == TokenType.Annotation)
                {
                    annotations = ASTAnnotation.Parse(this).ToList();
                }
                else if (Current.TokenType == TokenType.Directive)
                {
                    var(errors, dirs) = ASTDirective.Parse(this);
                    Errors.AddRange(errors.ToList());
                    directives = dirs.ToList();
                }
                else if (Current.TokenType == TokenType.Chapter)
                {
                    yield return(new ASTChapter(Current.Value));

                    Next();
                }
                else if (Current.TokenType == TokenType.Paragraph)
                {
                    yield return(new ASTParagraph(Current.Value));

                    Next();
                }
                else
                {
                    Next();
                }
            }
            yield break;
        }