MCPcopy
hub / github.com/kashav/fsql / Next

Method Next

tokenizer/tokenizer.go:19–130  ·  view source on GitHub ↗

Next finds and returns the next Token in the input string.

()

Source from the content-addressed store, hash-verified

17
18// Next finds and returns the next Token in the input string.
19func (t *Tokenizer) Next() *Token {
20 for unicode.IsSpace(t.current()) {
21 t.input = t.input[1:]
22 }
23
24 current := t.current()
25 if current == -1 {
26 return nil
27 }
28
29 switch current {
30 case '(':
31 t.input = t.input[1:]
32 return t.setToken(&Token{Type: OpenParen, Raw: "("})
33 case ')':
34 t.input = t.input[1:]
35 return t.setToken(&Token{Type: CloseParen, Raw: ")"})
36 case '[':
37 t.input = t.input[1:]
38 return t.setToken(&Token{Type: OpenBracket, Raw: "["})
39 case ']':
40 t.input = t.input[1:]
41 return t.setToken(&Token{Type: CloseBracket, Raw: "]"})
42 case ',':
43 t.input = t.input[1:]
44 return t.setToken(&Token{Type: Comma, Raw: ","})
45 case '-':
46 t.input = t.input[1:]
47 return t.setToken(&Token{Type: Hyphen, Raw: "-"})
48 case '!':
49 if t.getRuneAt(1) == '=' {
50 t.input = t.input[2:]
51 return t.setToken(&Token{Type: NotEquals, Raw: "!="})
52 }
53 return t.setToken(&Token{Type: ExclamationMark, Raw: "!"})
54 case '=':
55 t.input = t.input[1:]
56 return t.setToken(&Token{Type: Equals, Raw: "="})
57 case '>':
58 if t.getRuneAt(1) == '=' {
59 t.input = t.input[2:]
60 return t.setToken(&Token{Type: GreaterThanEquals, Raw: ">="})
61 }
62 t.input = t.input[1:]
63 return t.setToken(&Token{Type: GreaterThan, Raw: ">"})
64 case '<':
65 if t.getRuneAt(1) == '=' {
66 t.input = t.input[2:]
67 return t.setToken(&Token{Type: LessThanEquals, Raw: "<="})
68 }
69 if t.getRuneAt(1) == '>' {
70 t.input = t.input[2:]
71 return t.setToken(&Token{Type: NotEquals, Raw: "<>"})
72 }
73 t.input = t.input[1:]
74 return t.setToken(&Token{Type: LessThan, Raw: "<"})
75 }
76

Callers 6

AllMethod · 0.95
expectMethod · 0.80
parseConditionTreeMethod · 0.80
parseConditionMethod · 0.80
TestTokenizer_NextRawFunction · 0.80

Calls 9

currentMethod · 0.95
setTokenMethod · 0.95
getRuneAtMethod · 0.95
currentIsMethod · 0.95
readWordMethod · 0.95
getPreviousTokenMethod · 0.95
getTokenAtMethod · 0.95
readQueryMethod · 0.95
readUntilMethod · 0.95

Tested by 2

TestTokenizer_NextRawFunction · 0.64