From a6c7e0918516702e055b4c886ddcd0a7ba185c3e Mon Sep 17 00:00:00 2001 From: "Shea Lewis (Kai)" <355659+kaidesu@users.noreply.github.com> Date: Fri, 27 Oct 2023 11:48:56 -0700 Subject: [PATCH] allow numbers in identifiers --- examples/scratch.ghost | 8 +++++++- scanner/scanner.go | 2 +- scanner/scanner_test.go | 3 ++- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/examples/scratch.ghost b/examples/scratch.ghost index a9f1506..a6caea3 100644 --- a/examples/scratch.ghost +++ b/examples/scratch.ghost @@ -8,4 +8,10 @@ data = { } print(data.name) -print(data.handler(6)) \ No newline at end of file +print(data.handler(6)) + +function test1() { + print('test1') +} + +test1() \ No newline at end of file diff --git a/scanner/scanner.go b/scanner/scanner.go index 92290a3..63033f4 100644 --- a/scanner/scanner.go +++ b/scanner/scanner.go @@ -377,7 +377,7 @@ func isEmpty(character rune) bool { // isIdentifier tells us if the passed character can be used in a valid identifier. func isIdentifier(character rune) bool { - return !isDigit(character) && !isWhitespace(character) && !isBrace(character) && !isBracket(character) && !isParenthesis(character) && !isOperator(character) && !isCompound(character) && !isComparison(character) && !isEmpty(character) + return !isWhitespace(character) && !isBrace(character) && !isBracket(character) && !isParenthesis(character) && !isOperator(character) && !isCompound(character) && !isComparison(character) && !isEmpty(character) } // lookupIdentifier looks up the string in the list of keywords and returns its diff --git a/scanner/scanner_test.go b/scanner/scanner_test.go index e73e3fb..d913769 100644 --- a/scanner/scanner_test.go +++ b/scanner/scanner_test.go @@ -14,7 +14,7 @@ func TestScanTokens(t *testing.T) { expectedLexeme string } }{ - `( ) [ ] { } , . - + ; * % ? : > < >= <= ! != = == "hello world" 42 3.14 6.67428e-11 foo foobar true false class whilefoo こんにちは 世界 += -= *= /= import from as ..`, + `( ) [ ] { } , . - + ; * % ? : > < >= <= ! != = == "hello world" 42 3.14 6.67428e-11 foo foobar hello1 true false class whilefoo こんにちは 世界 += -= *= /= import from as ..`, []struct { expectedType token.Type expectedLexeme string @@ -48,6 +48,7 @@ func TestScanTokens(t *testing.T) { {token.NUMBER, "6.67428e-11"}, {token.IDENTIFIER, "foo"}, {token.IDENTIFIER, "foobar"}, + {token.IDENTIFIER, "hello1"}, {token.TRUE, "true"}, {token.FALSE, "false"}, {token.CLASS, "class"},