Adding start and stop offsets to CQLNodes objects #19
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.
Hi,
some code parsers/libraries provide source code (query string) location information with the parse tree. I added start and stop offsets (stop being exclusive, Java index style) to query nodes (
CQLNode
) based on the input CQL query string. The test classCQLNodePositionsTest
can be run to visualize the offsets against the original CQL query string.Note that not all the location information for all properties of CQLNodes and its subclasses are stored.
CQLNodePositionsTest
shows how to compute them (seeINFER_OTHER_POSITIONS
flag) as they require the query string for exact offsets and I did not want modify theCQLParser
too heavily. It currently includes a minimal set of start/stop offsets that allow to infer everything else (in what I tested so far).Is this something you can imaging adding to the library? If so, I can refine this further by adding some test outputs for the existing test queries and if needed see about adding more start/stop getter properties.
The primary use case I think of and want to use is being able to know where a parsed
CQLNode
is in the query string. E.g., this can be used to cut a CQLNode from the query string (wouldn't result in a valid CQL query with left/right children in aCQLBooleanNode
as the operator also needs to be cut but it is possible with a bit more work). It might also allow to do some "highlighting" (wrapping) of fragments in the query string for visualizations.The changes are relatively low overhead and there are probably other are uses, too.