Package dev.frostlake.executor
Class LeadingCommentOffset
java.lang.Object
dev.frostlake.executor.LeadingCommentOffset
A statement that BEGINS with comments reports its positions from the first real token, not from the
top of the text. Measured across nine shapes, and the rule is one line: the first token after the
leading comments becomes line 1, position 0, and everything after it shifts by the same amount.
NULL line 1 position 0
NULL line 1 position 3 whitespace ALONE still counts
/* c */ NULL line 1 position 0
/* c */ NULL line 1 position 0 the whitespace around it goes too
/* c */\nNULL line 1 position 0 the newline does not advance the line
/* a\nb */ NULL line 1 position 0 nor does one INSIDE the comment
-- c\nNULL line 1 position 0
/* c */ SELECT UPPER(o) line 1 position 7 the offset SHIFTS, it is not zeroed
SELECT /* c */ UPPER(o) line 1 position 15 an INTERIOR comment counts normally
The last two are what make this a re-basing rather than a stripping: only text BEFORE the first token disappears, and a comment between tokens is ordinary text that pushes the offset along.
-
Method Summary
Modifier and TypeMethodDescriptionstatic SourcePositionbegin(SourcePosition origin) Note this statement's re-basing origin for the rest of its execution.static voidend(SourcePosition previous) Put back whateverbegin(dev.frostlake.executor.expressions.SourcePosition)displaced; null clears.static SourcePositionWhere the statement's first real token begins, or null when nothing needs re-basing — which is every statement that does not open with a comment, whitespace included.static int[]rebase(int line, int position) A statement-relative place re-based past the leading comments, or unchanged when there are none.
-
Method Details
-
of
Where the statement's first real token begins, or null when nothing needs re-basing — which is every statement that does not open with a comment, whitespace included.- Parameters:
sql- the statement's text- Returns:
- the first token's line and column, or null
-
begin
Note this statement's re-basing origin for the rest of its execution.- Parameters:
origin- the first real token's place, or null for no re-basing- Returns:
- whatever origin it displaced, for
end(dev.frostlake.executor.expressions.SourcePosition)
-
end
Put back whateverbegin(dev.frostlake.executor.expressions.SourcePosition)displaced; null clears. -
rebase
public static int[] rebase(int line, int position) A statement-relative place re-based past the leading comments, or unchanged when there are none. The arithmetic isExpressionSource.resolve(dev.frostlake.executor.expressions.SourcePosition)'s, inverted: a place on the origin's own line loses the origin's column, a later line keeps its column, and the line count drops by however many lines the comments occupied.- Parameters:
line- the place's line, 1-basedposition- its column- Returns:
- the two re-based, as {line, position}
-