blob: 410fa7e715b7a7968f5d6ff85d5509a2d6dcbdbf (
plain)
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
|
package parsec
import "fmt"
type Node interface {
Pos() int
}
type Token struct {
pos int
Value string
}
func (e Token) Pos() int { return e.pos }
func NewToken(pos int, value string) Token {
return Token{pos, value}
}
type Error struct {
pos int
Message string
}
func (e Error) Pos() int { return e.pos }
func (e Error) Error() string { return fmt.Sprintf("offset %d: %s", e.pos, e.Message) }
func NewError(pos int, message string) Error {
return Error{pos, message}
}
func IsError(n Node) bool {
_, isErr := n.(Error)
return isErr
}
type Sequence struct {
pos int
Nodes []Node
}
func (e Sequence) Pos() int { return e.pos }
func NewSequence(pos int, n ...Node) Sequence {
return Sequence{pos, n}
}
|