-
Notifications
You must be signed in to change notification settings - Fork 1
/
end.go
67 lines (53 loc) · 1.58 KB
/
end.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
60
61
62
63
64
65
66
67
// Copyright (c) 2017 Opsidian Ltd.
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
package parser
import (
"errors"
"fmt"
"github.com/conflowio/parsley/data"
"github.com/conflowio/parsley/parsley"
)
// EOF is the end-of-file token
const EOF = "EOF"
// EndNode represents an eof node
type EndNode parsley.Pos
// Token returns with EOF
func (e EndNode) Token() string {
return EOF
}
// Schema returns with nil
func (e EndNode) Schema() interface{} {
return nil
}
// Value returns with nil
func (e EndNode) Value(userCtx interface{}) (interface{}, parsley.Error) {
return nil, nil
}
// Pos returns with the position
func (e EndNode) Pos() parsley.Pos {
return parsley.Pos(e)
}
// ReaderPos returns the reader position
func (e EndNode) ReaderPos() parsley.Pos {
return parsley.Pos(e)
}
// SetReaderPos changes the reader position
func (e EndNode) SetReaderPos(func(parsley.Pos) parsley.Pos) {
}
// String returns with a string representation of the node
func (e EndNode) String() string {
return fmt.Sprintf("%s{%d}", e.Token(), e.Pos())
}
// End matches the end of the input
func End() Func {
notFoundErr := errors.New("was expecting the end of input")
return Func(func(ctx *parsley.Context, leftRecCtx data.IntMap, pos parsley.Pos) (parsley.Node, data.IntSet, parsley.Error) {
if ctx.Reader().IsEOF(pos) {
return EndNode(pos), data.EmptyIntSet, nil
}
return nil, data.EmptyIntSet, parsley.NewError(pos, notFoundErr)
})
}