From 0c4e891f3e967ca58b7df1951a642799765bb403 Mon Sep 17 00:00:00 2001 From: Thomas Pelletier Date: Tue, 10 Dec 2013 19:46:56 +0100 Subject: [PATCH] Handle non-alpha chars in keys --- lexer.go | 4 +++- lexer_test.go | 9 +++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/lexer.go b/lexer.go index 91f93c9..5efbf6b 100644 --- a/lexer.go +++ b/lexer.go @@ -68,7 +68,9 @@ func isAlphanumeric(r rune) bool { } func isKeyChar(r rune) bool { - return isAlphanumeric(r) || r == '-' + // "Keys start with the first non-whitespace character and end with the last + // non-whitespace character before the equals sign." + return !(isSpace(r) || r == '\n' || r == eof || r == '=') } func isDigit(r rune) bool { diff --git a/lexer_test.go b/lexer_test.go index 1d7e37b..6436378 100644 --- a/lexer_test.go +++ b/lexer_test.go @@ -113,6 +113,15 @@ func TestBasicKeyAndEqual(t *testing.T) { }) } +func TestKeyWithSharpAndEqual(t *testing.T) { + testFlow(t, "key#name = 5", []token{ + token{tokenKey, "key#name"}, + token{tokenEqual, "="}, + token{tokenInteger, "5"}, + token{tokenEOF, ""}, + }) +} + func TestKeyEqualStringEscape(t *testing.T) { testFlow(t, "foo = \"hello\\\"\"", []token{ token{tokenKey, "foo"},