Standard Table
This commit is contained in:
@@ -33,6 +33,8 @@ type builder interface {
|
|||||||
InlineTableBegin()
|
InlineTableBegin()
|
||||||
InlineTableEnd()
|
InlineTableEnd()
|
||||||
InlineTableSeparator()
|
InlineTableSeparator()
|
||||||
|
StandardTableBegin()
|
||||||
|
StandardTableEnd()
|
||||||
}
|
}
|
||||||
|
|
||||||
type position struct {
|
type position struct {
|
||||||
@@ -44,6 +46,14 @@ type documentBuilder struct {
|
|||||||
document Document
|
document Document
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (d *documentBuilder) StandardTableBegin() {
|
||||||
|
fmt.Println("STD-TABLE[")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *documentBuilder) StandardTableEnd() {
|
||||||
|
fmt.Println("STD-TABLE]")
|
||||||
|
}
|
||||||
|
|
||||||
func (d *documentBuilder) InlineTableSeparator() {
|
func (d *documentBuilder) InlineTableSeparator() {
|
||||||
fmt.Println(", InlineTable SEPARATOR")
|
fmt.Println(", InlineTable SEPARATOR")
|
||||||
}
|
}
|
||||||
@@ -290,6 +300,10 @@ func (p *parser) parseRequiredNewline() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (p *parser) parseExpression() error {
|
func (p *parser) parseExpression() error {
|
||||||
|
//expression = ws [ comment ]
|
||||||
|
//expression =/ ws keyval ws [ comment ]
|
||||||
|
//expression =/ ws table ws [ comment ]
|
||||||
|
|
||||||
err := p.parseWhitespace()
|
err := p.parseWhitespace()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -305,12 +319,11 @@ 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
|
err := p.parseTable()
|
||||||
}
|
if err != nil {
|
||||||
|
return err
|
||||||
// it has to be a keyval
|
}
|
||||||
|
} else if isUnquotedKeyRune(r) || r == '\'' || r == '"' {
|
||||||
if isUnquotedKeyRune(r) || r == '\'' || r == '"' {
|
|
||||||
err := p.parseKeyval()
|
err := p.parseKeyval()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -844,3 +857,67 @@ func (p *parser) parseBasicString() error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (p *parser) parseTable() error {
|
||||||
|
//;; Table
|
||||||
|
//
|
||||||
|
//table = std-table / array-table
|
||||||
|
//
|
||||||
|
//;; Standard Table
|
||||||
|
//
|
||||||
|
//std-table = std-table-open key std-table-close
|
||||||
|
//
|
||||||
|
//std-table-open = %x5B ws ; [ Left square bracket
|
||||||
|
//std-table-close = ws %x5D ; ] Right square bracket
|
||||||
|
//
|
||||||
|
//;; 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
|
||||||
|
|
||||||
|
if p.follows("[[") {
|
||||||
|
panic("TODO") // TODO: array-table
|
||||||
|
}
|
||||||
|
|
||||||
|
return p.parseStandardTable()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *parser) parseStandardTable() error {
|
||||||
|
//;; Standard Table
|
||||||
|
//
|
||||||
|
//std-table = std-table-open key std-table-close
|
||||||
|
//
|
||||||
|
//std-table-open = %x5B ws ; [ Left square bracket
|
||||||
|
//std-table-close = ws %x5D ; ] Right square bracket
|
||||||
|
|
||||||
|
err := p.expect('[')
|
||||||
|
if err != nil {
|
||||||
|
panic("std-table should start with [")
|
||||||
|
}
|
||||||
|
p.ignore()
|
||||||
|
p.builder.StandardTableBegin()
|
||||||
|
|
||||||
|
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
|
||||||
|
}
|
||||||
|
p.ignore()
|
||||||
|
p.builder.StandardTableEnd()
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|||||||
@@ -31,6 +31,11 @@ var inputs = []string{
|
|||||||
`d = ["foo", "test"]`,
|
`d = ["foo", "test"]`,
|
||||||
`d = {}`,
|
`d = {}`,
|
||||||
`e = {f = "bar"}`,
|
`e = {f = "bar"}`,
|
||||||
|
`[foo]`,
|
||||||
|
`[ test ]`,
|
||||||
|
`[ "hello".world ]`,
|
||||||
|
`[test]
|
||||||
|
a = false`,
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestParse(t *testing.T) {
|
func TestParse(t *testing.T) {
|
||||||
@@ -47,6 +52,8 @@ func TestParse(t *testing.T) {
|
|||||||
type noopBuilder struct {
|
type noopBuilder struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (n noopBuilder) StandardTableBegin() {}
|
||||||
|
func (n noopBuilder) StandardTableEnd() {}
|
||||||
func (n noopBuilder) InlineTableSeparator() {}
|
func (n noopBuilder) InlineTableSeparator() {}
|
||||||
func (n noopBuilder) InlineTableBegin() {}
|
func (n noopBuilder) InlineTableBegin() {}
|
||||||
func (n noopBuilder) InlineTableEnd() {}
|
func (n noopBuilder) InlineTableEnd() {}
|
||||||
|
|||||||
Reference in New Issue
Block a user