Handle keys with dash. ref #10

This commit is contained in:
Thomas Pelletier
2013-12-09 17:12:07 +01:00
parent 34d60ec92f
commit 53005a205f
2 changed files with 12 additions and 1 deletions
+5 -1
View File
@@ -67,6 +67,10 @@ func isAlphanumeric(r rune) bool {
return unicode.IsLetter(r) || r == '_'
}
func isKeyChar(r rune) bool {
return isAlphanumeric(r) || r == '-'
}
func isDigit(r rune) bool {
return unicode.IsNumber(r)
}
@@ -276,7 +280,7 @@ func lexComma(l *lexer) stateFn {
func lexKey(l *lexer) stateFn {
l.ignore()
for isAlphanumeric(l.next()) {
for isKeyChar(l.next()) {
}
l.backup()
l.emit(tokenKey)
+7
View File
@@ -84,6 +84,13 @@ func TestBasicKeyWithUnderscore(t *testing.T) {
})
}
func TestBasicKeyWithDash(t *testing.T) {
testFlow(t, "hello-world", []token{
token{tokenKey, "hello-world"},
token{tokenEOF, ""},
})
}
func TestBasicKeyWithUppercaseMix(t *testing.T) {
testFlow(t, "helloHELLOHello", []token{
token{tokenKey, "helloHELLOHello"},