-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathterminal_node.go
74 lines (62 loc) · 1.67 KB
/
terminal_node.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
68
69
70
71
72
73
74
// 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 ast
import (
"fmt"
"github.com/conflowio/parsley/parsley"
)
// TerminalNode is a leaf node in the AST
type TerminalNode struct {
schema interface{}
token string
value interface{}
pos parsley.Pos
readerPos parsley.Pos
}
// NewTerminalNode creates a new TerminalNode instance
func NewTerminalNode(
schema interface{},
token string,
value interface{},
pos parsley.Pos,
readerPos parsley.Pos,
) *TerminalNode {
return &TerminalNode{
schema: schema,
token: token,
value: value,
pos: pos,
readerPos: readerPos,
}
}
// Token returns with the node token
func (t *TerminalNode) Token() string {
return t.token
}
// Schema returns the schema for the node's value
func (t *TerminalNode) Schema() interface{} {
return t.schema
}
// Value returns with the value of the node
func (t *TerminalNode) Value() interface{} {
return t.value
}
// Pos returns the position
func (t *TerminalNode) Pos() parsley.Pos {
return t.pos
}
// ReaderPos returns the position of the first character immediately after this node
func (t *TerminalNode) ReaderPos() parsley.Pos {
return t.readerPos
}
// SetReaderPos changes the reader position
func (t *TerminalNode) SetReaderPos(f func(parsley.Pos) parsley.Pos) {
t.readerPos = f(t.readerPos)
}
// String returns with a string representation of the node
func (t *TerminalNode) String() string {
return fmt.Sprintf("%s{%v, %d..%d}", t.token, t.value, t.pos, t.readerPos)
}