public LangElement Parse( ITokenProvider <SemanticValueType, Span> lexer, INodesFactory <LangElement, Span> astFactory, LanguageFeatures language, IErrorSink <Span> errors = null, IErrorRecovery errorRecovery = null, int positionShift = 0) { if (lexer == null) { throw new ArgumentNullException(nameof(lexer)); } if (astFactory == null) { throw new ArgumentNullException(nameof(astFactory)); } // initialization: _languageFeatures = language; if (errorRecovery != null) { _lexer = new BufferedLexer(new CompliantLexer(lexer)); } else { _lexer = new CompliantLexer(lexer); } _astFactory = astFactory; _errors = errors ?? new EmptyErrorSink <Span>(); _errorRecovery = errorRecovery ?? new EmptyErrorRecovery(); //InitializeFields(); _currentScope = new Scope(0); base.Scanner = _lexer; bool accept = base.Parse(); LangElement result = _astRoot; // clean and let GC collect unused AST and other stuff: //ClearFields(); return(result); }
public LangElement Parse( ITokenProvider <SemanticValueType, Span> lexer, INodesFactory <LangElement, Span> astFactory, LanguageFeatures language, IErrorSink <Span> errors = null, IErrorRecovery errorRecovery = null, int positionShift = 0) { if (lexer == null) { throw new ArgumentNullException(nameof(lexer)); } // initialization: _languageFeatures = language; _lexer = new CompliantLexer(lexer, language); _astFactory = astFactory ?? throw new ArgumentNullException(nameof(astFactory)); _errors = errors ?? new EmptyErrorSink <Span>(); if (errorRecovery != null) { _lexer = new BufferedLexer(_lexer); _errorRecovery = errorRecovery; } else { _errorRecovery = EmptyErrorRecovery.Instance; } //InitializeFields(); _currentScope = new Scope(0); base.Scanner = _lexer; bool accept = base.Parse(); // return(_astRoot); }
/// <summary> /// Construct a new parser state based on its current state. /// </summary> /// <param name="state">Current parser state.</param> /// <param name="expectedTokens">Expected tokens.</param> /// <param name="previousToken">Previous token.</param> /// <param name="currentToken">Current token.</param> /// <param name="provider">Currently used lexer.</param> public LexerState(int state, Dictionary <int, int> expectedTokens, CompleteToken previousToken, CompleteToken currentToken, IParserTokenProvider <SemanticValueType, Span> provider) { CurrentState = state; _buffer = new List <CompleteToken>() { currentToken }; _expectedTokens = expectedTokens; _provider = provider; _previousToken = previousToken; }
public BufferedLexer(IParserTokenProvider <SemanticValueType, Span> provider) { _provider = provider; }