@@ -4,9 +4,11 @@ import (
44 "os"
55
66 "github.com/alecthomas/kong"
7+
78 "github.com/alecthomas/participle"
89 "github.com/alecthomas/participle/lexer"
9- "github.com/alecthomas/participle/lexer/ebnf"
10+ "github.com/alecthomas/participle/lexer/stateful"
11+
1012 "github.com/alecthomas/repr"
1113)
1214
@@ -32,8 +34,7 @@ type Value struct {
3234 Date * string `| @Date`
3335 Time * string `| @Time`
3436 Bool * bool `| (@"true" | "false")`
35- Integer * int64 `| @Int`
36- Float * float64 `| @Float`
37+ Number * float64 `| @Number`
3738 List []* Value `| "[" [ @@ { "," @@ } ] "]"`
3839}
3940
@@ -43,28 +44,22 @@ type Section struct {
4344}
4445
4546var (
46- tomlLexer = lexer .Must (ebnf .New (`
47- Comment = "#" { "\u0000"…"\uffff"-"\n" } .
48- DateTime = date "T" time [ "-" digit digit ":" digit digit ].
49- Date = date .
50- Time = time .
51- Ident = (alpha | "_") { "_" | alpha | digit } .
52- String = "\"" { "\u0000"…"\uffff"-"\""-"\\" | "\\" any } "\"" .
53- Int = [ "-" | "+" ] digit { digit } .
54- Float = ("." | digit) {"." | digit} .
55- Punct = "!"…"/" | ":"…"@" | "["…` + "\" `\" " + ` | "{"…"~" .
56- Whitespace = " " | "\t" | "\n" | "\r" .
57-
58- alpha = "a"…"z" | "A"…"Z" .
59- digit = "0"…"9" .
60- any = "\u0000"…"\uffff" .
61- date = digit digit digit digit "-" digit digit "-" digit digit .
62- time = digit digit ":" digit digit ":" digit digit [ "." { digit } ] .
63- ` ))
47+ tomlLexer = lexer .Must (stateful .NewSimple ([]stateful.Rule {
48+ {"DateTime" , `\d\d\d\d-\d\d-\d\dT\d\d:\d\d:\d\d(\.\d+)?(-\d\d:\d\d)?` , nil },
49+ {"Date" , `\d\d\d\d-\d\d-\d\d` , nil },
50+ {"Time" , `\d\d:\d\d:\d\d(\.\d+)?` , nil },
51+ {"Ident" , `[a-zA-Z_][a-zA-Z_0-9]*` , nil },
52+ {"String" , `"[^"]*"` , nil },
53+ {"Number" , `[-+]?[.0-9]+\b` , nil },
54+ {"Punct" , `\[|]|[-!()+/*=,]` , nil },
55+ {"comment" , `#[^\n]+` , nil },
56+ {"whitespace" , `\s+` , nil },
57+ }))
6458 tomlParser = participle .MustBuild (& TOML {},
65- participle .Lexer (tomlLexer ),
59+ participle .Lexer (
60+ tomlLexer ,
61+ ),
6662 participle .Unquote ("String" ),
67- participle .Elide ("Whitespace" , "Comment" ),
6863 )
6964
7065 cli struct {
0 commit comments