Repository navigation
Conversation
captureRest() collapsed a dot into the token in front of it whenever the
previous token ended with a dot or the current token was a dot, without
looking at what followed. A dot which starts a number was therefore glued
to its neighbour, and the captured token stream no longer read back the
same way once it was rendered and parsed again:
REPLACE( . 5 captured as REPLACE ( .5
REPLACE( INTO t VALUES (1, . 5) REPLACE ( INTO t VALUES ( 1 ,.5 )
REPLACE( x . 1 . 2 captured as REPLACE ( x.1.2
toString() of such a statement is not a fixpoint, and the token stream it
prints is not what the input contained.
The dot is now only used to collapse a qualified name when it is a
qualifier. A dot which is followed by a number, and a number in front of
a dot, keep the tokens apart. A qualified name still collapses:
REPLACE( t . a . b captured as REPLACE ( t.a.b
REPLACE( a . b captured as REPLACE ( a.b
|
One token-preservation case remains on this head: |
|
I don't see the benefit in adding the complexity. Do you have any practical relevant use-case? |
|
You're right, and I could not find the use case either. What I checked:
The patch also does not establish its own invariant: on this head, Closing it rather than adding complexity you have to carry. If you ever want it, it is a handful of lines in |
captureRest()collapses a dot into the token in front of it whenever the previous token ends with a dot or the token is a dot, without looking at what follows. A dot which starts a number is therefore glued to its neighbour, and the captured token stream no longer reads back the same way once the statement is rendered and parsed again.The lexer reads
.5and5.as single doubles, so joining a dot in that position changes the token stream that the statement was built from.Fix
captureRest()now only uses a dot to collapse a qualified name when the dot is a qualifier (src/main/jjtree/net/sf/jsqlparser/parser/JSqlParserCC.jjt). A dot which is followed by a number is kept as its own token, and a number in front of a dot is not extended:Tests
Two tests in
UnsupportedStatementTest:testCaptureRestKeepsADotInFrontOfANumberchecks that the captured tokens read back the same way, and that the rendered statement parses to itself.testCaptureRestStillCollapsesAQualifiedNamepins the qualified name case, including the quoted"inter"."inter_user_rec"fromtestCaptureRestIssue1993.On the parent commit the new test fails with
and with the fix the suite passes:
mvn verifywas run locally on JDK 17 with-Dtoolchain.jdk.version=[17,26). The change is confined toJAVACODEmethods, so no grammar production is altered and no choice conflict is introduced.Ref #386 and #1993, which are about the same token echo.