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
|
||||||
|
|
||||||
string = ml-basic-string / basic-string / ml-literal-string / literal-string
|
string = ml-basic-string / basic-string / ml-literal-string / literal-string
|
||||||
|
|
||||||
;; Basic String
|
;; Basic String
|
||||||
|
|
||||||
basic-string = quotation-mark *basic-char quotation-mark
|
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 noopParser) ArrayTableBegin() {}
|
||||||
func (n noopBuilder) ArrayTableEnd() {}
|
func (n noopParser) ArrayTableEnd() {}
|
||||||
func (n noopBuilder) StandardTableBegin() {}
|
func (n noopParser) StandardTableBegin() {}
|
||||||
func (n noopBuilder) StandardTableEnd() {}
|
func (n noopParser) StandardTableEnd() {}
|
||||||
func (n noopBuilder) InlineTableSeparator() {}
|
func (n noopParser) InlineTableSeparator() {}
|
||||||
func (n noopBuilder) InlineTableBegin() {}
|
func (n noopParser) InlineTableBegin() {}
|
||||||
func (n noopBuilder) InlineTableEnd() {}
|
func (n noopParser) InlineTableEnd() {}
|
||||||
func (n noopBuilder) ArraySeparator() {}
|
func (n noopParser) ArraySeparator() {}
|
||||||
func (n noopBuilder) ArrayBegin() {}
|
func (n noopParser) ArrayBegin() {}
|
||||||
func (n noopBuilder) ArrayEnd() {}
|
func (n noopParser) ArrayEnd() {}
|
||||||
func (n noopBuilder) Whitespace(b []byte) {}
|
func (n noopParser) Whitespace(b []byte) {}
|
||||||
func (n noopBuilder) Comment(b []byte) {}
|
func (n noopParser) Comment(b []byte) {}
|
||||||
func (n noopBuilder) UnquotedKey(b []byte) {}
|
func (n noopParser) UnquotedKey(b []byte) {}
|
||||||
func (n noopBuilder) LiteralString(b []byte) {}
|
func (n noopParser) LiteralString(b []byte) {}
|
||||||
func (n noopBuilder) BasicString(b []byte) {}
|
func (n noopParser) BasicString(b []byte) {}
|
||||||
func (n noopBuilder) Dot(b []byte) {}
|
func (n noopParser) Dot(b []byte) {}
|
||||||
func (n noopBuilder) Boolean(b []byte) {}
|
func (n noopParser) Boolean(b []byte) {}
|
||||||
func (n noopBuilder) Equal(b []byte) {}
|
func (n noopParser) Equal(b []byte) {}
|
||||||
|
|
||||||
func BenchmarkParseAll(b *testing.B) {
|
func BenchmarkParseAll(b *testing.B) {
|
||||||
b.ReportAllocs()
|
b.ReportAllocs()
|
||||||
|
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
for _, data := range inputs {
|
for _, data := range inputs {
|
||||||
builder := noopBuilder{}
|
p := noopParser{}
|
||||||
p := parser{builder: &builder, data: []byte(data)}
|
l := lexer{parser: &p, data: []byte(data)}
|
||||||
err := p.parse()
|
err := l.run()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
b.Fatalf("error: %s", err)
|
b.Fatalf("error: %s", err)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user