let's just get rid of equals signs entirely

master
Jordan Orelli 10 years ago
parent 876794d694
commit 4e9169dda0

@ -25,8 +25,6 @@ func (t tokenType) String() string {
return "t_name" return "t_name"
case t_type: case t_type:
return "t_type" return "t_type"
case t_equals:
return "t_equals"
case t_comment: case t_comment:
return "t_comment" return "t_comment"
case t_list_start: case t_list_start:
@ -56,7 +54,6 @@ const (
t_string // a string literal t_string // a string literal
t_name // a name t_name // a name
t_type // a type t_type // a type
t_equals // equals sign
t_comment // a comment t_comment // a comment
t_list_start // [ t_list_start // [
t_list_end // ] t_list_end // ]
@ -189,9 +186,9 @@ func lexRoot(l *lexer) stateFn {
switch { switch {
case r == eof: case r == eof:
return nil return nil
case r == '=': case r == ':':
l.keep(r) l.keep(r)
l.emit(t_equals) l.emit(t_object_separator)
return lexRoot return lexRoot
case r == '"', r == '`': case r == '"', r == '`':
return lexStringLiteral(r) return lexStringLiteral(r)

@ -22,12 +22,12 @@ var primitivesTests = []struct {
{`Type`, []token{{t_type, "Type"}}}, {`Type`, []token{{t_type, "Type"}}},
{`CamelType`, []token{{t_type, "CamelType"}}}, {`CamelType`, []token{{t_type, "CamelType"}}},
{`Type_1_2`, []token{{t_type, "Type_1_2"}}}, {`Type_1_2`, []token{{t_type, "Type_1_2"}}},
{`=`, []token{{t_equals, "="}}}, {`:`, []token{{t_object_separator, ":"}}},
{` = `, []token{{t_equals, "="}}}, {` : `, []token{{t_object_separator, ":"}}},
{`"x" "y"`, []token{{t_string, "x"}, {t_string, "y"}}}, {`"x" "y"`, []token{{t_string, "x"}, {t_string, "y"}}},
{`x = "sam"`, []token{ {`x: "sam"`, []token{
{t_name, "x"}, {t_name, "x"},
{t_equals, "="}, {t_object_separator, ":"},
{t_string, "sam"}, {t_string, "sam"},
}}, }},
{`# this is a comment`, []token{{t_comment, " this is a comment"}}}, {`# this is a comment`, []token{{t_comment, " this is a comment"}}},

@ -105,7 +105,7 @@ func (n *assignmentNode) parse(p *parser) error {
return fmt.Errorf("parse error: saw lex error while parsing assignment node: %v", t.s) return fmt.Errorf("parse error: saw lex error while parsing assignment node: %v", t.s)
case t_eof: case t_eof:
return fmt.Errorf("parse error: unexpected eof in assignment node") return fmt.Errorf("parse error: unexpected eof in assignment node")
case t_equals: case t_object_separator:
default: default:
return fmt.Errorf("parse error: unexpected %v token after name, expected =", t.t) return fmt.Errorf("parse error: unexpected %v token after name, expected =", t.t)
} }

@ -22,7 +22,7 @@ var parseTests = []parseTest{
}, },
}, },
{ {
source: `name = "jordan"`, source: `name: "jordan"`,
root: &rootNode{ root: &rootNode{
children: []node{ children: []node{
&assignmentNode{"name", "jordan"}, &assignmentNode{"name", "jordan"},
@ -31,13 +31,13 @@ var parseTests = []parseTest{
}, },
{ {
source: ` source: `
hostname = "jordanorelli.com" hostname: "jordanorelli.com"
port = 9000 port: 9000
freq = 1e9 freq: 1e9
duty = 0.2 duty: 0.2
neg = -2 neg: -2
neg2 = -2.3 neg2: -2.3
imag = 1+2i imag: 1+2i
`, `,
root: &rootNode{ root: &rootNode{
children: []node{ children: []node{
@ -53,9 +53,9 @@ var parseTests = []parseTest{
}, },
{ {
source: ` source: `
first_name = "jordan" # yep, that's my name first_name: "jordan" # yep, that's my name
last_name = "orelli" # comments should be able to follow other shit last_name: "orelli" # comments should be able to follow other shit
`, `,
root: &rootNode{ root: &rootNode{
children: []node{ children: []node{
&assignmentNode{"first_name", "jordan"}, &assignmentNode{"first_name", "jordan"},
@ -67,8 +67,8 @@ var parseTests = []parseTest{
}, },
{ {
source: ` source: `
heroes = ["lina", "cm"] heroes: ["lina", "cm"]
`, `,
root: &rootNode{ root: &rootNode{
children: []node{ children: []node{
&assignmentNode{"heroes", list{"lina", "cm"}}, &assignmentNode{"heroes", list{"lina", "cm"}},
@ -77,8 +77,8 @@ var parseTests = []parseTest{
}, },
{ {
source: ` source: `
nested = [["one", "two"], ["three", "four"]] nested: [["one", "two"], ["three", "four"]]
`, `,
root: &rootNode{ root: &rootNode{
children: []node{ children: []node{
&assignmentNode{"nested", list{list{"one", "two"}, list{"three", "four"}}}, &assignmentNode{"nested", list{list{"one", "two"}, list{"three", "four"}}},
@ -87,11 +87,11 @@ var parseTests = []parseTest{
}, },
{ {
source: ` source: `
nested = [ nested: [
["one", "two"], ["one", "two"],
["three", "four"], ["three", "four"],
] ]
`, `,
root: &rootNode{ root: &rootNode{
children: []node{ children: []node{
&assignmentNode{"nested", list{list{"one", "two"}, list{"three", "four"}}}, &assignmentNode{"nested", list{list{"one", "two"}, list{"three", "four"}}},
@ -100,7 +100,7 @@ var parseTests = []parseTest{
}, },
{ {
source: ` source: `
admin = {first_name: "jordan", last_name: "orelli"} admin: {first_name: "jordan", last_name: "orelli"}
`, `,
root: &rootNode{ root: &rootNode{
children: []node{ children: []node{
@ -113,11 +113,11 @@ var parseTests = []parseTest{
}, },
{ {
source: ` source: `
http = { http: {
port: 9000, port: 9000,
routes: "/path/to/some/file", routes: "/path/to/some/file",
} }
`, `,
root: &rootNode{ root: &rootNode{
children: []node{ children: []node{
&assignmentNode{"http", object{ &assignmentNode{"http", object{

Loading…
Cancel
Save