Skip to content

Commit 0d39810

Browse files
committed
Treat function names as identifiers when they aren't followed by "("
Instead of treating them as keywords. Fixes #812
1 parent 2c54120 commit 0d39810

File tree

2 files changed

+7
-8
lines changed

2 files changed

+7
-8
lines changed

src/lexer/disambiguateTokens.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import { isReserved, Token, TokenType } from './token.js';
22

33
/**
4-
* Ensures that no keyword token (RESERVED_*) is preceded by dot (.)
4+
* Ensures that no keyword token (RESERVED_*) is preceded or followed by a dot (.)
55
* or any other property-access operator.
66
*
77
* Ensures that all RESERVED_FUNCTION_NAME tokens are followed by "(".
8-
* If they're not, converts the token to RESERVED_KEYWORD.
8+
* If they're not, converts the token to IDENTIFIER.
99
*
1010
* Converts RESERVED_DATA_TYPE tokens followed by "(" to RESERVED_PARAMETERIZED_DATA_TYPE.
1111
*
@@ -19,7 +19,7 @@ import { isReserved, Token, TokenType } from './token.js';
1919
export function disambiguateTokens(tokens: Token[]): Token[] {
2020
return tokens
2121
.map(propertyNameKeywordToIdent)
22-
.map(funcNameToKeyword)
22+
.map(funcNameToIdent)
2323
.map(dataTypeToParameterizedDataType)
2424
.map(identToArrayIdent)
2525
.map(dataTypeToArrayKeyword);
@@ -39,11 +39,11 @@ const propertyNameKeywordToIdent = (token: Token, i: number, tokens: Token[]): T
3939
return token;
4040
};
4141

42-
const funcNameToKeyword = (token: Token, i: number, tokens: Token[]): Token => {
42+
const funcNameToIdent = (token: Token, i: number, tokens: Token[]): Token => {
4343
if (token.type === TokenType.RESERVED_FUNCTION_NAME) {
4444
const nextToken = nextNonCommentToken(tokens, i);
4545
if (!nextToken || !isOpenParen(nextToken)) {
46-
return { ...token, type: TokenType.RESERVED_KEYWORD };
46+
return { ...token, type: TokenType.IDENTIFIER, text: token.raw };
4747
}
4848
}
4949
return token;

test/unit/__snapshots__/Parser.test.ts.snap

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -496,10 +496,9 @@ Array [
496496
Object {
497497
"children": Array [
498498
Object {
499-
"raw": "CURRENT_TIME",
499+
"quoted": false,
500500
"text": "CURRENT_TIME",
501-
"tokenType": "RESERVED_KEYWORD",
502-
"type": "keyword",
501+
"type": "identifier",
503502
},
504503
Object {
505504
"quoted": false,

0 commit comments

Comments
 (0)