Repository navigation
Establish complete source spans and diagnostics #328
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -70,12 +70,18 @@ func (e *ParseError) renderCaret(b *strings.Builder) { | |
| line := e.starts.lineText(e.input, e.Line) | ||
| b.WriteString(line) | ||
| b.WriteByte('\n') | ||
| for i := 1; i < e.Column; i++ { | ||
| b.WriteByte(' ') | ||
| lineStart := e.starts[int(e.Line)-1] | ||
| offset := int(e.Pos) - lineStart | ||
| if offset < 0 { | ||
| offset = 0 | ||
| } | ||
| if offset > len(line) { | ||
| offset = len(line) | ||
| } | ||
| b.WriteString(strings.Repeat(" ", displayWidth(line[:offset]))) | ||
| width := 1 | ||
| if e.Got != nil && len(e.Got.String) > width { | ||
| width = len(e.Got.String) | ||
| if e.Got != nil && displayWidth(e.Got.String) > width { | ||
| width = displayWidth(e.Got.String) | ||
|
Comment on lines
+83
to
+84
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
After string token positions were changed to include their quotes, Useful? React with 👍 / 👎. |
||
| } | ||
| b.WriteString(strings.Repeat("^", width)) | ||
| b.WriteByte('\n') | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,10 @@ | ||
| package parser | ||
|
|
||
| import "sort" | ||
| import ( | ||
| "sort" | ||
| "unicode" | ||
| "unicode/utf8" | ||
| ) | ||
|
|
||
| // lineStarts holds the byte offset where each line of the input begins | ||
| // (lineStarts[i] is the start of 0-based line i). It is built once so that | ||
|
|
@@ -45,3 +49,29 @@ func (s lineStarts) lineText(input string, line int) string { | |
| } | ||
| return input[start:end] | ||
| } | ||
|
|
||
| func displayWidth(text string) int { | ||
| width := 0 | ||
| for len(text) > 0 { | ||
| r, size := utf8.DecodeRuneInString(text) | ||
| switch { | ||
| case r == '\t': | ||
| width += 8 - width%8 | ||
| case unicode.Is(unicode.Mn, r) || unicode.Is(unicode.Me, r): | ||
| case eastAsianWide(r): | ||
| width += 2 | ||
| default: | ||
| width++ | ||
| } | ||
| text = text[size:] | ||
| } | ||
| return width | ||
| } | ||
|
|
||
| func eastAsianWide(r rune) bool { | ||
| return r >= 0x1100 && (r <= 0x115f || r == 0x2329 || r == 0x232a || | ||
| (r >= 0x2e80 && r <= 0xa4cf) || (r >= 0xac00 && r <= 0xd7a3) || | ||
| (r >= 0xf900 && r <= 0xfaff) || (r >= 0xfe10 && r <= 0xfe19) || | ||
| (r >= 0xfe30 && r <= 0xfe6f) || (r >= 0xff00 && r <= 0xff60) || | ||
| (r >= 0xffe0 && r <= 0xffe6)) | ||
|
Comment on lines
+71
to
+76
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The new width table stops at BMP ranges, so supplementary characters that occupy two terminal cells—such as CJK Extension B rune Useful? React with 👍 / 👎. |
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,7 @@ | ||
| [ | ||
| { | ||
| "SelectPos": 0, | ||
| "StatementEnd": 43, | ||
| "StatementEnd": 44, | ||
| "With": null, | ||
| "Top": null, | ||
| "HasDistinct": false, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,7 @@ | ||
| [ | ||
| { | ||
| "SelectPos": 0, | ||
| "StatementEnd": 34, | ||
| "StatementEnd": 35, | ||
| "With": null, | ||
| "Top": null, | ||
| "HasDistinct": false, | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For parametric aggregate calls,
Params.ColumnArgListcontains the second argument list, but this end position still stops after the first list. For example, parsingSELECT quantile(0.9)(x)reports the function and root query ending afterquantile(0.9), excluding(x), so source-rewriting consumers receive an incomplete span. Use the trailingColumnArgListend when it is present.Useful? React with 👍 / 👎.