Import upstream version 2.0.3+git20210715.1.148e697
Debian Janitor
2 years ago
0 | name: build | |
1 | ||
2 | on: [push, pull_request] | |
3 | ||
4 | jobs: | |
5 | build: | |
6 | runs-on: ubuntu-latest | |
7 | env: | |
8 | working-directory: ./src/github.com/awalterschulze/gographviz | |
9 | ||
10 | steps: | |
11 | - name: Set GOPATH | |
12 | run: | | |
13 | echo "GOPATH=$(dirname $GITHUB_WORKSPACE)/gographviz" >> $GITHUB_ENV | |
14 | echo "$(dirname $GITHUB_WORKSPACE)/gographviz/bin" >> $GITHUB_PATH | |
15 | shell: bash | |
16 | ||
17 | - name: Setup Go | |
18 | uses: actions/setup-go@v2 | |
19 | with: | |
20 | go-version: '1.14' | |
21 | ||
22 | - name: Checkout | |
23 | uses: actions/checkout@v2 | |
24 | with: | |
25 | fetch-depth: 1 | |
26 | path: src/github.com/awalterschulze/gographviz | |
27 | ||
28 | - name: Install dependencies | |
29 | run: make dependencies | |
30 | working-directory: ${{env.working-directory}} | |
31 | ||
32 | - name: Run regenerate | |
33 | run: make regenerate | |
34 | working-directory: ${{env.working-directory}} | |
35 | ||
36 | - name: Run build | |
37 | run: make build | |
38 | working-directory: ${{env.working-directory}} | |
39 | ||
40 | - name: Run checkers | |
41 | run: make checkers | |
42 | working-directory: ${{env.working-directory}} | |
43 | ||
44 | - name: Run testing | |
45 | run: make test | |
46 | working-directory: ${{env.working-directory}} |
0 | before_install: | |
1 | - ./install-godeps.sh | |
2 | ||
3 | script: | |
4 | - make travis | |
5 | ||
6 | language: go | |
7 | ||
8 | go: | |
9 | - 1.x |
0 | regenerate: | |
0 | .PHONY: help regenerate test dependencies build checkers action | |
1 | ||
2 | # Prefer tools that we've installed | |
3 | export PATH := $(HOME)/go/bin:$(PATH) | |
4 | ||
5 | help: | |
6 | @grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' | |
7 | ||
8 | regenerate: ## Re-generate lexers and parsers and pass through goimports | |
9 | go get github.com/goccmack/gocc | |
1 | 10 | go install github.com/goccmack/gocc |
2 | gocc -zip -o ./internal/ dot.bnf | |
11 | gocc -zip -o ./internal/ dot.bnf | |
3 | 12 | find . -type f -name '*.go' | xargs goimports -w |
4 | 13 | |
5 | test: | |
14 | test: ## Perform package tests | |
6 | 15 | go test ./... |
7 | 16 | |
8 | travis: | |
9 | make regenerate | |
10 | go build ./... | |
11 | go test ./... | |
17 | dependencies: ## Grab necessary dependencies for checkers | |
18 | go version | |
19 | go get golang.org/x/tools/cmd/goimports | |
20 | go get github.com/kisielk/errcheck | |
21 | go get -u golang.org/x/lint/golint | |
22 | ||
23 | build: ## Perform build process | |
24 | go build . | |
25 | ||
26 | checkers: ## Run all checkers (errcheck, gofmt and golint) | |
12 | 27 | errcheck -ignore 'fmt:[FS]?[Pp]rint*' ./... |
13 | 28 | gofmt -l -s -w . |
14 | 29 | golint -set_exit_status |
15 | 30 | git diff --exit-code |
31 | ||
32 | action: dependencies regenerate build test checkers ## Run steps of github action |
17 | 17 | |
18 | 18 | ### Documentation ### |
19 | 19 | |
20 | The [godoc](https://godoc.org/github.com/awalterschulze/gographviz) includes some more examples. | |
20 | - The [godoc](https://godoc.org/github.com/awalterschulze/gographviz) includes some more examples. | |
21 | - [How to implement an anonymous subgraph](https://github.com/awalterschulze/gographviz/issues/59) | |
21 | 22 | |
22 | 23 | ### Installation ### |
23 | 24 | go get github.com/awalterschulze/gographviz |
24 | 25 | |
25 | ### Tests ### | |
26 | ### Build and Tests ### | |
26 | 27 | |
27 | [![Build Status](https://travis-ci.org/awalterschulze/gographviz.svg?branch=master)](https://travis-ci.org/awalterschulze/gographviz) | |
28 | [![Build Status](https://github.com/awalterschulze/gographviz/workflows/build/badge.svg)](https://github.com/awalterschulze/gographviz/actions) | |
29 | ||
28 | 30 | |
29 | 31 | ### Users ### |
30 | 32 | |
33 | 35 | - [imagemonkey](https://imagemonkey.io/graph?editor=true) - Let's create our own image dataset |
34 | 36 | - [depviz](https://github.com/moul/depviz) - GitHub dependency visualizer (auto-roadmap) |
35 | 37 | - [kustomize-graph](https://github.com/jpreese/kustomize-graph) - A tool to visualize Kustomize dependencies |
38 | - [inframap](https://github.com/cycloidio/inframap) - Read your tfstate or HCL to generate a graph specific for each Terraform provider | |
39 | - [Antrea Traceflow](https://github.com/vmware-tanzu/antrea/blob/master/docs/traceflow-guide.md) supports using Traceflow for network diagnosis for Antrea, a Kubernetes networking solution intended to be Kubernetes native | |
36 | 40 | |
37 | 41 | ### Mentions ### |
38 | 42 |
103 | 103 | func TestString(t *testing.T) { |
104 | 104 | anal(t, |
105 | 105 | `digraph finite_state { rankdir = "LR" }`) |
106 | } | |
107 | ||
108 | func TestAttrImgPos(t *testing.T) { | |
109 | anal(t, | |
110 | "digraph finite_state { imagepos = tc }") | |
106 | 111 | } |
107 | 112 | |
108 | 113 | func TestAttrList(t *testing.T) { |
111 | 111 | } |
112 | 112 | s += this.Type.String() + " " + this.ID.String() + " {\n" |
113 | 113 | if this.StmtList != nil { |
114 | s += this.StmtList.String() | |
114 | s += this.StmtList.indentString("\t") | |
115 | 115 | } |
116 | 116 | s += "\n}\n" |
117 | 117 | return s |
142 | 142 | } |
143 | 143 | |
144 | 144 | func (this StmtList) String() string { |
145 | return this.indentString("") | |
146 | } | |
147 | ||
148 | func (this StmtList) indentString(indent string) string { | |
145 | 149 | if len(this) == 0 { |
146 | 150 | return "" |
147 | 151 | } |
148 | 152 | s := "" |
149 | 153 | for i := 0; i < len(this); i++ { |
150 | ss := this[i].String() | |
154 | ss := this[i].indentString(indent) | |
151 | 155 | if len(ss) > 0 { |
152 | s += "\t" + ss + ";\n" | |
156 | s += ss + ";\n" | |
153 | 157 | } |
154 | 158 | } |
159 | s = strings.TrimSuffix(s, "\n") | |
155 | 160 | return s |
156 | 161 | } |
157 | 162 | |
169 | 174 | Elem |
170 | 175 | Walkable |
171 | 176 | isStmt() |
177 | indentString(string) string | |
172 | 178 | } |
173 | 179 | |
174 | 180 | func (this NodeStmt) isStmt() {} |
215 | 221 | } |
216 | 222 | |
217 | 223 | func (this *SubGraph) String() string { |
224 | return this.indentString("") | |
225 | } | |
226 | ||
227 | func (this *SubGraph) indentString(indent string) string { | |
218 | 228 | gName := this.ID.String() |
219 | 229 | if strings.HasPrefix(gName, "anon") { |
220 | 230 | gName = "" |
221 | 231 | } |
222 | s := "subgraph " + this.ID.String() + " {\n" | |
232 | ||
233 | s := indent + "subgraph " + this.ID.String() + " {\n" | |
223 | 234 | if this.StmtList != nil { |
224 | s += this.StmtList.String() | |
225 | } | |
226 | s += "\n}\n" | |
235 | s += this.StmtList.indentString(indent + "\t") | |
236 | } | |
237 | s += "\n" + indent + "}" | |
227 | 238 | return s |
228 | 239 | } |
229 | 240 | |
243 | 254 | } |
244 | 255 | |
245 | 256 | func (this EdgeAttrs) String() string { |
257 | return this.indentString("") | |
258 | } | |
259 | ||
260 | func (this EdgeAttrs) indentString(indent string) string { | |
246 | 261 | s := AttrList(this).String() |
247 | 262 | if len(s) == 0 { |
248 | 263 | return "" |
249 | 264 | } |
250 | return `edge ` + s | |
265 | return indent + `edge ` + s | |
251 | 266 | } |
252 | 267 | |
253 | 268 | func (this EdgeAttrs) Walk(v Visitor) { |
267 | 282 | } |
268 | 283 | |
269 | 284 | func (this NodeAttrs) String() string { |
285 | return this.indentString("") | |
286 | } | |
287 | ||
288 | func (this NodeAttrs) indentString(indent string) string { | |
270 | 289 | s := AttrList(this).String() |
271 | 290 | if len(s) == 0 { |
272 | 291 | return "" |
273 | 292 | } |
274 | return `node ` + s | |
293 | return indent + `node ` + s | |
275 | 294 | } |
276 | 295 | |
277 | 296 | func (this NodeAttrs) Walk(v Visitor) { |
291 | 310 | } |
292 | 311 | |
293 | 312 | func (this GraphAttrs) String() string { |
313 | return this.indentString("") | |
314 | } | |
315 | ||
316 | func (this GraphAttrs) indentString(indent string) string { | |
294 | 317 | s := AttrList(this).String() |
295 | 318 | if len(s) == 0 { |
296 | 319 | return "" |
297 | 320 | } |
298 | return `graph ` + s | |
321 | return indent + `graph ` + s | |
299 | 322 | } |
300 | 323 | |
301 | 324 | func (this GraphAttrs) Walk(v Visitor) { |
428 | 451 | } |
429 | 452 | |
430 | 453 | func (this *Attr) String() string { |
431 | return this.Field.String() + `=` + this.Value.String() | |
454 | return this.indentString("") | |
455 | } | |
456 | ||
457 | func (this *Attr) indentString(indent string) string { | |
458 | return indent + this.Field.String() + `=` + this.Value.String() | |
432 | 459 | } |
433 | 460 | |
434 | 461 | func (this *Attr) Walk(v Visitor) { |
475 | 502 | } |
476 | 503 | |
477 | 504 | func (this EdgeStmt) String() string { |
478 | return strings.TrimSpace(this.Source.String() + this.EdgeRHS.String() + this.Attrs.String()) | |
505 | return this.indentString("") | |
506 | } | |
507 | ||
508 | func (this EdgeStmt) indentString(indent string) string { | |
509 | return indent + strings.TrimSpace(this.Source.String()+this.EdgeRHS.String()+` `+this.Attrs.String()) | |
479 | 510 | } |
480 | 511 | |
481 | 512 | func (this EdgeStmt) Walk(v Visitor) { |
557 | 588 | } |
558 | 589 | |
559 | 590 | func (this NodeStmt) String() string { |
560 | return strings.TrimSpace(this.NodeID.String() + ` ` + this.Attrs.String()) | |
591 | return this.indentString("") | |
592 | } | |
593 | ||
594 | func (this NodeStmt) indentString(indent string) string { | |
595 | return indent + strings.TrimSpace(this.NodeID.String()+` `+this.Attrs.String()) | |
561 | 596 | } |
562 | 597 | |
563 | 598 | func (this NodeStmt) Walk(v Visitor) { |
140 | 140 | Image Attr = "image" |
141 | 141 | // ImagePath http://graphviz.gitlab.io/_pages/doc/info/attrs.html#d:imagepath |
142 | 142 | ImagePath Attr = "imagepath" |
143 | // ImagePos https://graphviz.org/doc/info/attrs.html#d:imagepos | |
144 | ImagePos Attr = "imagepos" | |
143 | 145 | // ImageScale http://graphviz.gitlab.io/_pages/doc/info/attrs.html#d:imagescale |
144 | 146 | ImageScale Attr = "imagescale" |
145 | 147 | // InputScale http://graphviz.gitlab.io/_pages/doc/info/attrs.html#d:inputscale |
436 | 438 | string(ID): ID, |
437 | 439 | string(Image): Image, |
438 | 440 | string(ImagePath): ImagePath, |
441 | string(ImagePos): ImagePos, | |
439 | 442 | string(ImageScale): ImageScale, |
440 | 443 | string(InputScale): InputScale, |
441 | 444 | string(Label): Label, |
75 | 75 | return false |
76 | 76 | } |
77 | 77 | if c == '/' { |
78 | return false | |
79 | } | |
80 | if c == '.' { | |
78 | 81 | return false |
79 | 82 | } |
80 | 83 | i++ |
45 | 45 | if err := g.AddNode("asdf asdf", "a/b", nil); err != nil { |
46 | 46 | t.Fatal(err) |
47 | 47 | } |
48 | if err := g.AddNode("asdf asdf", "c.d", nil); err != nil { | |
49 | t.Fatal(err) | |
50 | } | |
51 | if err := g.AddNode("asdf asdf", "e-f", nil); err != nil { | |
52 | t.Fatal(err) | |
53 | } | |
54 | if err := g.AddNode("asdf asdf", "12_34", nil); err != nil { | |
55 | t.Fatal(err) | |
56 | } | |
48 | 57 | s := g.String() |
49 | 58 | if !strings.HasPrefix(s, `digraph "asdf adsf" { |
50 | 59 | "kasdf99 99"->7; |
60 | "12_34"; | |
51 | 61 | "a << b"; |
52 | 62 | "a/b"; |
63 | "c.d"; | |
64 | "e-f"; | |
53 | 65 | "kasdf99 99" [ URL="<a" ]; |
54 | 66 | 7 [ URL="<a" ]; |
55 | ||
56 | 67 | }`) { |
57 | 68 | t.Fatalf("%s", s) |
58 | 69 | } |
88 | 99 | graphStr := `graph G { |
89 | 100 | cluster_2--cluster_1; |
90 | 101 | subgraph cluster0 { |
91 | subgraph cluster_1 { | |
102 | subgraph cluster_1 { | |
92 | 103 | |
93 | } | |
94 | ; | |
95 | subgraph cluster_2 { | |
104 | }; | |
105 | subgraph cluster_2 { | |
96 | 106 | |
97 | } | |
98 | ; | |
99 | ||
100 | } | |
101 | ; | |
107 | }; | |
108 | }; | |
102 | 109 | "Code deployment"; |
103 | ||
104 | 110 | }` |
105 | 111 | if !strings.HasPrefix(s, graphStr) { |
106 | 112 | t.Fatalf("%s", s) |
29 | 29 | // Hello->World; |
30 | 30 | // Hello; |
31 | 31 | // World; |
32 | // | |
33 | 32 | //} |
34 | 33 | } |
35 | 34 | |
56 | 55 | // Hello->World; |
57 | 56 | // Hello; |
58 | 57 | // World; |
59 | // | |
60 | 58 | //} |
61 | 59 | } |
62 | 60 | |
159 | 157 | s := output.String() |
160 | 158 | fmt.Println(s) |
161 | 159 | // Output: digraph matrix { |
162 | // 1->1[ label=0 ]; | |
163 | // 1->2[ label=5 ]; | |
164 | // 1->3[ label=0 ]; | |
165 | // 1->4[ label=0 ]; | |
166 | // 2->1[ label=0 ]; | |
167 | // 2->2[ label=0 ]; | |
168 | // 2->3[ label=0 ]; | |
169 | // 2->4[ label=0 ]; | |
170 | // 3->1[ label=0 ]; | |
171 | // 3->2[ label=0 ]; | |
172 | // 3->3[ label=0 ]; | |
173 | // 3->4[ label=0 ]; | |
174 | // 4->1[ label=2 ]; | |
175 | // 4->2[ label=1 ]; | |
176 | // 4->3[ label=0 ]; | |
177 | // 4->4[ label=0 ]; | |
160 | // 1->1 [ label=0 ]; | |
161 | // 1->2 [ label=5 ]; | |
162 | // 1->3 [ label=0 ]; | |
163 | // 1->4 [ label=0 ]; | |
164 | // 2->1 [ label=0 ]; | |
165 | // 2->2 [ label=0 ]; | |
166 | // 2->3 [ label=0 ]; | |
167 | // 2->4 [ label=0 ]; | |
168 | // 3->1 [ label=0 ]; | |
169 | // 3->2 [ label=0 ]; | |
170 | // 3->3 [ label=0 ]; | |
171 | // 3->4 [ label=0 ]; | |
172 | // 4->1 [ label=2 ]; | |
173 | // 4->2 [ label=1 ]; | |
174 | // 4->3 [ label=0 ]; | |
175 | // 4->4 [ label=0 ]; | |
178 | 176 | // 1; |
179 | 177 | // 2; |
180 | 178 | // 3; |
181 | 179 | // 4; |
182 | // | |
183 | 180 | //} |
184 | 181 | } |
0 | #!/usr/bin/env bash | |
1 | set -xe | |
2 | mkdir -p $GOPATH/src/githbub.com/goccmack | |
3 | git clone https://github.com/goccmack/gocc $GOPATH/src/github.com/goccmack/gocc | |
4 | go get golang.org/x/tools/cmd/goimports | |
5 | go get github.com/kisielk/errcheck | |
6 | go get -u golang.org/x/lint/golint⏎ |
3 | 3 | |
4 | 4 | import ( |
5 | 5 | "fmt" |
6 | "strconv" | |
6 | 7 | "strings" |
8 | "unicode" | |
7 | 9 | |
8 | 10 | "github.com/awalterschulze/gographviz/internal/token" |
9 | 11 | ) |
21 | 23 | |
22 | 24 | func (e *Error) String() string { |
23 | 25 | w := new(strings.Builder) |
24 | fmt.Fprintf(w, "Error") | |
25 | 26 | if e.Err != nil { |
26 | fmt.Fprintf(w, " %s\n", e.Err) | |
27 | fmt.Fprintln(w, "Error ", e.Err) | |
27 | 28 | } else { |
28 | fmt.Fprintf(w, "\n") | |
29 | fmt.Fprintln(w, "Error") | |
29 | 30 | } |
30 | 31 | fmt.Fprintf(w, "Token: type=%d, lit=%s\n", e.ErrorToken.Type, e.ErrorToken.Lit) |
31 | 32 | fmt.Fprintf(w, "Pos: offset=%d, line=%d, column=%d\n", e.ErrorToken.Pos.Offset, e.ErrorToken.Pos.Line, e.ErrorToken.Pos.Column) |
32 | fmt.Fprintf(w, "Expected one of: ") | |
33 | fmt.Fprint(w, "Expected one of: ") | |
33 | 34 | for _, sym := range e.ExpectedTokens { |
34 | fmt.Fprintf(w, "%s ", sym) | |
35 | fmt.Fprint(w, string(sym), " ") | |
35 | 36 | } |
36 | fmt.Fprintf(w, "ErrorSymbol:\n") | |
37 | fmt.Fprintln(w, "ErrorSymbol:") | |
37 | 38 | for _, sym := range e.ErrorSymbols { |
38 | 39 | fmt.Fprintf(w, "%v\n", sym) |
39 | 40 | } |
41 | ||
40 | 42 | return w.String() |
41 | 43 | } |
42 | 44 | |
45 | func DescribeExpected(tokens []string) string { | |
46 | switch len(tokens) { | |
47 | case 0: | |
48 | return "unexpected additional tokens" | |
49 | ||
50 | case 1: | |
51 | return "expected " + tokens[0] | |
52 | ||
53 | case 2: | |
54 | return "expected either " + tokens[0] + " or " + tokens[1] | |
55 | ||
56 | case 3: | |
57 | // Oxford-comma rules require more than 3 items in a list for the | |
58 | // comma to appear before the 'or' | |
59 | return fmt.Sprintf("expected one of %s, %s or %s", tokens[0], tokens[1], tokens[2]) | |
60 | ||
61 | default: | |
62 | // Oxford-comma separated alternatives list. | |
63 | tokens = append(tokens[:len(tokens)-1], "or "+tokens[len(tokens)-1]) | |
64 | return "expected one of " + strings.Join(tokens, ", ") | |
65 | } | |
66 | } | |
67 | ||
68 | func DescribeToken(tok *token.Token) string { | |
69 | switch tok.Type { | |
70 | case token.INVALID: | |
71 | return fmt.Sprintf("unknown/invalid token %q", tok.Lit) | |
72 | case token.EOF: | |
73 | return "end-of-file" | |
74 | default: | |
75 | return fmt.Sprintf("%q", tok.Lit) | |
76 | } | |
77 | } | |
78 | ||
43 | 79 | func (e *Error) Error() string { |
44 | w := new(strings.Builder) | |
45 | fmt.Fprintf(w, "Error in S%d: %s, %s", e.StackTop, token.TokMap.TokenString(e.ErrorToken), e.ErrorToken.Pos.String()) | |
80 | // identify the line and column of the error in 'gnu' style so it can be understood | |
81 | // by editors and IDEs; user will need to prefix it with a filename. | |
82 | text := fmt.Sprintf("%d:%d: error: ", e.ErrorToken.Pos.Line, e.ErrorToken.Pos.Column) | |
83 | ||
84 | // See if the error token can provide us with the filename. | |
85 | switch src := e.ErrorToken.Pos.Context.(type) { | |
86 | case token.Sourcer: | |
87 | text = src.Source() + ":" + text | |
88 | } | |
89 | ||
46 | 90 | if e.Err != nil { |
47 | fmt.Fprintf(w, ": %+v", e.Err) | |
91 | // Custom error specified, e.g. by << nil, errors.New("missing newline") >> | |
92 | text += e.Err.Error() | |
48 | 93 | } else { |
49 | fmt.Fprintf(w, ", expected one of: ") | |
50 | for _, expected := range e.ExpectedTokens { | |
51 | fmt.Fprintf(w, "%s ", expected) | |
94 | tokens := make([]string, len(e.ExpectedTokens)) | |
95 | for idx, token := range e.ExpectedTokens { | |
96 | if !unicode.IsLetter(rune(token[0])) { | |
97 | token = strconv.Quote(token) | |
98 | } | |
99 | tokens[idx] = token | |
52 | 100 | } |
101 | text += DescribeExpected(tokens) | |
102 | actual := DescribeToken(e.ErrorToken) | |
103 | text += fmt.Sprintf("; got: %s", actual) | |
53 | 104 | } |
54 | return w.String() | |
105 | ||
106 | return text | |
55 | 107 | } |
15 | 15 | ) |
16 | 16 | |
17 | 17 | type Lexer struct { |
18 | src []byte | |
19 | pos int | |
20 | line int | |
21 | column int | |
18 | src []byte | |
19 | pos int | |
20 | line int | |
21 | column int | |
22 | Context token.Context | |
22 | 23 | } |
23 | 24 | |
24 | 25 | func NewLexer(src []byte) *Lexer { |
25 | 26 | lexer := &Lexer{ |
26 | src: src, | |
27 | pos: 0, | |
28 | line: 1, | |
29 | column: 1, | |
27 | src: src, | |
28 | pos: 0, | |
29 | line: 1, | |
30 | column: 1, | |
31 | Context: nil, | |
30 | 32 | } |
31 | 33 | return lexer |
34 | } | |
35 | ||
36 | // SourceContext is a simple instance of a token.Context which | |
37 | // contains the name of the source file. | |
38 | type SourceContext struct { | |
39 | Filepath string | |
40 | } | |
41 | ||
42 | func (s *SourceContext) Source() string { | |
43 | return s.Filepath | |
32 | 44 | } |
33 | 45 | |
34 | 46 | func NewLexerFile(fpath string) (*Lexer, error) { |
36 | 48 | if err != nil { |
37 | 49 | return nil, err |
38 | 50 | } |
39 | return NewLexer(src), nil | |
51 | lexer := NewLexer(src) | |
52 | lexer.Context = &SourceContext{Filepath: fpath} | |
53 | return lexer, nil | |
40 | 54 | } |
41 | 55 | |
42 | 56 | func (l *Lexer) Scan() (tok *token.Token) { |
43 | tok = new(token.Token) | |
57 | tok = &token.Token{} | |
44 | 58 | if l.pos >= len(l.src) { |
45 | 59 | tok.Type = token.EOF |
46 | 60 | tok.Pos.Offset, tok.Pos.Line, tok.Pos.Column = l.pos, l.line, l.column |
61 | tok.Pos.Context = l.Context | |
47 | 62 | return |
48 | 63 | } |
49 | 64 | start, startLine, startColumn, end := l.pos, l.line, l.column, 0 |
102 | 117 | tok.Lit = []byte{} |
103 | 118 | } |
104 | 119 | tok.Pos.Offset, tok.Pos.Line, tok.Pos.Column = start, startLine, startColumn |
120 | tok.Pos.Context = l.Context | |
105 | 121 | |
106 | 122 | return |
107 | 123 | } |
0 | // Code generated by gocc; DO NOT EDIT. | |
1 | ||
2 | package parser | |
3 | ||
4 | // Parser-specific user-defined and entirely-optional context, | |
5 | // accessible as '$Context' in SDT actions. | |
6 | type Context interface{} |
90 | 90 | stack *stack |
91 | 91 | nextToken *token.Token |
92 | 92 | pos int |
93 | Context Context | |
93 | 94 | } |
94 | 95 | |
95 | 96 | type Scanner interface { |
201 | 202 | p.nextToken = scanner.Scan() |
202 | 203 | case reduce: |
203 | 204 | prod := productionsTable[int(act)] |
204 | attrib, err := prod.ReduceFunc(p.stack.popN(prod.NumSymbols)) | |
205 | attrib, err := prod.ReduceFunc(p.stack.popN(prod.NumSymbols), p.Context) | |
205 | 206 | if err != nil { |
206 | 207 | return nil, p.newError(err) |
207 | 208 | } else { |
4 | 4 | import "github.com/awalterschulze/gographviz/ast" |
5 | 5 | |
6 | 6 | type ( |
7 | //TODO: change type and variable names to be consistent with other tables | |
8 | 7 | ProdTab [numProductions]ProdTabEntry |
9 | 8 | ProdTabEntry struct { |
10 | 9 | String string |
12 | 11 | NTType int |
13 | 12 | Index int |
14 | 13 | NumSymbols int |
15 | ReduceFunc func([]Attrib) (Attrib, error) | |
14 | ReduceFunc func([]Attrib, interface{}) (Attrib, error) | |
16 | 15 | } |
17 | 16 | Attrib interface { |
18 | 17 | } |
25 | 24 | NTType: 0, |
26 | 25 | Index: 0, |
27 | 26 | NumSymbols: 1, |
28 | ReduceFunc: func(X []Attrib) (Attrib, error) { | |
27 | ReduceFunc: func(X []Attrib, C interface{}) (Attrib, error) { | |
29 | 28 | return X[0], nil |
30 | 29 | }, |
31 | 30 | }, |
35 | 34 | NTType: 1, |
36 | 35 | Index: 1, |
37 | 36 | NumSymbols: 3, |
38 | ReduceFunc: func(X []Attrib) (Attrib, error) { | |
37 | ReduceFunc: func(X []Attrib, C interface{}) (Attrib, error) { | |
39 | 38 | return ast.NewGraph(ast.GRAPH, ast.FALSE, nil, nil) |
40 | 39 | }, |
41 | 40 | }, |
45 | 44 | NTType: 1, |
46 | 45 | Index: 2, |
47 | 46 | NumSymbols: 4, |
48 | ReduceFunc: func(X []Attrib) (Attrib, error) { | |
47 | ReduceFunc: func(X []Attrib, C interface{}) (Attrib, error) { | |
49 | 48 | return ast.NewGraph(ast.GRAPH, ast.TRUE, nil, nil) |
50 | 49 | }, |
51 | 50 | }, |
55 | 54 | NTType: 1, |
56 | 55 | Index: 3, |
57 | 56 | NumSymbols: 4, |
58 | ReduceFunc: func(X []Attrib) (Attrib, error) { | |
57 | ReduceFunc: func(X []Attrib, C interface{}) (Attrib, error) { | |
59 | 58 | return ast.NewGraph(ast.GRAPH, ast.FALSE, X[1], nil) |
60 | 59 | }, |
61 | 60 | }, |
65 | 64 | NTType: 1, |
66 | 65 | Index: 4, |
67 | 66 | NumSymbols: 5, |
68 | ReduceFunc: func(X []Attrib) (Attrib, error) { | |
67 | ReduceFunc: func(X []Attrib, C interface{}) (Attrib, error) { | |
69 | 68 | return ast.NewGraph(ast.GRAPH, ast.TRUE, X[2], nil) |
70 | 69 | }, |
71 | 70 | }, |
75 | 74 | NTType: 1, |
76 | 75 | Index: 5, |
77 | 76 | NumSymbols: 4, |
78 | ReduceFunc: func(X []Attrib) (Attrib, error) { | |
77 | ReduceFunc: func(X []Attrib, C interface{}) (Attrib, error) { | |
79 | 78 | return ast.NewGraph(ast.GRAPH, ast.FALSE, nil, X[2]) |
80 | 79 | }, |
81 | 80 | }, |
85 | 84 | NTType: 1, |
86 | 85 | Index: 6, |
87 | 86 | NumSymbols: 5, |
88 | ReduceFunc: func(X []Attrib) (Attrib, error) { | |
87 | ReduceFunc: func(X []Attrib, C interface{}) (Attrib, error) { | |
89 | 88 | return ast.NewGraph(ast.GRAPH, ast.FALSE, X[1], X[3]) |
90 | 89 | }, |
91 | 90 | }, |
95 | 94 | NTType: 1, |
96 | 95 | Index: 7, |
97 | 96 | NumSymbols: 5, |
98 | ReduceFunc: func(X []Attrib) (Attrib, error) { | |
97 | ReduceFunc: func(X []Attrib, C interface{}) (Attrib, error) { | |
99 | 98 | return ast.NewGraph(ast.GRAPH, ast.TRUE, nil, X[3]) |
100 | 99 | }, |
101 | 100 | }, |
105 | 104 | NTType: 1, |
106 | 105 | Index: 8, |
107 | 106 | NumSymbols: 6, |
108 | ReduceFunc: func(X []Attrib) (Attrib, error) { | |
107 | ReduceFunc: func(X []Attrib, C interface{}) (Attrib, error) { | |
109 | 108 | return ast.NewGraph(ast.GRAPH, ast.TRUE, X[2], X[4]) |
110 | 109 | }, |
111 | 110 | }, |
115 | 114 | NTType: 1, |
116 | 115 | Index: 9, |
117 | 116 | NumSymbols: 3, |
118 | ReduceFunc: func(X []Attrib) (Attrib, error) { | |
117 | ReduceFunc: func(X []Attrib, C interface{}) (Attrib, error) { | |
119 | 118 | return ast.NewGraph(ast.DIGRAPH, ast.FALSE, nil, nil) |
120 | 119 | }, |
121 | 120 | }, |
125 | 124 | NTType: 1, |
126 | 125 | Index: 10, |
127 | 126 | NumSymbols: 4, |
128 | ReduceFunc: func(X []Attrib) (Attrib, error) { | |
127 | ReduceFunc: func(X []Attrib, C interface{}) (Attrib, error) { | |
129 | 128 | return ast.NewGraph(ast.DIGRAPH, ast.TRUE, nil, nil) |
130 | 129 | }, |
131 | 130 | }, |
135 | 134 | NTType: 1, |
136 | 135 | Index: 11, |
137 | 136 | NumSymbols: 4, |
138 | ReduceFunc: func(X []Attrib) (Attrib, error) { | |
137 | ReduceFunc: func(X []Attrib, C interface{}) (Attrib, error) { | |
139 | 138 | return ast.NewGraph(ast.DIGRAPH, ast.FALSE, X[1], nil) |
140 | 139 | }, |
141 | 140 | }, |
145 | 144 | NTType: 1, |
146 | 145 | Index: 12, |
147 | 146 | NumSymbols: 5, |
148 | ReduceFunc: func(X []Attrib) (Attrib, error) { | |
147 | ReduceFunc: func(X []Attrib, C interface{}) (Attrib, error) { | |
149 | 148 | return ast.NewGraph(ast.DIGRAPH, ast.TRUE, X[2], nil) |
150 | 149 | }, |
151 | 150 | }, |
155 | 154 | NTType: 1, |
156 | 155 | Index: 13, |
157 | 156 | NumSymbols: 4, |
158 | ReduceFunc: func(X []Attrib) (Attrib, error) { | |
157 | ReduceFunc: func(X []Attrib, C interface{}) (Attrib, error) { | |
159 | 158 | return ast.NewGraph(ast.DIGRAPH, ast.FALSE, nil, X[2]) |
160 | 159 | }, |
161 | 160 | }, |
165 | 164 | NTType: 1, |
166 | 165 | Index: 14, |
167 | 166 | NumSymbols: 5, |
168 | ReduceFunc: func(X []Attrib) (Attrib, error) { | |
167 | ReduceFunc: func(X []Attrib, C interface{}) (Attrib, error) { | |
169 | 168 | return ast.NewGraph(ast.DIGRAPH, ast.FALSE, X[1], X[3]) |
170 | 169 | }, |
171 | 170 | }, |
175 | 174 | NTType: 1, |
176 | 175 | Index: 15, |
177 | 176 | NumSymbols: 5, |
178 | ReduceFunc: func(X []Attrib) (Attrib, error) { | |
177 | ReduceFunc: func(X []Attrib, C interface{}) (Attrib, error) { | |
179 | 178 | return ast.NewGraph(ast.DIGRAPH, ast.TRUE, nil, X[3]) |
180 | 179 | }, |
181 | 180 | }, |
185 | 184 | NTType: 1, |
186 | 185 | Index: 16, |
187 | 186 | NumSymbols: 6, |
188 | ReduceFunc: func(X []Attrib) (Attrib, error) { | |
187 | ReduceFunc: func(X []Attrib, C interface{}) (Attrib, error) { | |
189 | 188 | return ast.NewGraph(ast.DIGRAPH, ast.TRUE, X[2], X[4]) |
190 | 189 | }, |
191 | 190 | }, |
195 | 194 | NTType: 2, |
196 | 195 | Index: 17, |
197 | 196 | NumSymbols: 1, |
198 | ReduceFunc: func(X []Attrib) (Attrib, error) { | |
197 | ReduceFunc: func(X []Attrib, C interface{}) (Attrib, error) { | |
199 | 198 | return ast.NewStmtList(X[0]) |
200 | 199 | }, |
201 | 200 | }, |
205 | 204 | NTType: 2, |
206 | 205 | Index: 18, |
207 | 206 | NumSymbols: 2, |
208 | ReduceFunc: func(X []Attrib) (Attrib, error) { | |
207 | ReduceFunc: func(X []Attrib, C interface{}) (Attrib, error) { | |
209 | 208 | return ast.AppendStmtList(X[0], X[1]) |
210 | 209 | }, |
211 | 210 | }, |
215 | 214 | NTType: 3, |
216 | 215 | Index: 19, |
217 | 216 | NumSymbols: 1, |
218 | ReduceFunc: func(X []Attrib) (Attrib, error) { | |
217 | ReduceFunc: func(X []Attrib, C interface{}) (Attrib, error) { | |
219 | 218 | return X[0], nil |
220 | 219 | }, |
221 | 220 | }, |
225 | 224 | NTType: 3, |
226 | 225 | Index: 20, |
227 | 226 | NumSymbols: 2, |
228 | ReduceFunc: func(X []Attrib) (Attrib, error) { | |
227 | ReduceFunc: func(X []Attrib, C interface{}) (Attrib, error) { | |
229 | 228 | return X[0], nil |
230 | 229 | }, |
231 | 230 | }, |
235 | 234 | NTType: 4, |
236 | 235 | Index: 21, |
237 | 236 | NumSymbols: 3, |
238 | ReduceFunc: func(X []Attrib) (Attrib, error) { | |
237 | ReduceFunc: func(X []Attrib, C interface{}) (Attrib, error) { | |
239 | 238 | return ast.NewAttr(X[0], X[2]) |
240 | 239 | }, |
241 | 240 | }, |
245 | 244 | NTType: 4, |
246 | 245 | Index: 22, |
247 | 246 | NumSymbols: 1, |
248 | ReduceFunc: func(X []Attrib) (Attrib, error) { | |
247 | ReduceFunc: func(X []Attrib, C interface{}) (Attrib, error) { | |
249 | 248 | return X[0], nil |
250 | 249 | }, |
251 | 250 | }, |
255 | 254 | NTType: 4, |
256 | 255 | Index: 23, |
257 | 256 | NumSymbols: 1, |
258 | ReduceFunc: func(X []Attrib) (Attrib, error) { | |
257 | ReduceFunc: func(X []Attrib, C interface{}) (Attrib, error) { | |
259 | 258 | return X[0], nil |
260 | 259 | }, |
261 | 260 | }, |
265 | 264 | NTType: 4, |
266 | 265 | Index: 24, |
267 | 266 | NumSymbols: 1, |
268 | ReduceFunc: func(X []Attrib) (Attrib, error) { | |
267 | ReduceFunc: func(X []Attrib, C interface{}) (Attrib, error) { | |
269 | 268 | return X[0], nil |
270 | 269 | }, |
271 | 270 | }, |
275 | 274 | NTType: 4, |
276 | 275 | Index: 25, |
277 | 276 | NumSymbols: 1, |
278 | ReduceFunc: func(X []Attrib) (Attrib, error) { | |
277 | ReduceFunc: func(X []Attrib, C interface{}) (Attrib, error) { | |
279 | 278 | return X[0], nil |
280 | 279 | }, |
281 | 280 | }, |
285 | 284 | NTType: 5, |
286 | 285 | Index: 26, |
287 | 286 | NumSymbols: 2, |
288 | ReduceFunc: func(X []Attrib) (Attrib, error) { | |
287 | ReduceFunc: func(X []Attrib, C interface{}) (Attrib, error) { | |
289 | 288 | return ast.NewGraphAttrs(X[1]) |
290 | 289 | }, |
291 | 290 | }, |
295 | 294 | NTType: 5, |
296 | 295 | Index: 27, |
297 | 296 | NumSymbols: 2, |
298 | ReduceFunc: func(X []Attrib) (Attrib, error) { | |
297 | ReduceFunc: func(X []Attrib, C interface{}) (Attrib, error) { | |
299 | 298 | return ast.NewNodeAttrs(X[1]) |
300 | 299 | }, |
301 | 300 | }, |
305 | 304 | NTType: 5, |
306 | 305 | Index: 28, |
307 | 306 | NumSymbols: 2, |
308 | ReduceFunc: func(X []Attrib) (Attrib, error) { | |
307 | ReduceFunc: func(X []Attrib, C interface{}) (Attrib, error) { | |
309 | 308 | return ast.NewEdgeAttrs(X[1]) |
310 | 309 | }, |
311 | 310 | }, |
315 | 314 | NTType: 6, |
316 | 315 | Index: 29, |
317 | 316 | NumSymbols: 2, |
318 | ReduceFunc: func(X []Attrib) (Attrib, error) { | |
317 | ReduceFunc: func(X []Attrib, C interface{}) (Attrib, error) { | |
319 | 318 | return ast.NewAttrList(nil) |
320 | 319 | }, |
321 | 320 | }, |
325 | 324 | NTType: 6, |
326 | 325 | Index: 30, |
327 | 326 | NumSymbols: 3, |
328 | ReduceFunc: func(X []Attrib) (Attrib, error) { | |
327 | ReduceFunc: func(X []Attrib, C interface{}) (Attrib, error) { | |
329 | 328 | return ast.NewAttrList(X[1]) |
330 | 329 | }, |
331 | 330 | }, |
335 | 334 | NTType: 6, |
336 | 335 | Index: 31, |
337 | 336 | NumSymbols: 3, |
338 | ReduceFunc: func(X []Attrib) (Attrib, error) { | |
337 | ReduceFunc: func(X []Attrib, C interface{}) (Attrib, error) { | |
339 | 338 | return ast.AppendAttrList(X[0], nil) |
340 | 339 | }, |
341 | 340 | }, |
345 | 344 | NTType: 6, |
346 | 345 | Index: 32, |
347 | 346 | NumSymbols: 4, |
348 | ReduceFunc: func(X []Attrib) (Attrib, error) { | |
347 | ReduceFunc: func(X []Attrib, C interface{}) (Attrib, error) { | |
349 | 348 | return ast.AppendAttrList(X[0], X[2]) |
350 | 349 | }, |
351 | 350 | }, |
355 | 354 | NTType: 7, |
356 | 355 | Index: 33, |
357 | 356 | NumSymbols: 1, |
358 | ReduceFunc: func(X []Attrib) (Attrib, error) { | |
357 | ReduceFunc: func(X []Attrib, C interface{}) (Attrib, error) { | |
359 | 358 | return ast.NewAList(X[0]) |
360 | 359 | }, |
361 | 360 | }, |
365 | 364 | NTType: 7, |
366 | 365 | Index: 34, |
367 | 366 | NumSymbols: 2, |
368 | ReduceFunc: func(X []Attrib) (Attrib, error) { | |
367 | ReduceFunc: func(X []Attrib, C interface{}) (Attrib, error) { | |
369 | 368 | return ast.AppendAList(X[0], X[1]) |
370 | 369 | }, |
371 | 370 | }, |
375 | 374 | NTType: 7, |
376 | 375 | Index: 35, |
377 | 376 | NumSymbols: 3, |
378 | ReduceFunc: func(X []Attrib) (Attrib, error) { | |
377 | ReduceFunc: func(X []Attrib, C interface{}) (Attrib, error) { | |
379 | 378 | return ast.AppendAList(X[0], X[2]) |
380 | 379 | }, |
381 | 380 | }, |
385 | 384 | NTType: 8, |
386 | 385 | Index: 36, |
387 | 386 | NumSymbols: 1, |
388 | ReduceFunc: func(X []Attrib) (Attrib, error) { | |
387 | ReduceFunc: func(X []Attrib, C interface{}) (Attrib, error) { | |
389 | 388 | return ast.NewAttr(X[0], nil) |
390 | 389 | }, |
391 | 390 | }, |
395 | 394 | NTType: 8, |
396 | 395 | Index: 37, |
397 | 396 | NumSymbols: 3, |
398 | ReduceFunc: func(X []Attrib) (Attrib, error) { | |
397 | ReduceFunc: func(X []Attrib, C interface{}) (Attrib, error) { | |
399 | 398 | return ast.NewAttr(X[0], X[2]) |
400 | 399 | }, |
401 | 400 | }, |
405 | 404 | NTType: 9, |
406 | 405 | Index: 38, |
407 | 406 | NumSymbols: 2, |
408 | ReduceFunc: func(X []Attrib) (Attrib, error) { | |
407 | ReduceFunc: func(X []Attrib, C interface{}) (Attrib, error) { | |
409 | 408 | return ast.NewEdgeStmt(X[0], X[1], nil) |
410 | 409 | }, |
411 | 410 | }, |
415 | 414 | NTType: 9, |
416 | 415 | Index: 39, |
417 | 416 | NumSymbols: 3, |
418 | ReduceFunc: func(X []Attrib) (Attrib, error) { | |
417 | ReduceFunc: func(X []Attrib, C interface{}) (Attrib, error) { | |
419 | 418 | return ast.NewEdgeStmt(X[0], X[1], X[2]) |
420 | 419 | }, |
421 | 420 | }, |
425 | 424 | NTType: 9, |
426 | 425 | Index: 40, |
427 | 426 | NumSymbols: 2, |
428 | ReduceFunc: func(X []Attrib) (Attrib, error) { | |
427 | ReduceFunc: func(X []Attrib, C interface{}) (Attrib, error) { | |
429 | 428 | return ast.NewEdgeStmt(X[0], X[1], nil) |
430 | 429 | }, |
431 | 430 | }, |
435 | 434 | NTType: 9, |
436 | 435 | Index: 41, |
437 | 436 | NumSymbols: 3, |
438 | ReduceFunc: func(X []Attrib) (Attrib, error) { | |
437 | ReduceFunc: func(X []Attrib, C interface{}) (Attrib, error) { | |
439 | 438 | return ast.NewEdgeStmt(X[0], X[1], X[2]) |
440 | 439 | }, |
441 | 440 | }, |
445 | 444 | NTType: 10, |
446 | 445 | Index: 42, |
447 | 446 | NumSymbols: 2, |
448 | ReduceFunc: func(X []Attrib) (Attrib, error) { | |
447 | ReduceFunc: func(X []Attrib, C interface{}) (Attrib, error) { | |
449 | 448 | return ast.NewEdgeRHS(X[0], X[1]) |
450 | 449 | }, |
451 | 450 | }, |
455 | 454 | NTType: 10, |
456 | 455 | Index: 43, |
457 | 456 | NumSymbols: 2, |
458 | ReduceFunc: func(X []Attrib) (Attrib, error) { | |
457 | ReduceFunc: func(X []Attrib, C interface{}) (Attrib, error) { | |
459 | 458 | return ast.NewEdgeRHS(X[0], X[1]) |
460 | 459 | }, |
461 | 460 | }, |
465 | 464 | NTType: 10, |
466 | 465 | Index: 44, |
467 | 466 | NumSymbols: 3, |
468 | ReduceFunc: func(X []Attrib) (Attrib, error) { | |
467 | ReduceFunc: func(X []Attrib, C interface{}) (Attrib, error) { | |
469 | 468 | return ast.AppendEdgeRHS(X[0], X[1], X[2]) |
470 | 469 | }, |
471 | 470 | }, |
475 | 474 | NTType: 10, |
476 | 475 | Index: 45, |
477 | 476 | NumSymbols: 3, |
478 | ReduceFunc: func(X []Attrib) (Attrib, error) { | |
477 | ReduceFunc: func(X []Attrib, C interface{}) (Attrib, error) { | |
479 | 478 | return ast.AppendEdgeRHS(X[0], X[1], X[2]) |
480 | 479 | }, |
481 | 480 | }, |
485 | 484 | NTType: 11, |
486 | 485 | Index: 46, |
487 | 486 | NumSymbols: 1, |
488 | ReduceFunc: func(X []Attrib) (Attrib, error) { | |
487 | ReduceFunc: func(X []Attrib, C interface{}) (Attrib, error) { | |
489 | 488 | return ast.NewNodeStmt(X[0], nil) |
490 | 489 | }, |
491 | 490 | }, |
495 | 494 | NTType: 11, |
496 | 495 | Index: 47, |
497 | 496 | NumSymbols: 2, |
498 | ReduceFunc: func(X []Attrib) (Attrib, error) { | |
497 | ReduceFunc: func(X []Attrib, C interface{}) (Attrib, error) { | |
499 | 498 | return ast.NewNodeStmt(X[0], X[1]) |
500 | 499 | }, |
501 | 500 | }, |
505 | 504 | NTType: 12, |
506 | 505 | Index: 48, |
507 | 506 | NumSymbols: 1, |
508 | ReduceFunc: func(X []Attrib) (Attrib, error) { | |
507 | ReduceFunc: func(X []Attrib, C interface{}) (Attrib, error) { | |
509 | 508 | return ast.NewNodeID(X[0], nil) |
510 | 509 | }, |
511 | 510 | }, |
515 | 514 | NTType: 12, |
516 | 515 | Index: 49, |
517 | 516 | NumSymbols: 2, |
518 | ReduceFunc: func(X []Attrib) (Attrib, error) { | |
517 | ReduceFunc: func(X []Attrib, C interface{}) (Attrib, error) { | |
519 | 518 | return ast.NewNodeID(X[0], X[1]) |
520 | 519 | }, |
521 | 520 | }, |
525 | 524 | NTType: 13, |
526 | 525 | Index: 50, |
527 | 526 | NumSymbols: 2, |
528 | ReduceFunc: func(X []Attrib) (Attrib, error) { | |
527 | ReduceFunc: func(X []Attrib, C interface{}) (Attrib, error) { | |
529 | 528 | return ast.NewPort(X[1], nil), nil |
530 | 529 | }, |
531 | 530 | }, |
535 | 534 | NTType: 13, |
536 | 535 | Index: 51, |
537 | 536 | NumSymbols: 4, |
538 | ReduceFunc: func(X []Attrib) (Attrib, error) { | |
537 | ReduceFunc: func(X []Attrib, C interface{}) (Attrib, error) { | |
539 | 538 | return ast.NewPort(X[1], X[3]), nil |
540 | 539 | }, |
541 | 540 | }, |
545 | 544 | NTType: 14, |
546 | 545 | Index: 52, |
547 | 546 | NumSymbols: 3, |
548 | ReduceFunc: func(X []Attrib) (Attrib, error) { | |
547 | ReduceFunc: func(X []Attrib, C interface{}) (Attrib, error) { | |
549 | 548 | return ast.NewSubGraph(nil, X[1]) |
550 | 549 | }, |
551 | 550 | }, |
555 | 554 | NTType: 14, |
556 | 555 | Index: 53, |
557 | 556 | NumSymbols: 4, |
558 | ReduceFunc: func(X []Attrib) (Attrib, error) { | |
557 | ReduceFunc: func(X []Attrib, C interface{}) (Attrib, error) { | |
559 | 558 | return ast.NewSubGraph(nil, X[2]) |
560 | 559 | }, |
561 | 560 | }, |
565 | 564 | NTType: 14, |
566 | 565 | Index: 54, |
567 | 566 | NumSymbols: 5, |
568 | ReduceFunc: func(X []Attrib) (Attrib, error) { | |
567 | ReduceFunc: func(X []Attrib, C interface{}) (Attrib, error) { | |
569 | 568 | return ast.NewSubGraph(X[1], X[3]) |
570 | 569 | }, |
571 | 570 | }, |
575 | 574 | NTType: 14, |
576 | 575 | Index: 55, |
577 | 576 | NumSymbols: 3, |
578 | ReduceFunc: func(X []Attrib) (Attrib, error) { | |
577 | ReduceFunc: func(X []Attrib, C interface{}) (Attrib, error) { | |
579 | 578 | return ast.NewSubGraph(nil, nil) |
580 | 579 | }, |
581 | 580 | }, |
585 | 584 | NTType: 14, |
586 | 585 | Index: 56, |
587 | 586 | NumSymbols: 4, |
588 | ReduceFunc: func(X []Attrib) (Attrib, error) { | |
587 | ReduceFunc: func(X []Attrib, C interface{}) (Attrib, error) { | |
589 | 588 | return ast.NewSubGraph(X[1], nil) |
590 | 589 | }, |
591 | 590 | }, |
595 | 594 | NTType: 15, |
596 | 595 | Index: 57, |
597 | 596 | NumSymbols: 1, |
598 | ReduceFunc: func(X []Attrib) (Attrib, error) { | |
597 | ReduceFunc: func(X []Attrib, C interface{}) (Attrib, error) { | |
599 | 598 | return ast.DIRECTED, nil |
600 | 599 | }, |
601 | 600 | }, |
605 | 604 | NTType: 15, |
606 | 605 | Index: 58, |
607 | 606 | NumSymbols: 1, |
608 | ReduceFunc: func(X []Attrib) (Attrib, error) { | |
607 | ReduceFunc: func(X []Attrib, C interface{}) (Attrib, error) { | |
609 | 608 | return ast.UNDIRECTED, nil |
610 | 609 | }, |
611 | 610 | }, |
615 | 614 | NTType: 16, |
616 | 615 | Index: 59, |
617 | 616 | NumSymbols: 1, |
618 | ReduceFunc: func(X []Attrib) (Attrib, error) { | |
617 | ReduceFunc: func(X []Attrib, C interface{}) (Attrib, error) { | |
619 | 618 | return ast.NewID(X[0]) |
620 | 619 | }, |
621 | 620 | }, |
0 | // Code generated by gocc; DO NOT EDIT. | |
1 | ||
2 | package token | |
3 | ||
4 | // Context allows user-defined data to be associated with the | |
5 | // lexer/scanner to be associated with each token that lexer | |
6 | // produces. | |
7 | type Context interface{} | |
8 | ||
9 | // Sourcer is a Context interface which presents a Source() method | |
10 | // identifying e.g the filename for the current code. | |
11 | type Sourcer interface { | |
12 | Source() string | |
13 | } |
2 | 2 | package token |
3 | 3 | |
4 | 4 | import ( |
5 | "bytes" | |
5 | 6 | "fmt" |
7 | "strconv" | |
8 | "unicode/utf8" | |
6 | 9 | ) |
7 | 10 | |
8 | 11 | type Token struct { |
19 | 22 | ) |
20 | 23 | |
21 | 24 | type Pos struct { |
22 | Offset int | |
23 | Line int | |
24 | Column int | |
25 | Offset int | |
26 | Line int | |
27 | Column int | |
28 | Context Context | |
25 | 29 | } |
26 | 30 | |
27 | 31 | func (p Pos) String() string { |
28 | return fmt.Sprintf("Pos(offset=%d, line=%d, column=%d)", p.Offset, p.Line, p.Column) | |
32 | // If the context provides a filename, provide a human-readable File:Line:Column representation. | |
33 | switch src := p.Context.(type) { | |
34 | case Sourcer: | |
35 | return fmt.Sprintf("%s:%d:%d", src.Source(), p.Line, p.Column) | |
36 | default: | |
37 | return fmt.Sprintf("Pos(offset=%d, line=%d, column=%d)", p.Offset, p.Line, p.Column) | |
38 | } | |
29 | 39 | } |
30 | 40 | |
31 | 41 | type TokenMap struct { |
48 | 58 | } |
49 | 59 | |
50 | 60 | func (m TokenMap) TokenString(tok *Token) string { |
51 | //TODO: refactor to print pos & token string properly | |
52 | 61 | return fmt.Sprintf("%s(%d,%s)", m.Id(tok.Type), tok.Type, tok.Lit) |
53 | 62 | } |
54 | 63 | |
55 | 64 | func (m TokenMap) StringType(typ Type) string { |
56 | 65 | return fmt.Sprintf("%s(%d)", m.Id(typ), typ) |
66 | } | |
67 | ||
68 | // Equals returns returns true if the token Type and Lit are matches. | |
69 | func (t *Token) Equals(rhs interface{}) bool { | |
70 | switch rhsT := rhs.(type) { | |
71 | case *Token: | |
72 | return t == rhsT || (t.Type == rhsT.Type && bytes.Equal(t.Lit, rhsT.Lit)) | |
73 | default: | |
74 | return false | |
75 | } | |
76 | } | |
77 | ||
78 | // CharLiteralValue returns the string value of the char literal. | |
79 | func (t *Token) CharLiteralValue() string { | |
80 | return string(t.Lit[1 : len(t.Lit)-1]) | |
81 | } | |
82 | ||
83 | // Float32Value returns the float32 value of the token or an error if the token literal does not | |
84 | // denote a valid float32. | |
85 | func (t *Token) Float32Value() (float32, error) { | |
86 | if v, err := strconv.ParseFloat(string(t.Lit), 32); err != nil { | |
87 | return 0, err | |
88 | } else { | |
89 | return float32(v), nil | |
90 | } | |
91 | } | |
92 | ||
93 | // Float64Value returns the float64 value of the token or an error if the token literal does not | |
94 | // denote a valid float64. | |
95 | func (t *Token) Float64Value() (float64, error) { | |
96 | return strconv.ParseFloat(string(t.Lit), 64) | |
97 | } | |
98 | ||
99 | // IDValue returns the string representation of an identifier token. | |
100 | func (t *Token) IDValue() string { | |
101 | return string(t.Lit) | |
102 | } | |
103 | ||
104 | // Int32Value returns the int32 value of the token or an error if the token literal does not | |
105 | // denote a valid float64. | |
106 | func (t *Token) Int32Value() (int32, error) { | |
107 | if v, err := strconv.ParseInt(string(t.Lit), 10, 64); err != nil { | |
108 | return 0, err | |
109 | } else { | |
110 | return int32(v), nil | |
111 | } | |
112 | } | |
113 | ||
114 | // Int64Value returns the int64 value of the token or an error if the token literal does not | |
115 | // denote a valid float64. | |
116 | func (t *Token) Int64Value() (int64, error) { | |
117 | return strconv.ParseInt(string(t.Lit), 10, 64) | |
118 | } | |
119 | ||
120 | // UTF8Rune decodes the UTF8 rune in the token literal. It returns utf8.RuneError if | |
121 | // the token literal contains an invalid rune. | |
122 | func (t *Token) UTF8Rune() (rune, error) { | |
123 | r, _ := utf8.DecodeRune(t.Lit) | |
124 | if r == utf8.RuneError { | |
125 | err := fmt.Errorf("Invalid rune") | |
126 | return r, err | |
127 | } | |
128 | return r, nil | |
129 | } | |
130 | ||
131 | // StringValue returns the string value of the token literal. | |
132 | func (t *Token) StringValue() string { | |
133 | return string(t.Lit[1 : len(t.Lit)-1]) | |
57 | 134 | } |
58 | 135 | |
59 | 136 | var TokMap = TokenMap{ |
8 | 8 | "unicode/utf8" |
9 | 9 | ) |
10 | 10 | |
11 | /* Interface */ | |
11 | // Interface. | |
12 | 12 | |
13 | /* | |
14 | Convert the literal value of a scanned token to rune | |
15 | */ | |
13 | // RuneValue will convert the literal value of a scanned token to a rune. | |
16 | 14 | func RuneValue(lit []byte) rune { |
17 | 15 | if lit[1] == '\\' { |
18 | 16 | return escapeCharVal(lit) |
24 | 22 | return r |
25 | 23 | } |
26 | 24 | |
27 | /* | |
28 | Convert the literal value of a scanned token to int64 | |
29 | */ | |
25 | // UintValue will attempt to parse a byte-slice as a signed base-10 64-bit integer. | |
30 | 26 | func IntValue(lit []byte) (int64, error) { |
31 | 27 | return strconv.ParseInt(string(lit), 10, 64) |
32 | 28 | } |
33 | 29 | |
34 | /* | |
35 | Convert the literal value of a scanned token to uint64 | |
36 | */ | |
30 | // UintValue will attempt to parse a byte-slice as an unsigned base-10 64-bit integer. | |
37 | 31 | func UintValue(lit []byte) (uint64, error) { |
38 | 32 | return strconv.ParseUint(string(lit), 10, 64) |
39 | 33 | } |
40 | 34 | |
41 | /* Util */ | |
42 | ||
35 | // Helpers. | |
43 | 36 | func escapeCharVal(lit []byte) rune { |
44 | 37 | var i, base, max uint32 |
45 | 38 | offset := 2 |
68 | 68 | SupportingFunction:cluster_Supporting->CoreFunction:cluster_Core; |
69 | 69 | Hello->CoreFunction:cluster_Core; |
70 | 70 | subgraph cluster_Core { |
71 | CoreFunction; | |
72 | ||
73 | } | |
74 | ; | |
75 | subgraph cluster_Development { | |
76 | DevelopmentFunction; | |
77 | ||
78 | } | |
79 | ; | |
80 | subgraph cluster_Supporting { | |
81 | SupportingFunction; | |
82 | ||
83 | } | |
84 | ; | |
85 | Hello; | |
86 | World; | |
87 | ||
71 | CoreFunction; | |
72 | }; | |
73 | subgraph cluster_Development { | |
74 | DevelopmentFunction; | |
75 | }; | |
76 | subgraph cluster_Supporting { | |
77 | SupportingFunction; | |
78 | }; | |
79 | Hello; | |
80 | World; | |
88 | 81 | } |
89 | 82 | ` |
90 | 83 | |
101 | 94 | SupportingFunction:cluster_Supporting->CoreFunction:cluster_Core; |
102 | 95 | Hello->CoreFunction:cluster_Core; |
103 | 96 | subgraph cluster_Core { |
104 | CoreFunction; | |
105 | ||
106 | } | |
107 | ; | |
108 | subgraph cluster_Development { | |
109 | ||
110 | } | |
111 | ; | |
112 | subgraph cluster_Supporting { | |
113 | SupportingFunction; | |
114 | ||
115 | } | |
116 | ; | |
117 | Hello; | |
118 | World; | |
119 | ||
97 | CoreFunction; | |
98 | }; | |
99 | subgraph cluster_Development { | |
100 | ||
101 | }; | |
102 | subgraph cluster_Supporting { | |
103 | SupportingFunction; | |
104 | }; | |
105 | Hello; | |
106 | World; | |
120 | 107 | } |
121 | 108 | ` |
122 | 109 | if g.String() != expected { |
133 | 120 | expected = `digraph G { |
134 | 121 | SupportingFunction:cluster_Supporting->CoreFunction:cluster_Core; |
135 | 122 | subgraph cluster_Core { |
136 | CoreFunction; | |
137 | ||
138 | } | |
139 | ; | |
140 | subgraph cluster_Development { | |
141 | ||
142 | } | |
143 | ; | |
144 | subgraph cluster_Supporting { | |
145 | SupportingFunction; | |
146 | ||
147 | } | |
148 | ; | |
149 | ||
123 | CoreFunction; | |
124 | }; | |
125 | subgraph cluster_Development { | |
126 | ||
127 | }; | |
128 | subgraph cluster_Supporting { | |
129 | SupportingFunction; | |
130 | }; | |
150 | 131 | } |
151 | 132 | ` |
152 | 133 | if g.String() != expected { |
159 | 140 | |
160 | 141 | expected = `digraph G { |
161 | 142 | subgraph cluster_Core { |
162 | CoreFunction; | |
163 | ||
164 | } | |
165 | ; | |
166 | subgraph cluster_Development { | |
167 | ||
168 | } | |
169 | ; | |
170 | subgraph cluster_Supporting { | |
171 | ||
172 | } | |
173 | ; | |
174 | ||
143 | CoreFunction; | |
144 | }; | |
145 | subgraph cluster_Development { | |
146 | ||
147 | }; | |
148 | subgraph cluster_Supporting { | |
149 | ||
150 | }; | |
175 | 151 | } |
176 | 152 | ` |
177 | 153 | |
186 | 162 | expected = `digraph G { |
187 | 163 | subgraph cluster_Core { |
188 | 164 | |
189 | } | |
190 | ; | |
191 | subgraph cluster_Development { | |
192 | ||
193 | } | |
194 | ; | |
195 | subgraph cluster_Supporting { | |
196 | ||
197 | } | |
198 | ; | |
199 | ||
165 | }; | |
166 | subgraph cluster_Development { | |
167 | ||
168 | }; | |
169 | subgraph cluster_Supporting { | |
170 | ||
171 | }; | |
200 | 172 | } |
201 | 173 | ` |
202 | 174 | |
269 | 241 | Hello->CoreFunction:cluster_Core; |
270 | 242 | Hello->cluster_FooBar; |
271 | 243 | subgraph cluster_Core { |
272 | label=Core; | |
273 | CoreFunction; | |
274 | ||
275 | } | |
276 | ; | |
277 | subgraph cluster_Development { | |
278 | label=Development; | |
279 | DevelopmentFunction; | |
280 | ||
281 | } | |
282 | ; | |
244 | label=Core; | |
245 | CoreFunction; | |
246 | }; | |
247 | subgraph cluster_Development { | |
248 | label=Development; | |
249 | DevelopmentFunction; | |
250 | }; | |
283 | 251 | subgraph cluster_FooBar { |
284 | 252 | |
285 | } | |
286 | ; | |
287 | subgraph cluster_Supporting { | |
288 | label=Supporting; | |
289 | SupportingFunction; | |
290 | ||
291 | } | |
292 | ; | |
293 | Hello; | |
294 | World; | |
295 | ||
253 | }; | |
254 | subgraph cluster_Supporting { | |
255 | label=Supporting; | |
256 | SupportingFunction; | |
257 | }; | |
258 | Hello; | |
259 | World; | |
296 | 260 | } |
297 | 261 | ` |
298 | 262 | if g.String() != expected { |
309 | 273 | Hello->CoreFunction:cluster_Core; |
310 | 274 | Hello->cluster_FooBar; |
311 | 275 | subgraph cluster_Core { |
312 | label=Core; | |
313 | CoreFunction; | |
314 | ||
315 | } | |
316 | ; | |
276 | label=Core; | |
277 | CoreFunction; | |
278 | }; | |
317 | 279 | subgraph cluster_FooBar { |
318 | 280 | |
319 | } | |
320 | ; | |
321 | subgraph cluster_Supporting { | |
322 | label=Supporting; | |
323 | SupportingFunction; | |
324 | ||
325 | } | |
326 | ; | |
327 | Hello; | |
328 | World; | |
329 | ||
281 | }; | |
282 | subgraph cluster_Supporting { | |
283 | label=Supporting; | |
284 | SupportingFunction; | |
285 | }; | |
286 | Hello; | |
287 | World; | |
330 | 288 | } |
331 | 289 | ` |
332 | 290 | if g.String() != expected { |
342 | 300 | Hello->CoreFunction:cluster_Core; |
343 | 301 | Hello->cluster_FooBar; |
344 | 302 | subgraph cluster_Core { |
345 | label=Core; | |
346 | CoreFunction; | |
347 | ||
348 | } | |
349 | ; | |
303 | label=Core; | |
304 | CoreFunction; | |
305 | }; | |
350 | 306 | subgraph cluster_FooBar { |
351 | 307 | |
352 | } | |
353 | ; | |
354 | Hello; | |
355 | World; | |
356 | ||
308 | }; | |
309 | Hello; | |
310 | World; | |
357 | 311 | } |
358 | 312 | ` |
359 | 313 | if g.String() != expected { |
369 | 323 | Hello->cluster_FooBar; |
370 | 324 | subgraph cluster_FooBar { |
371 | 325 | |
372 | } | |
373 | ; | |
374 | Hello; | |
375 | World; | |
376 | ||
326 | }; | |
327 | Hello; | |
328 | World; | |
377 | 329 | } |
378 | 330 | ` |
379 | 331 | if g.String() != expected { |
388 | 340 | Hello->World; |
389 | 341 | Hello; |
390 | 342 | World; |
391 | ||
392 | } | |
393 | ` | |
394 | if g.String() != expected { | |
395 | t.Fatalf("output is not expected") | |
396 | } | |
397 | } | |
343 | } | |
344 | ` | |
345 | if g.String() != expected { | |
346 | t.Fatalf("output is not expected") | |
347 | } | |
348 | } |