Inline tables
This commit is contained in:
@@ -30,6 +30,9 @@ type builder interface {
|
||||
ArrayBegin()
|
||||
ArrayEnd()
|
||||
ArraySeparator()
|
||||
InlineTableBegin()
|
||||
InlineTableEnd()
|
||||
InlineTableSeparator()
|
||||
}
|
||||
|
||||
type position struct {
|
||||
@@ -41,6 +44,18 @@ type documentBuilder struct {
|
||||
document Document
|
||||
}
|
||||
|
||||
func (d *documentBuilder) InlineTableSeparator() {
|
||||
fmt.Println(", InlineTable SEPARATOR")
|
||||
}
|
||||
|
||||
func (d *documentBuilder) InlineTableBegin() {
|
||||
fmt.Println("{ InlineTable BEGIN")
|
||||
}
|
||||
|
||||
func (d *documentBuilder) InlineTableEnd() {
|
||||
fmt.Println("} InlineTable END")
|
||||
}
|
||||
|
||||
func (d *documentBuilder) ArraySeparator() {
|
||||
fmt.Println(", ARRAY SEPARATOR")
|
||||
}
|
||||
@@ -358,12 +373,81 @@ func (p *parser) parseVal() error {
|
||||
return p.parseString()
|
||||
case '[':
|
||||
return p.parseArray()
|
||||
case '{':
|
||||
return p.parseInlineTable()
|
||||
// TODO
|
||||
default:
|
||||
return &InvalidCharacter{r: r}
|
||||
}
|
||||
}
|
||||
|
||||
func (p *parser) parseInlineTable() error {
|
||||
//inline-table = inline-table-open [ inline-table-keyvals ] inline-table-close
|
||||
//
|
||||
//inline-table-open = %x7B ws ; {
|
||||
// inline-table-close = ws %x7D ; }
|
||||
//inline-table-sep = ws %x2C ws ; , Comma
|
||||
//
|
||||
//inline-table-keyvals = keyval [ inline-table-sep inline-table-keyvals ]
|
||||
|
||||
err := p.expect('{')
|
||||
if err != nil {
|
||||
panic("inline tables should start with {")
|
||||
}
|
||||
p.ignore()
|
||||
p.builder.InlineTableBegin()
|
||||
|
||||
err = p.parseWhitespace()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
r := p.peek()
|
||||
if r == '}' {
|
||||
p.next()
|
||||
p.ignore()
|
||||
p.builder.InlineTableEnd()
|
||||
return nil
|
||||
}
|
||||
|
||||
err = p.parseKeyval()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for {
|
||||
err = p.parseWhitespace()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
r := p.peek()
|
||||
if r == '}' {
|
||||
p.next()
|
||||
p.ignore()
|
||||
p.builder.InlineTableEnd()
|
||||
return nil
|
||||
}
|
||||
|
||||
err := p.expect(',')
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
p.builder.InlineTableSeparator()
|
||||
p.ignore()
|
||||
|
||||
err = p.parseWhitespace()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = p.parseKeyval()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (p *parser) parseArray() error {
|
||||
//array = array-open [ array-values ] ws-comment-newline array-close
|
||||
|
||||
@@ -371,6 +455,7 @@ func (p *parser) parseArray() error {
|
||||
if err != nil {
|
||||
panic("arrays should start with [")
|
||||
}
|
||||
p.ignore()
|
||||
|
||||
p.builder.ArrayBegin()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user