Пример #1
0
        public IListSource <LNode> Parse(IListSource <Token> input, ISourceFile file, IMessageSink msgs, ParsingMode 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 == ParsingMode.Expressions;
            char _        = '\0';

            if (inputType == ParsingMode.Expressions || file.Text.TryGet(255, ref _))
            {
                Les3Parser parser = _parser;
                if (parser == null)
                {
                    _parser = parser = new Les3Parser(input.AsList(), file, msgs);
                }
                else
                {
                    parser.ErrorSink = msgs;
                    parser.Reset(input.AsList(), file);
                }
                if (inputType == ParsingMode.Expressions)
                {
                    return(parser.Start(new Holder <TokenType>(default(TokenType))).Buffered());
                }
                else
                {
                    return(parser.Start(new Holder <TokenType>(TokenType.Semicolon)).Buffered());
                }
            }
            else
            {
                var parser = new Les3Parser(input.AsList(), file, msgs);
                return(parser.Start(new Holder <TokenType>(TokenType.Semicolon)).Buffered());
            }
        }
Пример #2
0
		public IListSource<LNode> Parse(IListSource<Token> input, ISourceFile file, IMessageSink msgs, ParsingMode 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 == ParsingMode.Expressions;
			char _ = '\0';
			if (inputType == ParsingMode.Expressions || file.Text.TryGet(255, ref _)) {
				Les3Parser parser = _parser;
				if (parser == null)
					_parser = parser = new Les3Parser(input.AsList(), file, msgs);
				else {
					parser.ErrorSink = msgs;
					parser.Reset(input.AsList(), file);
				}
				if (inputType == ParsingMode.Expressions)
					return parser.Start(new Holder<TokenType>(default(TokenType))).Buffered();
				else
					return parser.Start(new Holder<TokenType>(TokenType.Semicolon)).Buffered();
			} else {
				var parser = new Les3Parser(input.AsList(), file, msgs);
				return parser.Start(new Holder<TokenType>(TokenType.Semicolon)).Buffered();
			}
		}