Skip to content

Conversation

@Querela
Copy link

@Querela Querela commented Jul 3, 2025

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 class CQLNodePositionsTest 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 (see INFER_OTHER_POSITIONS flag) as they require the query string for exact offsets and I did not want modify the CQLParser 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 a CQLBooleanNode 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.

@Querela
Copy link
Author

Querela commented Jul 3, 2025

In #18 is merged, this will also require some whitespace cleanup.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant