Skip to content

Commit

Permalink
allow numbers in identifiers
Browse files Browse the repository at this point in the history
  • Loading branch information
kaidesu committed Oct 27, 2023
1 parent f35b017 commit a6c7e09
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
8 changes: 7 additions & 1 deletion examples/scratch.ghost
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,10 @@ data = {
}

print(data.name)
print(data.handler(6))
print(data.handler(6))

function test1() {
print('test1')
}

test1()
2 changes: 1 addition & 1 deletion scanner/scanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion scanner/scanner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"},
Expand Down

0 comments on commit a6c7e09

Please sign in to comment.