Array tables

This commit is contained in:
Thomas Pelletier
2021-02-02 08:19:04 -05:00
parent aae4656c64
commit 7300b6a97b
2 changed files with 59 additions and 1 deletions
+56 -1
View File
@@ -35,6 +35,8 @@ type builder interface {
InlineTableSeparator()
StandardTableBegin()
StandardTableEnd()
ArrayTableBegin()
ArrayTableEnd()
}
type position struct {
@@ -46,6 +48,14 @@ type documentBuilder struct {
document Document
}
func (d *documentBuilder) ArrayTableBegin() {
fmt.Println("ARRAY-TABLE[[")
}
func (d *documentBuilder) ArrayTableEnd() {
fmt.Println("ARRAY-TABLE]]")
}
func (d *documentBuilder) StandardTableBegin() {
fmt.Println("STD-TABLE[")
}
@@ -878,12 +888,57 @@ func (p *parser) parseTable() error {
//array-table-close = ws %x5D.5D ; ]] Double right square bracket
if p.follows("[[") {
panic("TODO") // TODO: array-table
return p.parseArrayTable()
}
return p.parseStandardTable()
}
func (p *parser) parseArrayTable() error {
//;; Array Table
//
//array-table = array-table-open key array-table-close
//
//array-table-open = %x5B.5B ws ; [[ Double left square bracket
//array-table-close = ws %x5D.5D ; ]] Double right square bracket
err := p.expect('[')
if err != nil {
return err
}
err = p.expect('[')
if err != nil {
return err
}
p.ignore()
p.builder.ArrayTableBegin()
err = p.parseWhitespace()
if err != nil {
return err
}
err = p.parseKey()
if err != nil {
return err
}
err = p.parseWhitespace()
if err != nil {
return err
}
err = p.expect(']')
if err != nil {
return err
}
err = p.expect(']')
if err != nil {
return err
}
p.ignore()
p.builder.ArrayTableEnd()
return nil
}
func (p *parser) parseStandardTable() error {
//;; Standard Table
//
+3
View File
@@ -36,6 +36,7 @@ var inputs = []string{
`[ "hello".world ]`,
`[test]
a = false`,
`[[foo]]`,
}
func TestParse(t *testing.T) {
@@ -52,6 +53,8 @@ func TestParse(t *testing.T) {
type noopBuilder struct {
}
func (n noopBuilder) ArrayTableBegin() {}
func (n noopBuilder) ArrayTableEnd() {}
func (n noopBuilder) StandardTableBegin() {}
func (n noopBuilder) StandardTableEnd() {}
func (n noopBuilder) InlineTableSeparator() {}