From c66d0847fa09aac8e5f885c684f35babd5901e14 Mon Sep 17 00:00:00 2001 From: brettlangdon Date: Sun, 9 Aug 2015 17:10:55 -0400 Subject: [PATCH] Allow integers in identifiers --- forge.go | 2 +- forge_test.go | 4 ++-- scanner.go | 2 +- test.cfg | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/forge.go b/forge.go index 76d44e5..733e471 100644 --- a/forge.go +++ b/forge.go @@ -32,7 +32,7 @@ // // Config file format: // -// IDENTIFIER: [_a-zA-Z]+ +// IDENTIFIER: [_a-zA-Z]([_a-zA-Z0-9]+)? // NUMBERS: [0-9]+ // END: ';' | '\n' // diff --git a/forge_test.go b/forge_test.go index 60cd800..a7ad3e8 100644 --- a/forge_test.go +++ b/forge_test.go @@ -19,7 +19,7 @@ primary { single_with_quote = '\'hello\' "world"'; # Semicolons are optional - integer = 500 + integer500 = 500 float = 80.80 negative = -50 boolean = true @@ -71,7 +71,7 @@ func assertDirectives(values map[string]interface{}, t *testing.T) { assertEqual(primary["string_with_quote"], "some \"quoted\" str\\ing", t) assertEqual(primary["single"], "hello world", t) assertEqual(primary["single_with_quote"], "'hello' \"world\"", t) - assertEqual(primary["integer"], int64(500), t) + assertEqual(primary["integer500"], int64(500), t) assertEqual(primary["float"], float64(80.80), t) assertEqual(primary["negative"], int64(-50), t) assertEqual(primary["boolean"], true, t) diff --git a/scanner.go b/scanner.go index ee60da1..865c1ab 100644 --- a/scanner.go +++ b/scanner.go @@ -85,7 +85,7 @@ func (scanner *Scanner) parseIdentifier() { scanner.curTok.Literal = string(scanner.curCh) for { scanner.readRune() - if !isLetter(scanner.curCh) && scanner.curCh != '_' { + if !isLetter(scanner.curCh) && !isDigit(scanner.curCh) && scanner.curCh != '_' { break } scanner.curTok.Literal += string(scanner.curCh) diff --git a/test.cfg b/test.cfg index f3ef9a4..d9b6f78 100644 --- a/test.cfg +++ b/test.cfg @@ -8,7 +8,7 @@ primary { single_with_quote = '\'hello\' "world"'; # Semicolons are optional - integer = 500 + integer500 = 500 float = 80.80 negative = -50 boolean = true