diff --git a/parse2/grammar.go b/parse2/grammar.go index 0d0a23f..fb1ea49 100644 --- a/parse2/grammar.go +++ b/parse2/grammar.go @@ -41,7 +41,7 @@ func (g Grammar) Get(name string) tokenize.Handler { if handler, ok := g[name]; ok { return handler } - return func(t *tokenize.API) bool { + return func(t tokenize.API) bool { if handler, ok := g[name]; ok { return handler(t) } @@ -110,6 +110,7 @@ func BuildGrammar() tokenize.Handler { m.Drop(G("ml-basic-string-delim")))) // Literal String + R("literal-char", c.Any(G("tab"), a.RuneRange(0x20, 0x26), a.RuneRange(0x28, 0x7E), G("non-ascii"))) R("literal-string", c.Seq( m.Drop(G("apostrophe")), @@ -177,7 +178,7 @@ func BuildGrammar() tokenize.Handler { R("float", c.Any( tok.Float64("float", G("standard-float")), - tok.ByCallback("float", G("inf-float"), func(t *tokenize.API) interface{} { + tok.ByCallback("float", G("inf-float"), func(t tokenize.API) interface{} { if t.Result().Rune(0) == '-' { return math.Inf(-1) } @@ -220,7 +221,7 @@ func BuildGrammar() tokenize.Handler { R("local-date", G("date")) R("local-time", G("time")) - makeDateTimeValue := func(t *tokenize.API) interface{} { + makeDateTimeValue := func(t tokenize.API) interface{} { layout := "" input := "" for _, t := range t.Result().Tokens() { @@ -244,16 +245,18 @@ func BuildGrammar() tokenize.Handler { // Inline Table R("inline-table-open", a.CurlyOpen.Then(G("ws"))) - R("inline-table-close", G("ws").Then(a.CurlyClose)) R("inline-table-sep", c.Seq(G("ws"), a.Comma, G("ws"))) - R("inline-table-keyvals", c.Seq(G("keyval"), c.ZeroOrMore(c.Seq(G("inline-table-sep"), G("keyval"))))) + R("inline-table-keyvals", c.Separated(G("inline-table-sep"), G("keyval"))) + R("inline-table-close", G("ws").Then(a.CurlyClose)) - R("inline-table", tok.Group("inline-table", c.Seq(G("inline-table-open"), G("inline-table-keyvals"), G("inline-table-close")))) + R("inline-table", tok.Group("inline-table", c.Seq( + G("inline-table-open"), + G("inline-table-keyvals"), + G("inline-table-close")))) - // Array + // Inline Array R("array-open", a.SquareOpen) - R("array-close", a.SquareClose) R("array-sep", G("ws").Then(a.Comma)) R("ws-comment-newline", c.ZeroOrMore(G("whitespaceChar").Or(G("comment").Optional().Then(G("newline"))))) R("array-values", c.Seq( @@ -261,6 +264,7 @@ func BuildGrammar() tokenize.Handler { G("val"), c.ZeroOrMore(c.Seq(G("ws"), G("array-sep"), G("ws-comment-newline"), G("val"))), G("array-sep").Optional())) + R("array-close", a.SquareClose) R("inline-array", tok.Group("array", c.Seq(G("array-open"), G("array-values").Optional(), G("ws-comment-newline"), G("array-close")))) @@ -288,13 +292,21 @@ func BuildGrammar() tokenize.Handler { R("quoted-key", G("basic-string").Or(G("literal-string"))) R("key-sep", c.Seq(G("ws"), a.Dot, G("ws"))) R("simple-key", tok.Str("key-part", G("quoted-key").Or(G("unquoted-key")))) - R("dotted-key", c.Separated(G("simple-key"), G("key-sep"))) + R("dotted-key", c.Separated(G("key-sep"), G("simple-key"))) R("key", c.FlushInput(tok.Group("key", G("dotted-key").Or(G("simple-key"))))) R("keyval-sep", c.FlushInput(c.Seq(G("ws"), a.Equal, G("ws")))) - R("val", c.FlushInput(tok.Group("val", c.Any(G("string"), G("boolean"), G("inline-array"), G("inline-table"), G("date-time"), G("float"), G("integer"))))) + R("val", tok.Group("val", c.Any( + G("string"), + G("date-time"), + G("float"), + G("integer"), + G("boolean"), + G("inline-array"), + G("inline-table"), + ))) R("keyval", tok.Group("keyval", c.Seq(G("key"), G("keyval-sep"), G("val")))) diff --git a/parse2/parse2 b/parse2/parse2 index 707c31f..3bac932 100755 Binary files a/parse2/parse2 and b/parse2/parse2 differ diff --git a/parse2/profile.sh b/parse2/profile.sh index 240ecaa..86a638f 100755 --- a/parse2/profile.sh +++ b/parse2/profile.sh @@ -1,6 +1,19 @@ #!/bin/bash +#cd $GOPATH/src/git.makaay.nl/mauricem/go-toml/cmd/burntsushi-tester/ +#go build +#go install +#cd $GOPATH/src/git.makaay.nl/mauricem/go-toml/parse2 +#PPFILE=`cat long.toml | $GOPATH/bin/burntsushi-tester 2>&1 | grep "profiling enabled" | cut -d, -f2` +#echo $PPFILE + +#ppfile=` | ./parse2 2>&1 | grep "cpu profiling enabled" | cut -d, -f2` + +echo "Building ..." go build -ppfile=`cat long.toml | ./parse2 2>&1 | grep "cpu profiling enabled" | cut -d, -f2` -#ppfile=`cat short.toml | ./parse2 2>&1 | grep "cpu profiling enabled" | cut -d, -f2` +echo "Running ..." +time cat long.toml | ./parse2 2>&1 +echo "Profiling ..." +ppfile=`cat long.toml | time ./parse2 2>&1 | grep "cpu profiling enabled" | cut -d, -f2` go tool pprof -http 0.0.0.0:8888 ./parse2 $ppfile + diff --git a/parse2/short.toml b/parse2/short.toml index 32e581c..9129f2b 100644 --- a/parse2/short.toml +++ b/parse2/short.toml @@ -1,3 +1 @@ -a=1 -b=2 -c=3 +c=[1]