detached 34c7f70

chore(expr): remove the helpers of the replaced JavaScript parser, fix lint

commit
34c7f7071bc2916f810d1d512d813a09b0312b83
author
brice · · 2026-10-12 18:20 UTC
parent
5f9df8b
signature
GPG VerifiedCD88F9E564E0102646FB6077A1A07C7C7C3E349D · arch-gpg Verified for the committer email
5 files · +5 -45
M expr/casing.go +0 -5
@@ -27,11 +27,6 @@ func isJSSpace(r rune) bool {
2727 return r >= 0x2000 && r <= 0x200A
2828 }
2929
30-// jsTrim is String.prototype.trim.
31-func jsTrim(s string) string {
32- return strings.TrimFunc(s, isJSSpace)
33-}
34-
3530 func isASCII(s string) bool {
3631 for i := 0; i < len(s); i++ {
3732 if s[i] >= utf8.RuneSelf {
@@ -27,11 +27,6 @@ func isJSSpace(r rune) bool {
27 return r >= 0x2000 && r <= 0x200A27 return r >= 0x2000 && r <= 0x200A
28 }28 }
29 29
30-// jsTrim is String.prototype.trim.
31-func jsTrim(s string) string {
32- return strings.TrimFunc(s, isJSSpace)
33-}
34-
35 func isASCII(s string) bool {30 func isASCII(s string) bool {
36 for i := 0; i < len(s); i++ {31 for i := 0; i < len(s); i++ {
37 if s[i] >= utf8.RuneSelf {32 if s[i] >= utf8.RuneSelf {
M expr/errors.go +0 -9
@@ -82,15 +82,6 @@ type Error struct {
8282
8383 func (e *Error) Error() string { return e.Message }
8484
85-func newTokenError(t ErrorType, tok Token) *Error {
86- return &Error{
87- Type: t,
88- Message: t.description() + ": '" + tokenString(tok) + "'",
89- Pos: tok.Range.Start,
90- Token: tokenString(tok),
91- }
92-}
93-
9485 // EvalError is an error raised while evaluating an expression: a failing
9586 // function, such as fromJSON on invalid input, or an invalid format string.
9687 type EvalError struct {
@@ -82,15 +82,6 @@ type Error struct {
82 82
83 func (e *Error) Error() string { return e.Message }83 func (e *Error) Error() string { return e.Message }
84 84
85-func newTokenError(t ErrorType, tok Token) *Error {
86- return &Error{
87- Type: t,
88- Message: t.description() + ": '" + tokenString(tok) + "'",
89- Pos: tok.Range.Start,
90- Token: tokenString(tok),
91- }
92-}
93-
94 // EvalError is an error raised while evaluating an expression: a failing85 // EvalError is an error raised while evaluating an expression: a failing
95 // function, such as fromJSON on invalid input, or an invalid format string.86 // function, such as fromJSON on invalid input, or an invalid format string.
96 type EvalError struct {87 type EvalError struct {
M expr/lexer.go +0 -11
@@ -70,17 +70,6 @@ type Token struct {
7070 Value Value
7171 }
7272
73-// tokenString is the text an error message shows for a token.
74-func tokenString(t Token) string {
75- switch t.Type {
76- case TokenEOF:
77- return "EOF"
78- case TokenString:
79- return string(t.Value.(String))
80- }
81- return t.Lexeme
82-}
83-
8473 // Lex splits an expression into tokens the way the JavaScript reference's
8574 // lexer does, ending with a TokenEOF token. [Parse] does not use it: it
8675 // follows the C# runner, whose tokenizer is context sensitive and lazy (see
@@ -70,17 +70,6 @@ type Token struct {
70 Value Value70 Value Value
71 }71 }
72 72
73-// tokenString is the text an error message shows for a token.
74-func tokenString(t Token) string {
75- switch t.Type {
76- case TokenEOF:
77- return "EOF"
78- case TokenString:
79- return string(t.Value.(String))
80- }
81- return t.Lexeme
82-}
83-
84 // Lex splits an expression into tokens the way the JavaScript reference's73 // Lex splits an expression into tokens the way the JavaScript reference's
85 // lexer does, ending with a TokenEOF token. [Parse] does not use it: it74 // lexer does, ending with a TokenEOF token. [Parse] does not use it: it
86 // follows the C# runner, whose tokenizer is context sensitive and lazy (see75 // follows the C# runner, whose tokenizer is context sensitive and lazy (see
M expr/parse_runner.go +3 -18
@@ -3,6 +3,7 @@
33 package expr
44
55 import (
6+ "strconv"
67 "strings"
78 "unicode/utf16"
89 )
@@ -206,7 +207,7 @@ func (l *csLexer) readNumber() *csToken {
206207 start := l.index
207208 for {
208209 l.index++
209- if !(l.index < len(l.units) && (!isCSBoundary(l.units[l.index]) || l.units[l.index] == '.')) {
210+ if l.index >= len(l.units) || (isCSBoundary(l.units[l.index]) && l.units[l.index] != '.') {
210211 break
211212 }
212213 }
@@ -407,28 +408,12 @@ func (p *csParser) fail(t ErrorType, tok *csToken) *Error {
407408 }
408409 return &Error{
409410 Type: t,
410- Message: t.description() + ": '" + tok.raw + "'. Located at position " + itoa(tok.index+1) + " within expression: " + p.expression,
411+ Message: t.description() + ": '" + tok.raw + "'. Located at position " + strconv.Itoa(tok.index+1) + " within expression: " + p.expression,
411412 Pos: p.position(tok.index),
412413 Token: tok.raw,
413414 }
414415 }
415416
416-func itoa(n int) string { return strings.TrimSpace(strings.Repeat(" ", 0) + intString(n)) }
417-
418-func intString(n int) string {
419- if n == 0 {
420- return "0"
421- }
422- var b [20]byte
423- i := len(b)
424- for n > 0 {
425- i--
426- b[i] = byte('0' + n%10)
427- n /= 10
428- }
429- return string(b[i:])
430-}
431-
432417 // position converts an absolute index into the line and column of the
433418 // JavaScript-style Position (line breaks are U+000A).
434419 func (p *csParser) position(index int) Position {
@@ -3,6 +3,7 @@
3 package expr3 package expr
4 4
5 import (5 import (
6+ "strconv"
6 "strings"7 "strings"
7 "unicode/utf16"8 "unicode/utf16"
8 )9 )
@@ -206,7 +207,7 @@ func (l *csLexer) readNumber() *csToken {
206 start := l.index207 start := l.index
207 for {208 for {
208 l.index++209 l.index++
209- if !(l.index < len(l.units) && (!isCSBoundary(l.units[l.index]) || l.units[l.index] == '.')) {210+ if l.index >= len(l.units) || (isCSBoundary(l.units[l.index]) && l.units[l.index] != '.') {
210 break211 break
211 }212 }
212 }213 }
@@ -407,28 +408,12 @@ func (p *csParser) fail(t ErrorType, tok *csToken) *Error {
407 }408 }
408 return &Error{409 return &Error{
409 Type: t,410 Type: t,
410- Message: t.description() + ": '" + tok.raw + "'. Located at position " + itoa(tok.index+1) + " within expression: " + p.expression,411+ Message: t.description() + ": '" + tok.raw + "'. Located at position " + strconv.Itoa(tok.index+1) + " within expression: " + p.expression,
411 Pos: p.position(tok.index),412 Pos: p.position(tok.index),
412 Token: tok.raw,413 Token: tok.raw,
413 }414 }
414 }415 }
415 416
416-func itoa(n int) string { return strings.TrimSpace(strings.Repeat(" ", 0) + intString(n)) }
417-
418-func intString(n int) string {
419- if n == 0 {
420- return "0"
421- }
422- var b [20]byte
423- i := len(b)
424- for n > 0 {
425- i--
426- b[i] = byte('0' + n%10)
427- n /= 10
428- }
429- return string(b[i:])
430-}
431-
432 // position converts an absolute index into the line and column of the417 // position converts an absolute index into the line and column of the
433 // JavaScript-style Position (line breaks are U+000A).418 // JavaScript-style Position (line breaks are U+000A).
434 func (p *csParser) position(index int) Position {419 func (p *csParser) position(index int) Position {
M expr/runner_strict_test.go +2 -2
@@ -11,8 +11,8 @@ import (
1111 // knownRunnerDifference classifies the answers of the corpus on which this
1212 // package knowingly differs from the runner. It returns the reason, or "".
1313 func knownRunnerDifference(g, r runnerCase) string {
14- switch {
15- case r.E == "-0" || r.E == "toJSON(-0)":
14+ switch r.E {
15+ case "-0", "toJSON(-0)":
1616 // .NET Core formats negative zero as "-0". The runner's newer copy
1717 // (src/Sdk/Expressions/EvaluationResult.cs) maps it back to "0" and the
1818 // shared fixtures (coerce_string.json) say "0", so "0" is kept.
@@ -11,8 +11,8 @@ import (
11 // knownRunnerDifference classifies the answers of the corpus on which this11 // knownRunnerDifference classifies the answers of the corpus on which this
12 // package knowingly differs from the runner. It returns the reason, or "".12 // package knowingly differs from the runner. It returns the reason, or "".
13 func knownRunnerDifference(g, r runnerCase) string {13 func knownRunnerDifference(g, r runnerCase) string {
14- switch {14+ switch r.E {
15- case r.E == "-0" || r.E == "toJSON(-0)":15+ case "-0", "toJSON(-0)":
16 // .NET Core formats negative zero as "-0". The runner's newer copy16 // .NET Core formats negative zero as "-0". The runner's newer copy
17 // (src/Sdk/Expressions/EvaluationResult.cs) maps it back to "0" and the17 // (src/Sdk/Expressions/EvaluationResult.cs) maps it back to "0" and the
18 // shared fixtures (coerce_string.json) say "0", so "0" is kept.18 // shared fixtures (coerce_string.json) say "0", so "0" is kept.

Keyboard shortcuts

Single-key shortcuts are on. ctrl k and esc work whatever this says.

ctrl k :
go to a section, branch, tag, file or repository
?
this list
j k
move the row cursor down / up
enter
open the row under the cursor; on Files, a directory opens or closes in place
↑ ↓ ← → home end
in the file tree (focus on a row): previous / next row, close / open a directory or go to its parent / first entry, first / last row. They never open a file
l h
on Files: open a directory or a file / close a directory or go up to its parent, then to the parent page. Elsewhere: into the side panel (on a merge request, its files) / back to the content; there j k move between its controls
g g G
first / last row
/
filter the list; on Files, find a file anywhere in the repository (esc clears, enter opens the best match)
b
switch branch or tag
g s g f g c g b g m g i g r g a
tabs: summary, files, commits, branches & tags, merge requests, issues, releases, actions (when available)
g h
home
w
wide mode: use the whole width of the screen, or not (remembered)
y
copy a permalink pinned to the commit
d u x
diff: split / unified / collapse or expand all
e E
diff: the whole file in view / every file, with the lines the hunks hide
n
merge request: next note in the diff
esc
close a dialog, leave a field

Branches 1

Tags 3

↑↓ moveenter openesc close