-
Notifications
You must be signed in to change notification settings - Fork 0
/
definitions.go
75 lines (57 loc) · 1.16 KB
/
definitions.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
75
package goparselib
import (
"fmt"
"regexp"
)
type Symbol interface {
symbol()
fmt.Stringer
}
type Terminal struct {
Reg *regexp.Regexp
}
func (t Terminal) String() string {
return fmt.Sprintf("T(%s)", t.Reg.String())
}
func (t Terminal) symbol() {
panic("implement me")
}
type Union []Symbol
func (u Union) String() string {
return fmt.Sprintf("U(%d)", len(u))
}
func (u Union) symbol() {
panic("implement me")
}
type Concat []Symbol
func (c Concat) String() string {
return fmt.Sprintf("C(%d)", len(c))
}
func (c Concat) symbol() {
panic("implement me")
}
type Reference struct {
R *Symbol
}
func (r Reference) String() string {
return fmt.Sprintf("R(%d)", r.R)
}
func (r Reference) symbol() {
panic("implement me")
}
func R(s *Symbol) Reference {
return Reference{s}
}
func CTerminal(expr string) Terminal {
return Terminal{regexp.MustCompilePOSIX(expr)}
}
func Define(s *Symbol, s2 Symbol) {
*s = s2
}
type Node struct {
Start int64 `json:"start"`
Size int64 `json:"size"`
Contents string `json:"contents"`
Type Symbol `json:"-"`
Children []Node `json:"children"`
}