From 4e9169dda06da59bb7135226ae38d85737aeefb2 Mon Sep 17 00:00:00 2001 From: Jordan Orelli Date: Sun, 22 Mar 2015 21:50:59 -0400 Subject: [PATCH] let's just get rid of equals signs entirely --- lex.go | 7 ++----- lex_test.go | 8 ++++---- node.go | 2 +- parse_test.go | 44 ++++++++++++++++++++++---------------------- 4 files changed, 29 insertions(+), 32 deletions(-) diff --git a/lex.go b/lex.go index 93abc4f..f726c36 100644 --- a/lex.go +++ b/lex.go @@ -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) diff --git a/lex_test.go b/lex_test.go index 74daad6..6c0368e 100644 --- a/lex_test.go +++ b/lex_test.go @@ -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"}}}, diff --git a/node.go b/node.go index 932615c..5ab6b6c 100644 --- a/node.go +++ b/node.go @@ -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) } diff --git a/parse_test.go b/parse_test.go index 88866e8..4920b4a 100644 --- a/parse_test.go +++ b/parse_test.go @@ -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{