From 53005a205f7722d6fccc5a42378dfa46cda8c0e0 Mon Sep 17 00:00:00 2001 From: Thomas Pelletier Date: Mon, 9 Dec 2013 17:12:07 +0100 Subject: [PATCH] Handle keys with dash. ref #10 --- lexer.go | 6 +++++- lexer_test.go | 7 +++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/lexer.go b/lexer.go index 09598ec..b70ff74 100644 --- a/lexer.go +++ b/lexer.go @@ -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) diff --git a/lexer_test.go b/lexer_test.go index f7ff7e1..9a98689 100644 --- a/lexer_test.go +++ b/lexer_test.go @@ -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"},