Пример #1
0
        private LNode ParseExpr(IListSource <Token> tree)
        {
            if (_parser == null)
            {
                _parser = new EcsParser(tree, SourceFile, ErrorSink);
            }
            else
            {
                _parser.Reset(tree, SourceFile);
            }
            LNode expr = _parser.ExprStart(false);

            return(expr);
        }
Пример #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 _))
            {
                EcsParser parser = _parser;
                if (parser == null)
                {
                    _parser = parser = new EcsParser(input, file, msgs);
                }
                else
                {
                    parser.ErrorSink = msgs;
                    parser.Reset(input, file);
                }
                if (inputType == ParsingService.Exprs)
                {
                    return(parser.ParseExprs());
                }
                else
                {
                    return(parser.ParseStmtsGreedy());
                }
            }
            else
            {
                var parser = new EcsParser(input, file, msgs);
                return(parser.ParseStmtsLazy().Buffered());
            }
        }
Пример #3
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 _)) {
				EcsParser parser = _parser;
				if (parser == null)
					_parser = parser = new EcsParser(input, file, msgs);
				else {
					parser.ErrorSink = msgs ?? MessageSink.Current;
					parser.Reset(input, file);
				}
				if (inputType == ParsingService.Exprs)
					return parser.ParseExprs();
				else
					return parser.ParseStmtsGreedy();
			} else {
				var parser = new EcsParser(input, file, msgs);
				return parser.ParseStmtsLazy().Buffered();
			}
		}
Пример #4
0
		protected override void Stmt(string text, LNode expected, Action<EcsNodePrinter> configure = null, bool exprMode = false, Mode mode = Mode.Both)
		{
			if (mode == Mode.PrintOnly)
				return;
			// This is the easy way: 
			//LNode result = EcsLanguageService.Value.ParseSingle(text, MessageSink.Console, exprMode ? ParsingService.Exprs : ParsingService.Stmts);
			// But to make debugging easier, I'll do it the long way:
			ILexer<Token> lexer = EcsLanguageService.Value.Tokenize(new UString(text), "", MessageSink.Console);
			var preprocessed = new EcsPreprocessor(lexer);
			var treeified = new TokensToTree(preprocessed, false);
			var parser = new EcsParser(treeified.Buffered(), lexer.SourceFile, MessageSink.Console);
			
			LNode result = exprMode ? parser.ExprStart(false) : parser.Stmt();

			AreEqual(TokenType.EOF, parser.LT0.Type());
			AreEqual(expected, result);
		}