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. char _ = '\0'; if (file.Text.TryGet(255, ref _) || inputType == ParsingMode.FormalArguments || inputType == ParsingMode.Types || inputType == ParsingMode.Expressions) { EcsParser parser = _parser; if (parser == null) { _parser = parser = new EcsParser(input, file, msgs); } else { parser.ErrorSink = msgs ?? MessageSink.Default; parser.Reset(input, file); } if (inputType == ParsingMode.Expressions) { return(parser.ParseExprs(false, allowUnassignedVarDecl: false)); } else if (inputType == ParsingMode.FormalArguments) { return(parser.ParseExprs(false, allowUnassignedVarDecl: true)); } else if (inputType == ParsingMode.Types) { return(LNode.List(parser.DataType())); } else { return(parser.ParseStmtsGreedy()); } } else { var parser = new EcsParser(input, file, msgs); return(parser.ParseStmtsLazy().Buffered()); } }
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()); } }