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

@ -22,12 +22,12 @@ var primitivesTests = []struct {
{`Type`, []token{{t_type, "Type"}}},
{`CamelType`, []token{{t_type, "CamelType"}}},
{`Type_1_2`, []token{{t_type, "Type_1_2"}}},
{`=`, []token{{t_equals, "="}}},
{` = `, []token{{t_equals, "="}}},
{`:`, []token{{t_object_separator, ":"}}},
{` : `, []token{{t_object_separator, ":"}}},
{`"x" "y"`, []token{{t_string, "x"}, {t_string, "y"}}},
{`x = "sam"`, []token{
{`x: "sam"`, []token{
{t_name, "x"},
{t_equals, "="},
{t_object_separator, ":"},
{t_string, "sam"},
}},
{`# 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)
case t_eof:
return fmt.Errorf("parse error: unexpected eof in assignment node")
case t_equals:
case t_object_separator:
default:
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{
children: []node{
&assignmentNode{"name", "jordan"},
@ -31,13 +31,13 @@ var parseTests = []parseTest{
},
{
source: `
hostname = "jordanorelli.com"
port = 9000
freq = 1e9
duty = 0.2
neg = -2
neg2 = -2.3
imag = 1+2i
hostname: "jordanorelli.com"
port: 9000
freq: 1e9
duty: 0.2
neg: -2
neg2: -2.3
imag: 1+2i
`,
root: &rootNode{
children: []node{
@ -53,9 +53,9 @@ var parseTests = []parseTest{
},
{
source: `
first_name = "jordan" # yep, that's my name
last_name = "orelli" # comments should be able to follow other shit
`,
first_name: "jordan" # yep, that's my name
last_name: "orelli" # comments should be able to follow other shit
`,
root: &rootNode{
children: []node{
&assignmentNode{"first_name", "jordan"},
@ -67,8 +67,8 @@ var parseTests = []parseTest{
},
{
source: `
heroes = ["lina", "cm"]
`,
heroes: ["lina", "cm"]
`,
root: &rootNode{
children: []node{
&assignmentNode{"heroes", list{"lina", "cm"}},
@ -77,8 +77,8 @@ var parseTests = []parseTest{
},
{
source: `
nested = [["one", "two"], ["three", "four"]]
`,
nested: [["one", "two"], ["three", "four"]]
`,
root: &rootNode{
children: []node{
&assignmentNode{"nested", list{list{"one", "two"}, list{"three", "four"}}},
@ -87,11 +87,11 @@ var parseTests = []parseTest{
},
{
source: `
nested = [
nested: [
["one", "two"],
["three", "four"],
]
`,
]
`,
root: &rootNode{
children: []node{
&assignmentNode{"nested", list{list{"one", "two"}, list{"three", "four"}}},
@ -100,7 +100,7 @@ var parseTests = []parseTest{
},
{
source: `
admin = {first_name: "jordan", last_name: "orelli"}
admin: {first_name: "jordan", last_name: "orelli"}
`,
root: &rootNode{
children: []node{
@ -113,11 +113,11 @@ var parseTests = []parseTest{
},
{
source: `
http = {
http: {
port: 9000,
routes: "/path/to/some/file",
}
`,
}
`,
root: &rootNode{
children: []node{
&assignmentNode{"http", object{

Loading…
Cancel
Save