-
Notifications
You must be signed in to change notification settings - Fork 1
/
parse_value.go
59 lines (50 loc) · 926 Bytes
/
parse_value.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
package gqlyzer
import "errors"
// temporary immplementation to parse value such as number, enum etc
func (l *Lexer) parseOtherAsString() (value string, err error) {
l.pushFlush()
c, err := l.read()
for err == nil &&
!isWhitespace(c) &&
c != ')' &&
c != ',' &&
c != '}' {
l.push(c)
l.cursor++
c, err = l.read()
}
return l.popFlush()
}
func (l *Lexer) parseString() (value string, err error) {
c, err := l.read()
if err != nil {
return
}
if c == '\'' || c == '"' {
l.push(c)
} else {
err = errors.New("value is not a string")
return
}
l.pushFlush()
l.cursor++
c, err = l.read()
for err == nil &&
!isWhitespace(c) &&
c != '\'' &&
c != '"' {
l.push(c)
l.cursor++
c, err = l.read()
}
content, err := l.popFlush()
if err != nil {
return
}
if c != l.pop() {
err = errors.New("no " + string(c) + " found")
return
}
l.cursor++
return `"` + content + `"`, nil
}