Introduce parsingContext wrapper and refactor _parseExecutionInfo using it #605
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR Introduces a wrapper
parseInternalsintended to make creatingparsingContextsin the various parsing methods ofOLParsereasier and some prerequisites for it in the Scanner and Parser.The wrapper is then used to create the
ParsingContextsin_parseExecutionInfo(), andparseEmbeddedServiceNode()This PR is similar to #581, for which @fmontesi, suggested I start with a simpler parsing method like _parseExecutionInfo
The wrapper method
<I> InternalParseResult<I> parseInternals(ParsingLambda<I> internalsParser)has
<I>, a type that holds the information required to create an AST node,the
ParsingLambda<I>is identical to a standard library Supplier (supplying<I>) except it throws relevant parser Exceptions.the return type
InternalParseResult<I>, is a record class consisting of<I>and ``ParsingContext`.The general way the wrapper is used for a parsing method is as follows:
of the constructor for the AST node the method creates. e.g.new Foo(A a, B, b, C c, ParsingContext context)`parseInternalswithParsingLambdaa lambda function of the body of the parsing method up to and excluding the point where the AST node is created, at the bottom of the lambda return an instance of the record from 2).InternalParseResultreturned by 3) to create the AST node, it will contain the record class of parameter required to do so, as well as an automatically generated ParsingContext.For examples of usage see the simple parsing method
_parseExecutionInfo(), andparseEmbeddedServiceNode()(a slightly less trivial case as requested by @kicito )Changes I made in
Scanner:currColumnto not increment multiple times on '\t' characters, as it made it hard use with for example LSP Range which does not treat '\t' different from other characters. Additionally I made it 0-indexed to match the LSP Location.character after discussion with (@kicito).TokensIn
AbstractParserI added required functionality to store and get theScannertokenEndLineandtokenEndOffset(together known asTokenEnd) as they were one token ago, this is because some (all?) parsing methods inOLParserby increment the Token stored in the Parser after parsing what they need, and have to work that way e.g.The import statement may be done here, but the parser cannot know that without reading the next token, as it may be a comma followed by another symbol to import in the same import statement:
But that means that the current token of the parser after running a parsing method, will be the next non-newline token (the parser skips newlines).
Thus the need for storing the
TokenEndfor the previous token (Bin the example above). It is achieved by storing the last twoTokenEndsin a new Deque fieldpreviousTokenEndthat is managed by a new methodAbstractParser::saveTokenEnd()saveTokenEnd()is called inAbstractParser::readToken()iff the token read from the scanner is not a newline, this is becauseAbstractParser::nextToken()immediately calls readToken again if it encounters a newline, which would otherwise overwrite the saved TokenEnd in unpredictable ways.As a caveat: The parser can add tokens back to be read before the next token in the scanner, unfortunately I do not have time to look into or handle those cases.