-
Notifications
You must be signed in to change notification settings - Fork 18
/
limit_exceeded_error.go
59 lines (50 loc) · 1.67 KB
/
limit_exceeded_error.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// Copyright 2020 The Scriggo Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package compiler
import (
"fmt"
"github.com/open2b/scriggo/ast"
"github.com/open2b/scriggo/internal/runtime"
)
// A LimitExceededError is an error returned by the compiler reporting that the
// compilation has exceeded a limit imposed by the implementation.
type LimitExceededError struct {
// pos is the position of the function that cannot be compiled.
pos *ast.Position
// path of file in which the function is defined.
path string
// msg is the error message. Does not include file/position.
msg string
}
// newLimitExceededError returns a new LimitError that occurred in the file path
// inside a function declared at the given pos.
func newLimitExceededError(pos *runtime.Position, path, format string, a ...interface{}) *LimitExceededError {
astPos := &ast.Position{
Line: pos.Line,
Column: pos.Column,
Start: pos.Start,
End: pos.End,
}
return &LimitExceededError{
pos: astPos,
path: path,
msg: fmt.Sprintf(format, a...),
}
}
// Position returns the position of the function that caused the LimitError.
func (e *LimitExceededError) Position() ast.Position {
return *e.pos
}
// Path returns the path of the source code that caused the LimitError.
func (e *LimitExceededError) Path() string {
return e.path
}
// Message returns the error message of the LimitError.
func (e *LimitExceededError) Message() string {
return e.msg
}
// Error implements the interface error for the LimitError.
func (e *LimitExceededError) Error() string {
return fmt.Sprintf("%s:%s: %s", e.path, e.pos, e.msg)
}