Ejemplo n.º 1
0
		public IListSource<LNode> Parse(IListSource<Token> input, ISourceFile file, IMessageSink msgs, Symbol inputType = null)
		{
			// For efficiency we'd prefer to re-use our _parser object, but
			// when parsing lazily, we can't re-use it because another parsing 
			// operation could start before this one is finished. To force 
			// greedy parsing, we can call ParseStmtsGreedy(), but the caller may 
			// prefer lazy parsing, especially if the input is large. As a 
			// compromise I'll check if the source file is larger than a 
			// certain arbitrary size. Also, ParseExprs() is always greedy 
			// so we can always re-use _parser in that case.
			bool exprMode = inputType == ParsingService.Exprs;
			char _ = '\0';
			if (inputType == ParsingService.Exprs || file.Text.TryGet(255, ref _)) {
				LesParser parser = _parser;
				if (parser == null)
					_parser = parser = new LesParser(input, file, msgs);
				else {
					parser.ErrorSink = msgs;
					parser.Reset(input.AsList(), file);
				}
				if (inputType == ParsingService.Exprs)
					return parser.ExprList();
				else
					return parser.Start(new Holder<TokenType>(TokenType.Semicolon)).Buffered();
			} else {
				var parser = new LesParser(input, file, msgs);
				return parser.Start(new Holder<TokenType>(TokenType.Semicolon)).Buffered();
			}
		}
Ejemplo n.º 2
0
        public IListSource <LNode> Parse(IListSource <Token> input, ISourceFile file, IMessageSink msgs, Symbol inputType = null)
        {
            // For efficiency we'd prefer to re-use our _parser object, but
            // when parsing lazily, we can't re-use it because another parsing
            // operation could start before this one is finished. To force
            // greedy parsing, we can call ParseStmtsGreedy(), but the caller may
            // prefer lazy parsing, especially if the input is large. As a
            // compromise I'll check if the source file is larger than a
            // certain arbitrary size. Also, ParseExprs() is always greedy
            // so we can always re-use _parser in that case.
            bool exprMode = inputType == ParsingService.Exprs;
            char _        = '\0';

            if (inputType == ParsingService.Exprs || file.Text.TryGet(255, ref _))
            {
                LesParser parser = _parser;
                if (parser == null)
                {
                    _parser = parser = new LesParser(input, file, msgs);
                }
                else
                {
                    parser.MessageSink = msgs;
                    parser.Reset(input, file);
                }
                if (inputType == ParsingService.Exprs)
                {
                    return(parser.ParseExprs());
                }
                else
                {
                    return(parser.ParseStmtsGreedy());
                }
            }
            else
            {
                var parser = new LesParser(input, file, msgs);
                return(parser.ParseStmtsLazy().Buffered());
            }
        }