Handle non-alpha chars in keys

This commit is contained in:
Thomas Pelletier
2013-12-10 19:46:56 +01:00
parent b1d602f733
commit 0c4e891f3e
2 changed files with 12 additions and 1 deletions
+3 -1
View File
@@ -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 {
+9
View File
@@ -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"},