-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathparse_selection.go
90 lines (77 loc) · 1.52 KB
/
parse_selection.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
package gqlyzer
import (
"fmt"
"github.com/kumparan/gqlyzer/token"
)
func (l *Lexer) parseSelection() (newSelection token.Selection, err error) {
if x := l.pop(); x != ',' && x != '\\' {
err = fmt.Errorf("expected separator, but got: %s", string(x))
return
}
name, err := l.parseName()
if err != nil {
return
}
newSelection.Name = name
arguments, argErr := l.parseArgumentSet()
if argErr == nil && len(arguments) > 0 {
newSelection.Arguments = arguments
l.cursor++
l.consumeWhitespace()
}
subSelection, subErr := l.parseSelectionSet()
if subErr == nil {
newSelection.InnerSelection = subSelection
}
return
}
func (l *Lexer) parseSelectionSet() (set token.SelectionSet, err error) {
set = make(token.SelectionSet)
l.consumeWhitespace()
c, err := l.read()
if err != nil {
return
}
if c == '{' {
l.push('{')
l.pushFlush()
if err != nil {
return
}
l.cursor++
l.consumeWhitespace()
c, err = l.read()
for err == nil && c != '}' {
if c == ',' {
l.push(c)
l.cursor++
l.consumeWhitespace()
c, err = l.read()
continue
}
selection, err := l.parseSelection()
if err != nil {
fmt.Print(set)
return token.SelectionSet{}, err
}
set[selection.Name] = selection
l.consumeWhitespace()
c, err = l.read()
if err != nil {
return token.SelectionSet{}, err
}
}
_, err = l.popFlush()
if err != nil {
return
}
err = l.popCond('{')
if err != nil {
return
}
} else {
return token.SelectionSet{}, nil
}
l.cursor++
return
}