Rename to lexer and split in files
This commit is contained in:
+100
@@ -0,0 +1,100 @@
|
||||
package toml
|
||||
|
||||
import "fmt"
|
||||
|
||||
type Document struct {
|
||||
}
|
||||
|
||||
type docParser struct {
|
||||
document Document
|
||||
}
|
||||
|
||||
func (d *docParser) ArrayTableBegin() {
|
||||
fmt.Println("ARRAY-TABLE[[")
|
||||
}
|
||||
|
||||
func (d *docParser) ArrayTableEnd() {
|
||||
fmt.Println("ARRAY-TABLE]]")
|
||||
}
|
||||
|
||||
func (d *docParser) StandardTableBegin() {
|
||||
fmt.Println("STD-TABLE[")
|
||||
}
|
||||
|
||||
func (d *docParser) StandardTableEnd() {
|
||||
fmt.Println("STD-TABLE]")
|
||||
}
|
||||
|
||||
func (d *docParser) InlineTableSeparator() {
|
||||
fmt.Println(", InlineTable SEPARATOR")
|
||||
}
|
||||
|
||||
func (d *docParser) InlineTableBegin() {
|
||||
fmt.Println("{ InlineTable BEGIN")
|
||||
}
|
||||
|
||||
func (d *docParser) InlineTableEnd() {
|
||||
fmt.Println("} InlineTable END")
|
||||
}
|
||||
|
||||
func (d *docParser) ArraySeparator() {
|
||||
fmt.Println(", ARRAY SEPARATOR")
|
||||
}
|
||||
|
||||
func (d *docParser) ArrayBegin() {
|
||||
fmt.Println("[ ARRAY BEGIN")
|
||||
}
|
||||
|
||||
func (d *docParser) ArrayEnd() {
|
||||
fmt.Println("] ARRAY END")
|
||||
}
|
||||
|
||||
func (d *docParser) Equal(b []byte) {
|
||||
s := string(b)
|
||||
fmt.Printf("EQUAL: '%s'\n", s)
|
||||
}
|
||||
|
||||
func (d *docParser) Boolean(b []byte) {
|
||||
s := string(b)
|
||||
fmt.Printf("Boolean: '%s'\n", s)
|
||||
}
|
||||
|
||||
func (d *docParser) Dot(b []byte) {
|
||||
s := string(b)
|
||||
fmt.Printf("DOT: '%s'\n", s)
|
||||
}
|
||||
|
||||
func (d *docParser) BasicString(b []byte) {
|
||||
s := string(b)
|
||||
fmt.Printf("BasicString: '%s'\n", s)
|
||||
}
|
||||
|
||||
func (d *docParser) LiteralString(b []byte) {
|
||||
s := string(b)
|
||||
fmt.Printf("LiteralString: '%s'\n", s)
|
||||
}
|
||||
|
||||
func (d *docParser) UnquotedKey(b []byte) {
|
||||
s := string(b)
|
||||
fmt.Printf("UnquotedKey: '%s'\n", s)
|
||||
}
|
||||
|
||||
func (d *docParser) Comment(b []byte) {
|
||||
s := string(b)
|
||||
fmt.Printf("Comment: '%s'\n", s)
|
||||
}
|
||||
|
||||
func (d *docParser) Whitespace(b []byte) {
|
||||
s := string(b)
|
||||
fmt.Printf("Whitespace: '%s'\n", s)
|
||||
}
|
||||
|
||||
func Parse(b []byte) (Document, error) {
|
||||
p := docParser{}
|
||||
l := lexer{parser: &p, data: b}
|
||||
err := l.run()
|
||||
if err != nil {
|
||||
return Document{}, err
|
||||
}
|
||||
return p.document, nil
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
package toml
|
||||
|
||||
func Unmarshal(data []byte, v interface{}) error {
|
||||
// TODO
|
||||
return nil
|
||||
}
|
||||
|
||||
func Marshal(v interface{}) ([]byte, error) {
|
||||
// TODO
|
||||
return nil, nil
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package toml
|
||||
|
||||
type parser interface {
|
||||
Whitespace(b []byte)
|
||||
Comment(b []byte)
|
||||
UnquotedKey(b []byte)
|
||||
LiteralString(b []byte)
|
||||
BasicString(b []byte)
|
||||
Dot(b []byte)
|
||||
Boolean(b []byte)
|
||||
Equal(b []byte)
|
||||
ArrayBegin()
|
||||
ArrayEnd()
|
||||
ArraySeparator()
|
||||
InlineTableBegin()
|
||||
InlineTableEnd()
|
||||
InlineTableSeparator()
|
||||
StandardTableBegin()
|
||||
StandardTableEnd()
|
||||
ArrayTableBegin()
|
||||
ArrayTableEnd()
|
||||
}
|
||||
@@ -59,7 +59,6 @@ val = string / boolean / array / inline-table / date-time / float / integer
|
||||
;; String
|
||||
|
||||
string = ml-basic-string / basic-string / ml-literal-string / literal-string
|
||||
|
||||
;; Basic String
|
||||
|
||||
basic-string = quotation-mark *basic-char quotation-mark
|
||||
|
||||
+22
-22
@@ -50,36 +50,36 @@ func TestParse(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
type noopBuilder struct {
|
||||
type noopParser struct {
|
||||
}
|
||||
|
||||
func (n noopBuilder) ArrayTableBegin() {}
|
||||
func (n noopBuilder) ArrayTableEnd() {}
|
||||
func (n noopBuilder) StandardTableBegin() {}
|
||||
func (n noopBuilder) StandardTableEnd() {}
|
||||
func (n noopBuilder) InlineTableSeparator() {}
|
||||
func (n noopBuilder) InlineTableBegin() {}
|
||||
func (n noopBuilder) InlineTableEnd() {}
|
||||
func (n noopBuilder) ArraySeparator() {}
|
||||
func (n noopBuilder) ArrayBegin() {}
|
||||
func (n noopBuilder) ArrayEnd() {}
|
||||
func (n noopBuilder) Whitespace(b []byte) {}
|
||||
func (n noopBuilder) Comment(b []byte) {}
|
||||
func (n noopBuilder) UnquotedKey(b []byte) {}
|
||||
func (n noopBuilder) LiteralString(b []byte) {}
|
||||
func (n noopBuilder) BasicString(b []byte) {}
|
||||
func (n noopBuilder) Dot(b []byte) {}
|
||||
func (n noopBuilder) Boolean(b []byte) {}
|
||||
func (n noopBuilder) Equal(b []byte) {}
|
||||
func (n noopParser) ArrayTableBegin() {}
|
||||
func (n noopParser) ArrayTableEnd() {}
|
||||
func (n noopParser) StandardTableBegin() {}
|
||||
func (n noopParser) StandardTableEnd() {}
|
||||
func (n noopParser) InlineTableSeparator() {}
|
||||
func (n noopParser) InlineTableBegin() {}
|
||||
func (n noopParser) InlineTableEnd() {}
|
||||
func (n noopParser) ArraySeparator() {}
|
||||
func (n noopParser) ArrayBegin() {}
|
||||
func (n noopParser) ArrayEnd() {}
|
||||
func (n noopParser) Whitespace(b []byte) {}
|
||||
func (n noopParser) Comment(b []byte) {}
|
||||
func (n noopParser) UnquotedKey(b []byte) {}
|
||||
func (n noopParser) LiteralString(b []byte) {}
|
||||
func (n noopParser) BasicString(b []byte) {}
|
||||
func (n noopParser) Dot(b []byte) {}
|
||||
func (n noopParser) Boolean(b []byte) {}
|
||||
func (n noopParser) Equal(b []byte) {}
|
||||
|
||||
func BenchmarkParseAll(b *testing.B) {
|
||||
b.ReportAllocs()
|
||||
|
||||
for i := 0; i < b.N; i++ {
|
||||
for _, data := range inputs {
|
||||
builder := noopBuilder{}
|
||||
p := parser{builder: &builder, data: []byte(data)}
|
||||
err := p.parse()
|
||||
p := noopParser{}
|
||||
l := lexer{parser: &p, data: []byte(data)}
|
||||
err := l.run()
|
||||
if err != nil {
|
||||
b.Fatalf("error: %s", err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user