You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Unfortunately, this is correct: the Parser literally swallows any Comments as SPECIAL_TOKENS and removes them from the AST (simply as they do not belong to any Nodes of the AST).
If you want to keep the Comments, then I recommend to:
build a map of the comments based on the ASCII Position of occurance
parse and deparse your statement (could be a formatter too)
re-insert the comments based on the ASCII Position Map
You can check out JSQLFormatter, where I have done exactly this (since a Formatter definitely does not want to swallow comments).
Activity
manticore-projects commentedon Apr 27, 2023
Greetings.
Unfortunately, this is correct: the Parser literally swallows any Comments as
SPECIAL_TOKENSand removes them from the AST (simply as they do not belong to any Nodes of the AST).If you want to keep the Comments, then I recommend to:
ASCII Positionof occuranceASCII PositionMapYou can check out JSQLFormatter, where I have done exactly this (since a Formatter definitely does not want to swallow comments).
https://github.com/manticore-projects/jsqlformatter/blob/e3bc912f3257f91ff5c880567ca0718ef4a6887a/src/main/java/com/manticore/jsqlformatter/JSQLFormatter.java#L1038
https://github.com/manticore-projects/jsqlformatter/blob/e3bc912f3257f91ff5c880567ca0718ef4a6887a/src/main/java/com/manticore/jsqlformatter/JSQLFormatter.java#L1102
manticore-projects commentedon May 16, 2023
Closed, since I have explained it and no further questions has been asked since.