v0.1.0 28f9d6e

errors.go RawHistoryFolder

1// SPDX-License-Identifier: MIT
2
3package expr
4
5import (
6	"fmt"
7)
8
9// Limits of the reference implementation.
10const (
11	// MaxParserDepth is the deepest nesting of groupings, function arguments,
12	// index accesses, negations and logical operators the parser accepts.
13	MaxParserDepth = 50
14	// MaxExpressionLength is the longest expression accepted, counted in
15	// UTF-16 code units like the JavaScript string length it mirrors.
16	MaxExpressionLength = 21000
17)
18
19// ErrorType classifies an [Error].
20type ErrorType int
21
22// The error types of the reference implementation, in its order.
23const (
24	ErrorUnexpectedSymbol ErrorType = iota
25	// ErrorUnrecognizedNamedValue is declared by the reference but never
26	// produced; ErrorUnrecognizedContext carries the same text.
27	ErrorUnrecognizedNamedValue
28	ErrorUnexpectedEndOfExpression
29	ErrorExceededMaxDepth
30	ErrorExceededMaxLength
31	ErrorTooFewParameters
32	ErrorTooManyParameters
33	ErrorEvenParameters
34	ErrorUnrecognizedContext
35	ErrorUnrecognizedFunction
36)
37
38func (t ErrorType) description() string {
39	switch t {
40	case ErrorUnexpectedEndOfExpression:
41		return "Unexpected end of expression"
42	case ErrorUnexpectedSymbol:
43		return "Unexpected symbol"
44	case ErrorUnrecognizedNamedValue:
45		return "Unrecognized named-value"
46	case ErrorExceededMaxDepth:
47		return fmt.Sprintf("Exceeded max expression depth %d", MaxParserDepth)
48	case ErrorExceededMaxLength:
49		return fmt.Sprintf("Exceeded max expression length %d", MaxExpressionLength)
50	case ErrorTooFewParameters:
51		return "Too few parameters supplied"
52	case ErrorTooManyParameters:
53		return "Too many parameters supplied"
54	case ErrorEvenParameters:
55		return "Even number of parameters supplied, requires an odd number of parameters"
56	case ErrorUnrecognizedContext:
57		return "Unrecognized named-value"
58	case ErrorUnrecognizedFunction:
59		return "Unrecognized function"
60	}
61	return "Unknown error"
62}
63
64// Position is a zero-based line and column in an expression. Columns count
65// UTF-16 code units, as in the reference implementation.
66type Position struct {
67	Line   int
68	Column int
69}
70
71// Error is a lexing or parsing error. Its message is exactly the one the
72// reference implementation produces.
73type Error struct {
74	Type ErrorType
75	// Message is the full text, e.g. "Unexpected symbol: ')'".
76	Message string
77	// Pos is where the offending token starts.
78	Pos Position
79	// Token is the text of the offending token.
80	Token string
81}
82
83func (e *Error) Error() string { return e.Message }
84
85// EvalError is an error raised while evaluating an expression: a failing
86// function, such as fromJSON on invalid input, or an invalid format string.
87type EvalError struct {
88	Message string
89	// Err is the underlying error, if any.
90	Err error
91}
92
93func (e *EvalError) Error() string { return e.Message }
94func (e *EvalError) Unwrap() error { return e.Err }
95
96func evalErrorf(format string, a ...any) *EvalError {
97	return &EvalError{Message: fmt.Sprintf(format, a...)}
98}

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