Dotted keys

This commit is contained in:
Thomas Pelletier
2021-02-01 19:07:51 -05:00
parent 07aa85ea0b
commit 1c7e9fe3af
2 changed files with 45 additions and 2 deletions
+43 -2
View File
@@ -24,6 +24,7 @@ type builder interface {
UnquotedKey(b []byte) UnquotedKey(b []byte)
LiteralString(b []byte) LiteralString(b []byte)
BasicString(b []byte) BasicString(b []byte)
Dot(b []byte)
} }
type position struct { type position struct {
@@ -35,6 +36,11 @@ type documentBuilder struct {
document Document document Document
} }
func (d *documentBuilder) Dot(b []byte) {
s := string(b)
fmt.Printf("DOT: '%s'\n", s)
}
func (d *documentBuilder) BasicString(b []byte) { func (d *documentBuilder) BasicString(b []byte) {
s := string(b) s := string(b)
fmt.Printf("BasicString: '%s'\n", s) fmt.Printf("BasicString: '%s'\n", s)
@@ -230,6 +236,7 @@ func (p *parser) parseExpression() error {
// or line with something? // or line with something?
if r == '[' { if r == '[' {
// parse table. could be either a standard table or an array table // parse table. could be either a standard table or an array table
// TODO
} }
// it has to be a keyval // it has to be a keyval
@@ -271,9 +278,43 @@ func (p *parser) parseKeyval() error {
func (p *parser) parseKey() error { func (p *parser) parseKey() error {
// simple-key / dotted-key // simple-key / dotted-key
// dotted-key = simple-key 1*( dot-sep simple-key ) // dotted-key = simple-key 1*( dot-sep simple-key )
// dot-sep = ws %x2E ws
return p.parseSimpleKey() for {
// TODO: dotted key err := p.parseSimpleKey()
if err != nil {
return err
}
err = p.parseWhitespace()
if err != nil {
return err
}
r, err := p.peek()
if err != nil {
return err
}
if r != '.' {
break
}
p.sureNext()
p.builder.Dot(p.accept())
err = p.parseWhitespace()
if err != nil {
return err
}
}
err := p.parseWhitespace()
if err != nil {
return err
}
return nil
} }
func isUnquotedKeyRune(r rune) bool { func isUnquotedKeyRune(r rune) bool {
+2
View File
@@ -22,6 +22,8 @@ func TestParse(t *testing.T) {
`"foo bar"`, `"foo bar"`,
`"hello\tworld"`, `"hello\tworld"`,
`"hello \u1234 foo"`, `"hello \u1234 foo"`,
`a.b.c`,
`a."b".c`,
} }
for i, data := range inputs { for i, data := range inputs {