File tree 2 files changed +28
-1
lines changed
2 files changed +28
-1
lines changed Original file line number Diff line number Diff line change @@ -36,7 +36,7 @@ func (p *Parser) Parse() *graph.Graph {
36
36
for p .currentToken .Type != END {
37
37
ast .AddVertex (graph.Vertex {
38
38
Id : uint64 (p .position + 1 ),
39
- Label : fmt . Sprint ( p .currentToken .Type ),
39
+ Label : p .currentToken .String ( ),
40
40
})
41
41
p .readToken ()
42
42
}
Original file line number Diff line number Diff line change 1
1
package query
2
2
3
+ import "fmt"
4
+
3
5
const (
4
6
TERM = iota
5
7
AND
@@ -18,3 +20,28 @@ type Token struct {
18
20
Type TokenType
19
21
Value string
20
22
}
23
+
24
+ func (t * Token ) String () string {
25
+ switch t .Type {
26
+ case TERM :
27
+ return "TERM"
28
+ case AND :
29
+ return "AND"
30
+ case OR :
31
+ return "OR"
32
+ case NOT :
33
+ return "NOT"
34
+ case LEFT_BRACKET :
35
+ return "("
36
+ case RIGHT_BRACKET :
37
+ return ")"
38
+ case SINGLE_QUOTE :
39
+ return "'"
40
+ case DOUBLE_QUOTE :
41
+ return "\" "
42
+ case END :
43
+ return "END"
44
+ default :
45
+ panic (fmt .Sprintf ("Unknown token: %d" , t .Type ))
46
+ }
47
+ }
You can’t perform that action at this time.
0 commit comments