-
Notifications
You must be signed in to change notification settings - Fork 0
/
lexer.go
35 lines (33 loc) · 787 Bytes
/
lexer.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
package parser
import (
"github.com/alecthomas/participle/v2/lexer"
)
var atLexer = lexer.MustStateful(lexer.Rules{
"Root": {
{"AT", "AT", lexer.Push("Commands")},
},
"Commands": {
{"CommandName", "[^?=;]+", lexer.Push("Command")},
},
"Command": {
{"TestModifier", "=\\?", nil},
{"ReadModifier", "\\?", nil},
{"SetModifier", "=", lexer.Push("SetCommand")},
{"CommandSeparator", ";", lexer.Pop()},
},
"SetCommand": {
{"quotedStringStart", `"`, lexer.Push("QuotedString")},
{"ValueSeparator", ",", nil},
lexer.Include("String"),
},
"String": {
{"Escaped", `\\.`, nil},
{"Chars", `[^",;\\]+`, nil},
lexer.Return(),
},
"QuotedString": {
{"QuotedEscaped", `\\.`, nil},
{"quotedStringEnd", `"`, lexer.Pop()},
{"QuotedChars", `[^"\\]+`, nil},
},
})