This commit is contained in:
Lucas Serven
2019-01-18 02:50:10 +01:00
commit e989f0a25f
1789 changed files with 680059 additions and 0 deletions

View File

@@ -0,0 +1,56 @@
// Code generated by gocc; DO NOT EDIT.
package errors
import (
"bytes"
"fmt"
"github.com/awalterschulze/gographviz/internal/token"
)
type ErrorSymbol interface {
}
type Error struct {
Err error
ErrorToken *token.Token
ErrorSymbols []ErrorSymbol
ExpectedTokens []string
StackTop int
}
func (e *Error) String() string {
w := new(bytes.Buffer)
fmt.Fprintf(w, "Error")
if e.Err != nil {
fmt.Fprintf(w, " %s\n", e.Err)
} else {
fmt.Fprintf(w, "\n")
}
fmt.Fprintf(w, "Token: type=%d, lit=%s\n", e.ErrorToken.Type, e.ErrorToken.Lit)
fmt.Fprintf(w, "Pos: offset=%d, line=%d, column=%d\n", e.ErrorToken.Pos.Offset, e.ErrorToken.Pos.Line, e.ErrorToken.Pos.Column)
fmt.Fprintf(w, "Expected one of: ")
for _, sym := range e.ExpectedTokens {
fmt.Fprintf(w, "%s ", sym)
}
fmt.Fprintf(w, "ErrorSymbol:\n")
for _, sym := range e.ErrorSymbols {
fmt.Fprintf(w, "%v\n", sym)
}
return w.String()
}
func (e *Error) Error() string {
w := new(bytes.Buffer)
fmt.Fprintf(w, "Error in S%d: %s, %s", e.StackTop, token.TokMap.TokenString(e.ErrorToken), e.ErrorToken.Pos.String())
if e.Err != nil {
fmt.Fprintf(w, ": %+v", e.Err)
} else {
fmt.Fprintf(w, ", expected one of: ")
for _, expected := range e.ExpectedTokens {
fmt.Fprintf(w, "%s ", expected)
}
}
return w.String()
}

View File

@@ -0,0 +1,587 @@
// Code generated by gocc; DO NOT EDIT.
package lexer
import (
"fmt"
"github.com/awalterschulze/gographviz/internal/token"
)
type ActionTable [NumStates]ActionRow
type ActionRow struct {
Accept token.Type
Ignore string
}
func (a ActionRow) String() string {
return fmt.Sprintf("Accept=%d, Ignore=%s", a.Accept, a.Ignore)
}
var ActTab = ActionTable{
ActionRow{ // S0
Accept: 0,
Ignore: "",
},
ActionRow{ // S1
Accept: -1,
Ignore: "!whitespace",
},
ActionRow{ // S2
Accept: 0,
Ignore: "",
},
ActionRow{ // S3
Accept: 0,
Ignore: "",
},
ActionRow{ // S4
Accept: 13,
Ignore: "",
},
ActionRow{ // S5
Accept: 0,
Ignore: "",
},
ActionRow{ // S6
Accept: 0,
Ignore: "",
},
ActionRow{ // S7
Accept: 0,
Ignore: "",
},
ActionRow{ // S8
Accept: 18,
Ignore: "",
},
ActionRow{ // S9
Accept: 14,
Ignore: "",
},
ActionRow{ // S10
Accept: 7,
Ignore: "",
},
ActionRow{ // S11
Accept: 0,
Ignore: "",
},
ActionRow{ // S12
Accept: 8,
Ignore: "",
},
ActionRow{ // S13
Accept: 18,
Ignore: "",
},
ActionRow{ // S14
Accept: 18,
Ignore: "",
},
ActionRow{ // S15
Accept: 18,
Ignore: "",
},
ActionRow{ // S16
Accept: 18,
Ignore: "",
},
ActionRow{ // S17
Accept: 18,
Ignore: "",
},
ActionRow{ // S18
Accept: 18,
Ignore: "",
},
ActionRow{ // S19
Accept: 11,
Ignore: "",
},
ActionRow{ // S20
Accept: 12,
Ignore: "",
},
ActionRow{ // S21
Accept: 18,
Ignore: "",
},
ActionRow{ // S22
Accept: 18,
Ignore: "",
},
ActionRow{ // S23
Accept: 18,
Ignore: "",
},
ActionRow{ // S24
Accept: 18,
Ignore: "",
},
ActionRow{ // S25
Accept: 18,
Ignore: "",
},
ActionRow{ // S26
Accept: 18,
Ignore: "",
},
ActionRow{ // S27
Accept: 3,
Ignore: "",
},
ActionRow{ // S28
Accept: 4,
Ignore: "",
},
ActionRow{ // S29
Accept: 18,
Ignore: "",
},
ActionRow{ // S30
Accept: 0,
Ignore: "",
},
ActionRow{ // S31
Accept: 18,
Ignore: "",
},
ActionRow{ // S32
Accept: 0,
Ignore: "",
},
ActionRow{ // S33
Accept: 0,
Ignore: "",
},
ActionRow{ // S34
Accept: -1,
Ignore: "!comment",
},
ActionRow{ // S35
Accept: 17,
Ignore: "",
},
ActionRow{ // S36
Accept: 16,
Ignore: "",
},
ActionRow{ // S37
Accept: 18,
Ignore: "",
},
ActionRow{ // S38
Accept: 0,
Ignore: "",
},
ActionRow{ // S39
Accept: 0,
Ignore: "",
},
ActionRow{ // S40
Accept: 18,
Ignore: "",
},
ActionRow{ // S41
Accept: 0,
Ignore: "",
},
ActionRow{ // S42
Accept: 0,
Ignore: "",
},
ActionRow{ // S43
Accept: 18,
Ignore: "",
},
ActionRow{ // S44
Accept: 18,
Ignore: "",
},
ActionRow{ // S45
Accept: 18,
Ignore: "",
},
ActionRow{ // S46
Accept: 18,
Ignore: "",
},
ActionRow{ // S47
Accept: 18,
Ignore: "",
},
ActionRow{ // S48
Accept: 18,
Ignore: "",
},
ActionRow{ // S49
Accept: 18,
Ignore: "",
},
ActionRow{ // S50
Accept: 18,
Ignore: "",
},
ActionRow{ // S51
Accept: 18,
Ignore: "",
},
ActionRow{ // S52
Accept: 18,
Ignore: "",
},
ActionRow{ // S53
Accept: 18,
Ignore: "",
},
ActionRow{ // S54
Accept: 18,
Ignore: "",
},
ActionRow{ // S55
Accept: 18,
Ignore: "",
},
ActionRow{ // S56
Accept: 18,
Ignore: "",
},
ActionRow{ // S57
Accept: 18,
Ignore: "",
},
ActionRow{ // S58
Accept: 18,
Ignore: "",
},
ActionRow{ // S59
Accept: 18,
Ignore: "",
},
ActionRow{ // S60
Accept: 18,
Ignore: "",
},
ActionRow{ // S61
Accept: 18,
Ignore: "",
},
ActionRow{ // S62
Accept: 18,
Ignore: "",
},
ActionRow{ // S63
Accept: 0,
Ignore: "",
},
ActionRow{ // S64
Accept: 0,
Ignore: "",
},
ActionRow{ // S65
Accept: 0,
Ignore: "",
},
ActionRow{ // S66
Accept: 0,
Ignore: "",
},
ActionRow{ // S67
Accept: 18,
Ignore: "",
},
ActionRow{ // S68
Accept: 0,
Ignore: "",
},
ActionRow{ // S69
Accept: 18,
Ignore: "",
},
ActionRow{ // S70
Accept: 18,
Ignore: "",
},
ActionRow{ // S71
Accept: 18,
Ignore: "",
},
ActionRow{ // S72
Accept: 18,
Ignore: "",
},
ActionRow{ // S73
Accept: 18,
Ignore: "",
},
ActionRow{ // S74
Accept: 18,
Ignore: "",
},
ActionRow{ // S75
Accept: 18,
Ignore: "",
},
ActionRow{ // S76
Accept: 18,
Ignore: "",
},
ActionRow{ // S77
Accept: 18,
Ignore: "",
},
ActionRow{ // S78
Accept: 18,
Ignore: "",
},
ActionRow{ // S79
Accept: 18,
Ignore: "",
},
ActionRow{ // S80
Accept: 18,
Ignore: "",
},
ActionRow{ // S81
Accept: 18,
Ignore: "",
},
ActionRow{ // S82
Accept: 18,
Ignore: "",
},
ActionRow{ // S83
Accept: 18,
Ignore: "",
},
ActionRow{ // S84
Accept: 18,
Ignore: "",
},
ActionRow{ // S85
Accept: 18,
Ignore: "",
},
ActionRow{ // S86
Accept: 18,
Ignore: "",
},
ActionRow{ // S87
Accept: 18,
Ignore: "",
},
ActionRow{ // S88
Accept: 18,
Ignore: "",
},
ActionRow{ // S89
Accept: -1,
Ignore: "!comment",
},
ActionRow{ // S90
Accept: 0,
Ignore: "",
},
ActionRow{ // S91
Accept: 18,
Ignore: "",
},
ActionRow{ // S92
Accept: 18,
Ignore: "",
},
ActionRow{ // S93
Accept: 18,
Ignore: "",
},
ActionRow{ // S94
Accept: 10,
Ignore: "",
},
ActionRow{ // S95
Accept: 18,
Ignore: "",
},
ActionRow{ // S96
Accept: 18,
Ignore: "",
},
ActionRow{ // S97
Accept: 9,
Ignore: "",
},
ActionRow{ // S98
Accept: 18,
Ignore: "",
},
ActionRow{ // S99
Accept: 18,
Ignore: "",
},
ActionRow{ // S100
Accept: 18,
Ignore: "",
},
ActionRow{ // S101
Accept: 18,
Ignore: "",
},
ActionRow{ // S102
Accept: 18,
Ignore: "",
},
ActionRow{ // S103
Accept: 18,
Ignore: "",
},
ActionRow{ // S104
Accept: 18,
Ignore: "",
},
ActionRow{ // S105
Accept: 18,
Ignore: "",
},
ActionRow{ // S106
Accept: 18,
Ignore: "",
},
ActionRow{ // S107
Accept: 18,
Ignore: "",
},
ActionRow{ // S108
Accept: 18,
Ignore: "",
},
ActionRow{ // S109
Accept: 18,
Ignore: "",
},
ActionRow{ // S110
Accept: 18,
Ignore: "",
},
ActionRow{ // S111
Accept: 18,
Ignore: "",
},
ActionRow{ // S112
Accept: 2,
Ignore: "",
},
ActionRow{ // S113
Accept: 18,
Ignore: "",
},
ActionRow{ // S114
Accept: 18,
Ignore: "",
},
ActionRow{ // S115
Accept: 18,
Ignore: "",
},
ActionRow{ // S116
Accept: 18,
Ignore: "",
},
ActionRow{ // S117
Accept: 18,
Ignore: "",
},
ActionRow{ // S118
Accept: 18,
Ignore: "",
},
ActionRow{ // S119
Accept: 18,
Ignore: "",
},
ActionRow{ // S120
Accept: 18,
Ignore: "",
},
ActionRow{ // S121
Accept: 18,
Ignore: "",
},
ActionRow{ // S122
Accept: 18,
Ignore: "",
},
ActionRow{ // S123
Accept: 18,
Ignore: "",
},
ActionRow{ // S124
Accept: 18,
Ignore: "",
},
ActionRow{ // S125
Accept: 18,
Ignore: "",
},
ActionRow{ // S126
Accept: 5,
Ignore: "",
},
ActionRow{ // S127
Accept: 18,
Ignore: "",
},
ActionRow{ // S128
Accept: 18,
Ignore: "",
},
ActionRow{ // S129
Accept: 18,
Ignore: "",
},
ActionRow{ // S130
Accept: 18,
Ignore: "",
},
ActionRow{ // S131
Accept: 18,
Ignore: "",
},
ActionRow{ // S132
Accept: 18,
Ignore: "",
},
ActionRow{ // S133
Accept: 18,
Ignore: "",
},
ActionRow{ // S134
Accept: 6,
Ignore: "",
},
ActionRow{ // S135
Accept: 18,
Ignore: "",
},
ActionRow{ // S136
Accept: 18,
Ignore: "",
},
ActionRow{ // S137
Accept: 18,
Ignore: "",
},
ActionRow{ // S138
Accept: 18,
Ignore: "",
},
ActionRow{ // S139
Accept: 18,
Ignore: "",
},
ActionRow{ // S140
Accept: 15,
Ignore: "",
},
}

View File

@@ -0,0 +1,300 @@
// Code generated by gocc; DO NOT EDIT.
package lexer
import (
"io/ioutil"
"unicode/utf8"
"github.com/awalterschulze/gographviz/internal/token"
)
const (
NoState = -1
NumStates = 141
NumSymbols = 184
)
type Lexer struct {
src []byte
pos int
line int
column int
}
func NewLexer(src []byte) *Lexer {
lexer := &Lexer{
src: src,
pos: 0,
line: 1,
column: 1,
}
return lexer
}
func NewLexerFile(fpath string) (*Lexer, error) {
src, err := ioutil.ReadFile(fpath)
if err != nil {
return nil, err
}
return NewLexer(src), nil
}
func (l *Lexer) Scan() (tok *token.Token) {
tok = new(token.Token)
if l.pos >= len(l.src) {
tok.Type = token.EOF
tok.Pos.Offset, tok.Pos.Line, tok.Pos.Column = l.pos, l.line, l.column
return
}
start, startLine, startColumn, end := l.pos, l.line, l.column, 0
tok.Type = token.INVALID
state, rune1, size := 0, rune(-1), 0
for state != -1 {
if l.pos >= len(l.src) {
rune1 = -1
} else {
rune1, size = utf8.DecodeRune(l.src[l.pos:])
l.pos += size
}
nextState := -1
if rune1 != -1 {
nextState = TransTab[state](rune1)
}
state = nextState
if state != -1 {
switch rune1 {
case '\n':
l.line++
l.column = 1
case '\r':
l.column = 1
case '\t':
l.column += 4
default:
l.column++
}
switch {
case ActTab[state].Accept != -1:
tok.Type = ActTab[state].Accept
end = l.pos
case ActTab[state].Ignore != "":
start, startLine, startColumn = l.pos, l.line, l.column
state = 0
if start >= len(l.src) {
tok.Type = token.EOF
}
}
} else {
if tok.Type == token.INVALID {
end = l.pos
}
}
}
if end > start {
l.pos = end
tok.Lit = l.src[start:end]
} else {
tok.Lit = []byte{}
}
tok.Pos.Offset, tok.Pos.Line, tok.Pos.Column = start, startLine, startColumn
return
}
func (l *Lexer) Reset() {
l.pos = 0
}
/*
Lexer symbols:
0: 'n'
1: 'o'
2: 'd'
3: 'e'
4: 'N'
5: 'o'
6: 'd'
7: 'e'
8: 'N'
9: 'O'
10: 'D'
11: 'E'
12: 'e'
13: 'd'
14: 'g'
15: 'e'
16: 'E'
17: 'd'
18: 'g'
19: 'e'
20: 'E'
21: 'D'
22: 'G'
23: 'E'
24: 'g'
25: 'r'
26: 'a'
27: 'p'
28: 'h'
29: 'G'
30: 'r'
31: 'a'
32: 'p'
33: 'h'
34: 'G'
35: 'R'
36: 'A'
37: 'P'
38: 'H'
39: 'd'
40: 'i'
41: 'g'
42: 'r'
43: 'a'
44: 'p'
45: 'h'
46: 'D'
47: 'i'
48: 'g'
49: 'r'
50: 'a'
51: 'p'
52: 'h'
53: 'd'
54: 'i'
55: 'G'
56: 'r'
57: 'a'
58: 'p'
59: 'h'
60: 'D'
61: 'i'
62: 'G'
63: 'r'
64: 'a'
65: 'p'
66: 'h'
67: 'D'
68: 'I'
69: 'G'
70: 'R'
71: 'A'
72: 'P'
73: 'H'
74: 's'
75: 'u'
76: 'b'
77: 'g'
78: 'r'
79: 'a'
80: 'p'
81: 'h'
82: 'S'
83: 'u'
84: 'b'
85: 'g'
86: 'r'
87: 'a'
88: 'p'
89: 'h'
90: 's'
91: 'u'
92: 'b'
93: 'G'
94: 'r'
95: 'a'
96: 'p'
97: 'h'
98: 'S'
99: 'u'
100: 'b'
101: 'G'
102: 'r'
103: 'a'
104: 'p'
105: 'h'
106: 'S'
107: 'U'
108: 'B'
109: 'G'
110: 'R'
111: 'A'
112: 'P'
113: 'H'
114: 's'
115: 't'
116: 'r'
117: 'i'
118: 'c'
119: 't'
120: 'S'
121: 't'
122: 'r'
123: 'i'
124: 'c'
125: 't'
126: 'S'
127: 'T'
128: 'R'
129: 'I'
130: 'C'
131: 'T'
132: '{'
133: '}'
134: ';'
135: '='
136: '['
137: ']'
138: ','
139: ':'
140: '-'
141: '>'
142: '-'
143: '-'
144: '_'
145: '-'
146: '.'
147: '-'
148: '.'
149: '\'
150: '"'
151: '\'
152: '"'
153: '"'
154: '='
155: '<'
156: '>'
157: '<'
158: '>'
159: '/'
160: '/'
161: '\n'
162: '#'
163: '\n'
164: '/'
165: '*'
166: '*'
167: '*'
168: '/'
169: ' '
170: '\t'
171: '\r'
172: '\n'
173: \u0001-'!'
174: '#'-'['
175: ']'-\u007f
176: 'a'-'z'
177: 'A'-'Z'
178: '0'-'9'
179: \u0080-\ufffc
180: \ufffe-\U0010ffff
181: \u0001-';'
182: '?'-\u00ff
183: .
*/

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,51 @@
// Code generated by gocc; DO NOT EDIT.
package parser
import (
"fmt"
)
type action interface {
act()
String() string
}
type (
accept bool
shift int // value is next state index
reduce int // value is production index
)
func (this accept) act() {}
func (this shift) act() {}
func (this reduce) act() {}
func (this accept) Equal(that action) bool {
if _, ok := that.(accept); ok {
return true
}
return false
}
func (this reduce) Equal(that action) bool {
that1, ok := that.(reduce)
if !ok {
return false
}
return this == that1
}
func (this shift) Equal(that action) bool {
that1, ok := that.(shift)
if !ok {
return false
}
return this == that1
}
func (this accept) String() string { return "accept(0)" }
func (this shift) String() string { return fmt.Sprintf("shift:%d", this) }
func (this reduce) String() string {
return fmt.Sprintf("reduce:%d(%s)", this, productionsTable[this].String)
}

View File

@@ -0,0 +1,152 @@
// Code generated by gocc; DO NOT EDIT.
package parser
import (
"bytes"
"compress/gzip"
"encoding/gob"
)
type (
actionTable [numStates]actionRow
actionRow struct {
canRecover bool
actions [numSymbols]action
}
)
var actionTab = actionTable{}
func init() {
tab := []struct {
CanRecover bool
Actions []struct {
Index int
Action int
Amount int
}
}{}
data := []byte{
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x9c, 0x97, 0x4f, 0x88, 0x5b, 0x55,
0x1b, 0xc6, 0xcf, 0x7b, 0xe7, 0x7e, 0xd3, 0xf9, 0x66, 0xa6, 0xa5, 0x0c, 0xf3, 0x85, 0x61, 0x18,
0x86, 0x10, 0xc2, 0x10, 0x42, 0x08, 0x21, 0x0c, 0x21, 0xe4, 0x8b, 0x21, 0x8e, 0x65, 0xd0, 0x21,
0x84, 0x10, 0x42, 0x08, 0x31, 0x86, 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4, 0xee, 0xdd, 0x19, 0xa2,
0xff, 0xea, 0x05, 0xd8, 0x67, 0x01, 0xf6, 0x59, 0x80, 0x7d, 0x16, 0x60, 0x9f, 0x99, 0xdf, 0x67,
0xe6, 0xf7, 0x59, 0x61, 0xef, 0x28, 0xde, 0xe5, 0x67, 0x58, 0x37, 0xde, 0xa2, 0x6e, 0x79, 0xff,
0xf1, 0x00, 0xa8, 0xfb, 0xce, 0xb4, 0x28, 0xef, 0xce, 0x9c, 0x07, 0xad, 0x7f, 0xcf, 0xd4, 0x5d,
0x8b, 0x54, 0x2d, 0x52, 0xb5, 0x48, 0xd5, 0x22, 0x55, 0x8b, 0x54, 0x2d, 0xea, 0xa1, 0x45, 0xa8,
0x16, 0x85, 0xd0, 0xa2, 0x10, 0x5a, 0x44, 0x6c, 0x8d, 0xd1, 0xef, 0x9b, 0x39, 0x5e, 0x35, 0x27,
0x4b, 0x18, 0x93, 0x30, 0x26, 0x61, 0xe8, 0x61, 0xe8, 0x61, 0xb0, 0x61, 0x40, 0x61, 0xa3, 0x89,
0xa0, 0x89, 0xa0, 0x89, 0xa0, 0x89, 0xa0, 0x89, 0xa0, 0x89, 0xa0, 0x89, 0x98, 0xc1, 0x94, 0xd0,
0x94, 0xd0, 0x94, 0x18, 0x4c, 0x09, 0x69, 0x09, 0x69, 0x69, 0x62, 0x13, 0x95, 0xce, 0xda, 0x44,
0x25, 0xa5, 0xac, 0x25, 0x3d, 0xab, 0xee, 0x07, 0x4c, 0xa0, 0xfb, 0xa1, 0x1a, 0x0f, 0x6e, 0x49,
0x7b, 0x1c, 0x03, 0x38, 0x46, 0x72, 0x6c, 0xfa, 0x87, 0xf4, 0x0f, 0xe9, 0x1f, 0x9a, 0xd5, 0x4f,
0x11, 0x2d, 0x45, 0xb4, 0x14, 0xd1, 0x52, 0x44, 0x4b, 0x11, 0x2d, 0x35, 0xb9, 0xfa, 0x29, 0x10,
0xe3, 0x02, 0x4a, 0x83, 0x48, 0x83, 0x48, 0x83, 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, 0x77, 0xd9, 0xa3, 0x19, 0xb3, 0xb3, 0x36, 0xc7,
0xec, 0x04, 0x66, 0x4f, 0xd2, 0x3f, 0x01, 0x00, 0x00, 0xff, 0xff, 0xd1, 0x47, 0x5c, 0x26, 0x6b,
0x16, 0x00, 0x00,
}
buf, err := gzip.NewReader(bytes.NewBuffer(data))
if err != nil {
panic(err)
}
dec := gob.NewDecoder(buf)
if err := dec.Decode(&tab); err != nil {
panic(err)
}
for i, row := range tab {
actionTab[i].canRecover = row.CanRecover
for _, a := range row.Actions {
switch a.Action {
case 0:
actionTab[i].actions[a.Index] = accept(true)
case 1:
actionTab[i].actions[a.Index] = reduce(a.Amount)
case 2:
actionTab[i].actions[a.Index] = shift(a.Amount)
}
}
}
}

View File

@@ -0,0 +1,56 @@
// Code generated by gocc; DO NOT EDIT.
package parser
import (
"bytes"
"compress/gzip"
"encoding/gob"
)
const numNTSymbols = 17
type (
gotoTable [numStates]gotoRow
gotoRow [numNTSymbols]int
)
var gotoTab = gotoTable{}
func init() {
tab := [][]int{}
data := []byte{
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xe2, 0xfd, 0xdf, 0xcd, 0xc4, 0xc8,
0xf4, 0xbf, 0x87, 0x81, 0xf1, 0x7f, 0x17, 0x03, 0x03, 0xcf, 0xff, 0x4e, 0x10, 0xaf, 0x8b, 0x81,
0x91, 0x85, 0x81, 0xe1, 0x1f, 0xa7, 0xc6, 0xff, 0x1e, 0x86, 0xff, 0x0d, 0x82, 0x8c, 0x4c, 0x8c,
0xa8, 0x40, 0x90, 0x11, 0x1d, 0x60, 0x88, 0xf0, 0x10, 0xa1, 0x46, 0x4c, 0x90, 0x91, 0x51, 0x41,
0x49, 0x45, 0x8b, 0x91, 0x91, 0x51, 0x83, 0x51, 0xcd, 0x88, 0x51, 0x87, 0x51, 0x8e, 0x08, 0x5d,
0x98, 0x22, 0x36, 0x18, 0x22, 0x0e, 0x82, 0x8c, 0x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d3, 0xc0, 0x06, 0xee, 0x60, 0x13, 0xc1, 0x0c, 0xa0, 0x3f, 0xf4, 0x0a, 0x20,
0x40, 0x00, 0x00, 0x00, 0xff, 0xff, 0x8f, 0xfa, 0xd1, 0x1a, 0x46, 0x09, 0x00, 0x00,
}
buf, err := gzip.NewReader(bytes.NewBuffer(data))
if err != nil {
panic(err)
}
dec := gob.NewDecoder(buf)
if err := dec.Decode(&tab); err != nil {
panic(err)
}
for i := 0; i < numStates; i++ {
for j := 0; j < numNTSymbols; j++ {
gotoTab[i][j] = tab[i][j]
}
}
}

View File

@@ -0,0 +1,72 @@
//Copyright 2013 GoGraphviz Authors
//
//Licensed under the Apache License, Version 2.0 (the "License");
//you may not use this file except in compliance with the License.
//You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
//Unless required by applicable law or agreed to in writing, software
//distributed under the License is distributed on an "AS IS" BASIS,
//WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//See the License for the specific language governing permissions and
//limitations under the License.
//A parser for the DOT grammar.
package parser
import (
"fmt"
"io"
"io/ioutil"
"os"
"github.com/awalterschulze/gographviz/ast"
"github.com/awalterschulze/gographviz/internal/lexer"
)
//Parses a DOT string and outputs the
//abstract syntax tree representing the graph.
func ParseString(dotString string) (*ast.Graph, error) {
return ParseBytes([]byte(dotString))
}
//Parses the bytes representing a DOT string
//and outputs the abstract syntax tree representing the graph.
func ParseBytes(dotBytes []byte) (*ast.Graph, error) {
lex := lexer.NewLexer(dotBytes)
parser := NewParser()
st, err := parser.Parse(lex)
if err != nil {
return nil, err
}
g, ok := st.(*ast.Graph)
if !ok {
panic(fmt.Sprintf("Parser did not return an *ast.Graph, but rather a %T", st))
}
return g, nil
}
//Parses a reader which contains a DOT string
//and outputs the abstract syntax tree representing the graph.
func Parse(r io.Reader) (*ast.Graph, error) {
bytes, err := ioutil.ReadAll(r)
if err != nil {
return nil, err
}
return ParseBytes(bytes)
}
//Parses a file which contains a DOT string
//and outputs the abstract syntax tree representing the graph.
func ParseFile(filename string) (*ast.Graph, error) {
f, err := os.Open(filename)
if err != nil {
return nil, err
}
g, err := Parse(f)
if err := f.Close(); err != nil {
return nil, err
}
return g, err
}

View File

@@ -0,0 +1,216 @@
// Code generated by gocc; DO NOT EDIT.
package parser
import (
"bytes"
"fmt"
parseError "github.com/awalterschulze/gographviz/internal/errors"
"github.com/awalterschulze/gographviz/internal/token"
)
const (
numProductions = 60
numStates = 128
numSymbols = 36
)
// Stack
type stack struct {
state []int
attrib []Attrib
}
const iNITIAL_STACK_SIZE = 100
func newStack() *stack {
return &stack{
state: make([]int, 0, iNITIAL_STACK_SIZE),
attrib: make([]Attrib, 0, iNITIAL_STACK_SIZE),
}
}
func (s *stack) reset() {
s.state = s.state[:0]
s.attrib = s.attrib[:0]
}
func (s *stack) push(state int, a Attrib) {
s.state = append(s.state, state)
s.attrib = append(s.attrib, a)
}
func (s *stack) top() int {
return s.state[len(s.state)-1]
}
func (s *stack) peek(pos int) int {
return s.state[pos]
}
func (s *stack) topIndex() int {
return len(s.state) - 1
}
func (s *stack) popN(items int) []Attrib {
lo, hi := len(s.state)-items, len(s.state)
attrib := s.attrib[lo:hi]
s.state = s.state[:lo]
s.attrib = s.attrib[:lo]
return attrib
}
func (s *stack) String() string {
w := new(bytes.Buffer)
fmt.Fprintf(w, "stack:\n")
for i, st := range s.state {
fmt.Fprintf(w, "\t%d: %d , ", i, st)
if s.attrib[i] == nil {
fmt.Fprintf(w, "nil")
} else {
switch attr := s.attrib[i].(type) {
case *token.Token:
fmt.Fprintf(w, "%s", attr.Lit)
default:
fmt.Fprintf(w, "%v", attr)
}
}
fmt.Fprintf(w, "\n")
}
return w.String()
}
// Parser
type Parser struct {
stack *stack
nextToken *token.Token
pos int
}
type Scanner interface {
Scan() (tok *token.Token)
}
func NewParser() *Parser {
p := &Parser{stack: newStack()}
p.Reset()
return p
}
func (p *Parser) Reset() {
p.stack.reset()
p.stack.push(0, nil)
}
func (p *Parser) Error(err error, scanner Scanner) (recovered bool, errorAttrib *parseError.Error) {
errorAttrib = &parseError.Error{
Err: err,
ErrorToken: p.nextToken,
ErrorSymbols: p.popNonRecoveryStates(),
ExpectedTokens: make([]string, 0, 8),
}
for t, action := range actionTab[p.stack.top()].actions {
if action != nil {
errorAttrib.ExpectedTokens = append(errorAttrib.ExpectedTokens, token.TokMap.Id(token.Type(t)))
}
}
if action := actionTab[p.stack.top()].actions[token.TokMap.Type("error")]; action != nil {
p.stack.push(int(action.(shift)), errorAttrib) // action can only be shift
} else {
return
}
if action := actionTab[p.stack.top()].actions[p.nextToken.Type]; action != nil {
recovered = true
}
for !recovered && p.nextToken.Type != token.EOF {
p.nextToken = scanner.Scan()
if action := actionTab[p.stack.top()].actions[p.nextToken.Type]; action != nil {
recovered = true
}
}
return
}
func (p *Parser) popNonRecoveryStates() (removedAttribs []parseError.ErrorSymbol) {
if rs, ok := p.firstRecoveryState(); ok {
errorSymbols := p.stack.popN(p.stack.topIndex() - rs)
removedAttribs = make([]parseError.ErrorSymbol, len(errorSymbols))
for i, e := range errorSymbols {
removedAttribs[i] = e
}
} else {
removedAttribs = []parseError.ErrorSymbol{}
}
return
}
// recoveryState points to the highest state on the stack, which can recover
func (p *Parser) firstRecoveryState() (recoveryState int, canRecover bool) {
recoveryState, canRecover = p.stack.topIndex(), actionTab[p.stack.top()].canRecover
for recoveryState > 0 && !canRecover {
recoveryState--
canRecover = actionTab[p.stack.peek(recoveryState)].canRecover
}
return
}
func (p *Parser) newError(err error) error {
e := &parseError.Error{
Err: err,
StackTop: p.stack.top(),
ErrorToken: p.nextToken,
}
actRow := actionTab[p.stack.top()]
for i, t := range actRow.actions {
if t != nil {
e.ExpectedTokens = append(e.ExpectedTokens, token.TokMap.Id(token.Type(i)))
}
}
return e
}
func (p *Parser) Parse(scanner Scanner) (res interface{}, err error) {
p.Reset()
p.nextToken = scanner.Scan()
for acc := false; !acc; {
action := actionTab[p.stack.top()].actions[p.nextToken.Type]
if action == nil {
if recovered, errAttrib := p.Error(nil, scanner); !recovered {
p.nextToken = errAttrib.ErrorToken
return nil, p.newError(nil)
}
if action = actionTab[p.stack.top()].actions[p.nextToken.Type]; action == nil {
panic("Error recovery led to invalid action")
}
}
switch act := action.(type) {
case accept:
res = p.stack.popN(1)[0]
acc = true
case shift:
p.stack.push(int(act), p.nextToken)
p.nextToken = scanner.Scan()
case reduce:
prod := productionsTable[int(act)]
attrib, err := prod.ReduceFunc(p.stack.popN(prod.NumSymbols))
if err != nil {
return nil, p.newError(err)
} else {
p.stack.push(gotoTab[p.stack.top()][prod.NTType], attrib)
}
default:
panic("unknown action: " + action.String())
}
}
return res, nil
}

View File

@@ -0,0 +1,623 @@
// Code generated by gocc; DO NOT EDIT.
package parser
import "github.com/awalterschulze/gographviz/ast"
type (
//TODO: change type and variable names to be consistent with other tables
ProdTab [numProductions]ProdTabEntry
ProdTabEntry struct {
String string
Id string
NTType int
Index int
NumSymbols int
ReduceFunc func([]Attrib) (Attrib, error)
}
Attrib interface {
}
)
var productionsTable = ProdTab{
ProdTabEntry{
String: `S' : DotGraph << >>`,
Id: "S'",
NTType: 0,
Index: 0,
NumSymbols: 1,
ReduceFunc: func(X []Attrib) (Attrib, error) {
return X[0], nil
},
},
ProdTabEntry{
String: `DotGraph : graphx "{" "}" << ast.NewGraph(ast.GRAPH, ast.FALSE, nil, nil) >>`,
Id: "DotGraph",
NTType: 1,
Index: 1,
NumSymbols: 3,
ReduceFunc: func(X []Attrib) (Attrib, error) {
return ast.NewGraph(ast.GRAPH, ast.FALSE, nil, nil)
},
},
ProdTabEntry{
String: `DotGraph : strict graphx "{" "}" << ast.NewGraph(ast.GRAPH, ast.TRUE, nil, nil) >>`,
Id: "DotGraph",
NTType: 1,
Index: 2,
NumSymbols: 4,
ReduceFunc: func(X []Attrib) (Attrib, error) {
return ast.NewGraph(ast.GRAPH, ast.TRUE, nil, nil)
},
},
ProdTabEntry{
String: `DotGraph : graphx Id "{" "}" << ast.NewGraph(ast.GRAPH, ast.FALSE, X[1], nil) >>`,
Id: "DotGraph",
NTType: 1,
Index: 3,
NumSymbols: 4,
ReduceFunc: func(X []Attrib) (Attrib, error) {
return ast.NewGraph(ast.GRAPH, ast.FALSE, X[1], nil)
},
},
ProdTabEntry{
String: `DotGraph : strict graphx Id "{" "}" << ast.NewGraph(ast.GRAPH, ast.TRUE, X[2], nil) >>`,
Id: "DotGraph",
NTType: 1,
Index: 4,
NumSymbols: 5,
ReduceFunc: func(X []Attrib) (Attrib, error) {
return ast.NewGraph(ast.GRAPH, ast.TRUE, X[2], nil)
},
},
ProdTabEntry{
String: `DotGraph : graphx "{" StmtList "}" << ast.NewGraph(ast.GRAPH, ast.FALSE, nil, X[2]) >>`,
Id: "DotGraph",
NTType: 1,
Index: 5,
NumSymbols: 4,
ReduceFunc: func(X []Attrib) (Attrib, error) {
return ast.NewGraph(ast.GRAPH, ast.FALSE, nil, X[2])
},
},
ProdTabEntry{
String: `DotGraph : graphx Id "{" StmtList "}" << ast.NewGraph(ast.GRAPH, ast.FALSE, X[1], X[3]) >>`,
Id: "DotGraph",
NTType: 1,
Index: 6,
NumSymbols: 5,
ReduceFunc: func(X []Attrib) (Attrib, error) {
return ast.NewGraph(ast.GRAPH, ast.FALSE, X[1], X[3])
},
},
ProdTabEntry{
String: `DotGraph : strict graphx "{" StmtList "}" << ast.NewGraph(ast.GRAPH, ast.TRUE, nil, X[3]) >>`,
Id: "DotGraph",
NTType: 1,
Index: 7,
NumSymbols: 5,
ReduceFunc: func(X []Attrib) (Attrib, error) {
return ast.NewGraph(ast.GRAPH, ast.TRUE, nil, X[3])
},
},
ProdTabEntry{
String: `DotGraph : strict graphx Id "{" StmtList "}" << ast.NewGraph(ast.GRAPH, ast.TRUE, X[2], X[4]) >>`,
Id: "DotGraph",
NTType: 1,
Index: 8,
NumSymbols: 6,
ReduceFunc: func(X []Attrib) (Attrib, error) {
return ast.NewGraph(ast.GRAPH, ast.TRUE, X[2], X[4])
},
},
ProdTabEntry{
String: `DotGraph : digraph "{" "}" << ast.NewGraph(ast.DIGRAPH, ast.FALSE, nil, nil) >>`,
Id: "DotGraph",
NTType: 1,
Index: 9,
NumSymbols: 3,
ReduceFunc: func(X []Attrib) (Attrib, error) {
return ast.NewGraph(ast.DIGRAPH, ast.FALSE, nil, nil)
},
},
ProdTabEntry{
String: `DotGraph : strict digraph "{" "}" << ast.NewGraph(ast.DIGRAPH, ast.TRUE, nil, nil) >>`,
Id: "DotGraph",
NTType: 1,
Index: 10,
NumSymbols: 4,
ReduceFunc: func(X []Attrib) (Attrib, error) {
return ast.NewGraph(ast.DIGRAPH, ast.TRUE, nil, nil)
},
},
ProdTabEntry{
String: `DotGraph : digraph Id "{" "}" << ast.NewGraph(ast.DIGRAPH, ast.FALSE, X[1], nil) >>`,
Id: "DotGraph",
NTType: 1,
Index: 11,
NumSymbols: 4,
ReduceFunc: func(X []Attrib) (Attrib, error) {
return ast.NewGraph(ast.DIGRAPH, ast.FALSE, X[1], nil)
},
},
ProdTabEntry{
String: `DotGraph : strict digraph Id "{" "}" << ast.NewGraph(ast.DIGRAPH, ast.TRUE, X[2], nil) >>`,
Id: "DotGraph",
NTType: 1,
Index: 12,
NumSymbols: 5,
ReduceFunc: func(X []Attrib) (Attrib, error) {
return ast.NewGraph(ast.DIGRAPH, ast.TRUE, X[2], nil)
},
},
ProdTabEntry{
String: `DotGraph : digraph "{" StmtList "}" << ast.NewGraph(ast.DIGRAPH, ast.FALSE, nil, X[2]) >>`,
Id: "DotGraph",
NTType: 1,
Index: 13,
NumSymbols: 4,
ReduceFunc: func(X []Attrib) (Attrib, error) {
return ast.NewGraph(ast.DIGRAPH, ast.FALSE, nil, X[2])
},
},
ProdTabEntry{
String: `DotGraph : digraph Id "{" StmtList "}" << ast.NewGraph(ast.DIGRAPH, ast.FALSE, X[1], X[3]) >>`,
Id: "DotGraph",
NTType: 1,
Index: 14,
NumSymbols: 5,
ReduceFunc: func(X []Attrib) (Attrib, error) {
return ast.NewGraph(ast.DIGRAPH, ast.FALSE, X[1], X[3])
},
},
ProdTabEntry{
String: `DotGraph : strict digraph "{" StmtList "}" << ast.NewGraph(ast.DIGRAPH, ast.TRUE, nil, X[3]) >>`,
Id: "DotGraph",
NTType: 1,
Index: 15,
NumSymbols: 5,
ReduceFunc: func(X []Attrib) (Attrib, error) {
return ast.NewGraph(ast.DIGRAPH, ast.TRUE, nil, X[3])
},
},
ProdTabEntry{
String: `DotGraph : strict digraph Id "{" StmtList "}" << ast.NewGraph(ast.DIGRAPH, ast.TRUE, X[2], X[4]) >>`,
Id: "DotGraph",
NTType: 1,
Index: 16,
NumSymbols: 6,
ReduceFunc: func(X []Attrib) (Attrib, error) {
return ast.NewGraph(ast.DIGRAPH, ast.TRUE, X[2], X[4])
},
},
ProdTabEntry{
String: `StmtList : Stmt1 << ast.NewStmtList(X[0]) >>`,
Id: "StmtList",
NTType: 2,
Index: 17,
NumSymbols: 1,
ReduceFunc: func(X []Attrib) (Attrib, error) {
return ast.NewStmtList(X[0])
},
},
ProdTabEntry{
String: `StmtList : StmtList Stmt1 << ast.AppendStmtList(X[0], X[1]) >>`,
Id: "StmtList",
NTType: 2,
Index: 18,
NumSymbols: 2,
ReduceFunc: func(X []Attrib) (Attrib, error) {
return ast.AppendStmtList(X[0], X[1])
},
},
ProdTabEntry{
String: `Stmt1 : Stmt << X[0], nil >>`,
Id: "Stmt1",
NTType: 3,
Index: 19,
NumSymbols: 1,
ReduceFunc: func(X []Attrib) (Attrib, error) {
return X[0], nil
},
},
ProdTabEntry{
String: `Stmt1 : Stmt ";" << X[0], nil >>`,
Id: "Stmt1",
NTType: 3,
Index: 20,
NumSymbols: 2,
ReduceFunc: func(X []Attrib) (Attrib, error) {
return X[0], nil
},
},
ProdTabEntry{
String: `Stmt : Id "=" Id << ast.NewAttr(X[0], X[2]) >>`,
Id: "Stmt",
NTType: 4,
Index: 21,
NumSymbols: 3,
ReduceFunc: func(X []Attrib) (Attrib, error) {
return ast.NewAttr(X[0], X[2])
},
},
ProdTabEntry{
String: `Stmt : NodeStmt << X[0], nil >>`,
Id: "Stmt",
NTType: 4,
Index: 22,
NumSymbols: 1,
ReduceFunc: func(X []Attrib) (Attrib, error) {
return X[0], nil
},
},
ProdTabEntry{
String: `Stmt : EdgeStmt << X[0], nil >>`,
Id: "Stmt",
NTType: 4,
Index: 23,
NumSymbols: 1,
ReduceFunc: func(X []Attrib) (Attrib, error) {
return X[0], nil
},
},
ProdTabEntry{
String: `Stmt : AttrStmt << X[0], nil >>`,
Id: "Stmt",
NTType: 4,
Index: 24,
NumSymbols: 1,
ReduceFunc: func(X []Attrib) (Attrib, error) {
return X[0], nil
},
},
ProdTabEntry{
String: `Stmt : SubGraphStmt << X[0], nil >>`,
Id: "Stmt",
NTType: 4,
Index: 25,
NumSymbols: 1,
ReduceFunc: func(X []Attrib) (Attrib, error) {
return X[0], nil
},
},
ProdTabEntry{
String: `AttrStmt : graphx AttrList << ast.NewGraphAttrs(X[1]) >>`,
Id: "AttrStmt",
NTType: 5,
Index: 26,
NumSymbols: 2,
ReduceFunc: func(X []Attrib) (Attrib, error) {
return ast.NewGraphAttrs(X[1])
},
},
ProdTabEntry{
String: `AttrStmt : node AttrList << ast.NewNodeAttrs(X[1]) >>`,
Id: "AttrStmt",
NTType: 5,
Index: 27,
NumSymbols: 2,
ReduceFunc: func(X []Attrib) (Attrib, error) {
return ast.NewNodeAttrs(X[1])
},
},
ProdTabEntry{
String: `AttrStmt : edge AttrList << ast.NewEdgeAttrs(X[1]) >>`,
Id: "AttrStmt",
NTType: 5,
Index: 28,
NumSymbols: 2,
ReduceFunc: func(X []Attrib) (Attrib, error) {
return ast.NewEdgeAttrs(X[1])
},
},
ProdTabEntry{
String: `AttrList : "[" "]" << ast.NewAttrList(nil) >>`,
Id: "AttrList",
NTType: 6,
Index: 29,
NumSymbols: 2,
ReduceFunc: func(X []Attrib) (Attrib, error) {
return ast.NewAttrList(nil)
},
},
ProdTabEntry{
String: `AttrList : "[" AList "]" << ast.NewAttrList(X[1]) >>`,
Id: "AttrList",
NTType: 6,
Index: 30,
NumSymbols: 3,
ReduceFunc: func(X []Attrib) (Attrib, error) {
return ast.NewAttrList(X[1])
},
},
ProdTabEntry{
String: `AttrList : AttrList "[" "]" << ast.AppendAttrList(X[0], nil) >>`,
Id: "AttrList",
NTType: 6,
Index: 31,
NumSymbols: 3,
ReduceFunc: func(X []Attrib) (Attrib, error) {
return ast.AppendAttrList(X[0], nil)
},
},
ProdTabEntry{
String: `AttrList : AttrList "[" AList "]" << ast.AppendAttrList(X[0], X[2]) >>`,
Id: "AttrList",
NTType: 6,
Index: 32,
NumSymbols: 4,
ReduceFunc: func(X []Attrib) (Attrib, error) {
return ast.AppendAttrList(X[0], X[2])
},
},
ProdTabEntry{
String: `AList : Attr << ast.NewAList(X[0]) >>`,
Id: "AList",
NTType: 7,
Index: 33,
NumSymbols: 1,
ReduceFunc: func(X []Attrib) (Attrib, error) {
return ast.NewAList(X[0])
},
},
ProdTabEntry{
String: `AList : AList Attr << ast.AppendAList(X[0], X[1]) >>`,
Id: "AList",
NTType: 7,
Index: 34,
NumSymbols: 2,
ReduceFunc: func(X []Attrib) (Attrib, error) {
return ast.AppendAList(X[0], X[1])
},
},
ProdTabEntry{
String: `AList : AList "," Attr << ast.AppendAList(X[0], X[2]) >>`,
Id: "AList",
NTType: 7,
Index: 35,
NumSymbols: 3,
ReduceFunc: func(X []Attrib) (Attrib, error) {
return ast.AppendAList(X[0], X[2])
},
},
ProdTabEntry{
String: `Attr : Id << ast.NewAttr(X[0], nil) >>`,
Id: "Attr",
NTType: 8,
Index: 36,
NumSymbols: 1,
ReduceFunc: func(X []Attrib) (Attrib, error) {
return ast.NewAttr(X[0], nil)
},
},
ProdTabEntry{
String: `Attr : Id "=" Id << ast.NewAttr(X[0], X[2]) >>`,
Id: "Attr",
NTType: 8,
Index: 37,
NumSymbols: 3,
ReduceFunc: func(X []Attrib) (Attrib, error) {
return ast.NewAttr(X[0], X[2])
},
},
ProdTabEntry{
String: `EdgeStmt : NodeId EdgeRHS << ast.NewEdgeStmt(X[0], X[1], nil) >>`,
Id: "EdgeStmt",
NTType: 9,
Index: 38,
NumSymbols: 2,
ReduceFunc: func(X []Attrib) (Attrib, error) {
return ast.NewEdgeStmt(X[0], X[1], nil)
},
},
ProdTabEntry{
String: `EdgeStmt : NodeId EdgeRHS AttrList << ast.NewEdgeStmt(X[0], X[1], X[2]) >>`,
Id: "EdgeStmt",
NTType: 9,
Index: 39,
NumSymbols: 3,
ReduceFunc: func(X []Attrib) (Attrib, error) {
return ast.NewEdgeStmt(X[0], X[1], X[2])
},
},
ProdTabEntry{
String: `EdgeStmt : SubGraphStmt EdgeRHS << ast.NewEdgeStmt(X[0], X[1], nil) >>`,
Id: "EdgeStmt",
NTType: 9,
Index: 40,
NumSymbols: 2,
ReduceFunc: func(X []Attrib) (Attrib, error) {
return ast.NewEdgeStmt(X[0], X[1], nil)
},
},
ProdTabEntry{
String: `EdgeStmt : SubGraphStmt EdgeRHS AttrList << ast.NewEdgeStmt(X[0], X[1], X[2]) >>`,
Id: "EdgeStmt",
NTType: 9,
Index: 41,
NumSymbols: 3,
ReduceFunc: func(X []Attrib) (Attrib, error) {
return ast.NewEdgeStmt(X[0], X[1], X[2])
},
},
ProdTabEntry{
String: `EdgeRHS : EdgeOp NodeId << ast.NewEdgeRHS(X[0], X[1]) >>`,
Id: "EdgeRHS",
NTType: 10,
Index: 42,
NumSymbols: 2,
ReduceFunc: func(X []Attrib) (Attrib, error) {
return ast.NewEdgeRHS(X[0], X[1])
},
},
ProdTabEntry{
String: `EdgeRHS : EdgeOp SubGraphStmt << ast.NewEdgeRHS(X[0], X[1]) >>`,
Id: "EdgeRHS",
NTType: 10,
Index: 43,
NumSymbols: 2,
ReduceFunc: func(X []Attrib) (Attrib, error) {
return ast.NewEdgeRHS(X[0], X[1])
},
},
ProdTabEntry{
String: `EdgeRHS : EdgeRHS EdgeOp NodeId << ast.AppendEdgeRHS(X[0], X[1], X[2]) >>`,
Id: "EdgeRHS",
NTType: 10,
Index: 44,
NumSymbols: 3,
ReduceFunc: func(X []Attrib) (Attrib, error) {
return ast.AppendEdgeRHS(X[0], X[1], X[2])
},
},
ProdTabEntry{
String: `EdgeRHS : EdgeRHS EdgeOp SubGraphStmt << ast.AppendEdgeRHS(X[0], X[1], X[2]) >>`,
Id: "EdgeRHS",
NTType: 10,
Index: 45,
NumSymbols: 3,
ReduceFunc: func(X []Attrib) (Attrib, error) {
return ast.AppendEdgeRHS(X[0], X[1], X[2])
},
},
ProdTabEntry{
String: `NodeStmt : NodeId << ast.NewNodeStmt(X[0], nil) >>`,
Id: "NodeStmt",
NTType: 11,
Index: 46,
NumSymbols: 1,
ReduceFunc: func(X []Attrib) (Attrib, error) {
return ast.NewNodeStmt(X[0], nil)
},
},
ProdTabEntry{
String: `NodeStmt : NodeId AttrList << ast.NewNodeStmt(X[0], X[1]) >>`,
Id: "NodeStmt",
NTType: 11,
Index: 47,
NumSymbols: 2,
ReduceFunc: func(X []Attrib) (Attrib, error) {
return ast.NewNodeStmt(X[0], X[1])
},
},
ProdTabEntry{
String: `NodeId : Id << ast.NewNodeID(X[0], nil) >>`,
Id: "NodeId",
NTType: 12,
Index: 48,
NumSymbols: 1,
ReduceFunc: func(X []Attrib) (Attrib, error) {
return ast.NewNodeID(X[0], nil)
},
},
ProdTabEntry{
String: `NodeId : Id Port << ast.NewNodeID(X[0], X[1]) >>`,
Id: "NodeId",
NTType: 12,
Index: 49,
NumSymbols: 2,
ReduceFunc: func(X []Attrib) (Attrib, error) {
return ast.NewNodeID(X[0], X[1])
},
},
ProdTabEntry{
String: `Port : ":" Id << ast.NewPort(X[1], nil), nil >>`,
Id: "Port",
NTType: 13,
Index: 50,
NumSymbols: 2,
ReduceFunc: func(X []Attrib) (Attrib, error) {
return ast.NewPort(X[1], nil), nil
},
},
ProdTabEntry{
String: `Port : ":" Id ":" Id << ast.NewPort(X[1], X[3]), nil >>`,
Id: "Port",
NTType: 13,
Index: 51,
NumSymbols: 4,
ReduceFunc: func(X []Attrib) (Attrib, error) {
return ast.NewPort(X[1], X[3]), nil
},
},
ProdTabEntry{
String: `SubGraphStmt : "{" StmtList "}" << ast.NewSubGraph(nil, X[1]) >>`,
Id: "SubGraphStmt",
NTType: 14,
Index: 52,
NumSymbols: 3,
ReduceFunc: func(X []Attrib) (Attrib, error) {
return ast.NewSubGraph(nil, X[1])
},
},
ProdTabEntry{
String: `SubGraphStmt : subgraph "{" StmtList "}" << ast.NewSubGraph(nil, X[2]) >>`,
Id: "SubGraphStmt",
NTType: 14,
Index: 53,
NumSymbols: 4,
ReduceFunc: func(X []Attrib) (Attrib, error) {
return ast.NewSubGraph(nil, X[2])
},
},
ProdTabEntry{
String: `SubGraphStmt : subgraph Id "{" StmtList "}" << ast.NewSubGraph(X[1], X[3]) >>`,
Id: "SubGraphStmt",
NTType: 14,
Index: 54,
NumSymbols: 5,
ReduceFunc: func(X []Attrib) (Attrib, error) {
return ast.NewSubGraph(X[1], X[3])
},
},
ProdTabEntry{
String: `SubGraphStmt : subgraph "{" "}" << ast.NewSubGraph(nil, nil) >>`,
Id: "SubGraphStmt",
NTType: 14,
Index: 55,
NumSymbols: 3,
ReduceFunc: func(X []Attrib) (Attrib, error) {
return ast.NewSubGraph(nil, nil)
},
},
ProdTabEntry{
String: `SubGraphStmt : subgraph Id "{" "}" << ast.NewSubGraph(X[1], nil) >>`,
Id: "SubGraphStmt",
NTType: 14,
Index: 56,
NumSymbols: 4,
ReduceFunc: func(X []Attrib) (Attrib, error) {
return ast.NewSubGraph(X[1], nil)
},
},
ProdTabEntry{
String: `EdgeOp : "->" << ast.DIRECTED, nil >>`,
Id: "EdgeOp",
NTType: 15,
Index: 57,
NumSymbols: 1,
ReduceFunc: func(X []Attrib) (Attrib, error) {
return ast.DIRECTED, nil
},
},
ProdTabEntry{
String: `EdgeOp : "--" << ast.UNDIRECTED, nil >>`,
Id: "EdgeOp",
NTType: 15,
Index: 58,
NumSymbols: 1,
ReduceFunc: func(X []Attrib) (Attrib, error) {
return ast.UNDIRECTED, nil
},
},
ProdTabEntry{
String: `Id : id << ast.NewID(X[0]) >>`,
Id: "Id",
NTType: 16,
Index: 59,
NumSymbols: 1,
ReduceFunc: func(X []Attrib) (Attrib, error) {
return ast.NewID(X[0])
},
},
}

View File

@@ -0,0 +1,104 @@
// Code generated by gocc; DO NOT EDIT.
package token
import (
"fmt"
)
type Token struct {
Type
Lit []byte
Pos
}
type Type int
const (
INVALID Type = iota
EOF
)
type Pos struct {
Offset int
Line int
Column int
}
func (p Pos) String() string {
return fmt.Sprintf("Pos(offset=%d, line=%d, column=%d)", p.Offset, p.Line, p.Column)
}
type TokenMap struct {
typeMap []string
idMap map[string]Type
}
func (m TokenMap) Id(tok Type) string {
if int(tok) < len(m.typeMap) {
return m.typeMap[tok]
}
return "unknown"
}
func (m TokenMap) Type(tok string) Type {
if typ, exist := m.idMap[tok]; exist {
return typ
}
return INVALID
}
func (m TokenMap) TokenString(tok *Token) string {
//TODO: refactor to print pos & token string properly
return fmt.Sprintf("%s(%d,%s)", m.Id(tok.Type), tok.Type, tok.Lit)
}
func (m TokenMap) StringType(typ Type) string {
return fmt.Sprintf("%s(%d)", m.Id(typ), typ)
}
var TokMap = TokenMap{
typeMap: []string{
"INVALID",
"$",
"graphx",
"{",
"}",
"strict",
"digraph",
";",
"=",
"node",
"edge",
"[",
"]",
",",
":",
"subgraph",
"->",
"--",
"id",
},
idMap: map[string]Type{
"INVALID": 0,
"$": 1,
"graphx": 2,
"{": 3,
"}": 4,
"strict": 5,
"digraph": 6,
";": 7,
"=": 8,
"node": 9,
"edge": 10,
"[": 11,
"]": 12,
",": 13,
":": 14,
"subgraph": 15,
"->": 16,
"--": 17,
"id": 18,
},
}