Skip to content

Commit

Permalink
Treat function names as identifiers when they aren't followed by "("
Browse files Browse the repository at this point in the history
Instead of treating them as keywords.

Fixes #812
  • Loading branch information
nene committed Dec 21, 2024
1 parent 2c54120 commit 0d39810
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
10 changes: 5 additions & 5 deletions src/lexer/disambiguateTokens.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { isReserved, Token, TokenType } from './token.js';

/**
* Ensures that no keyword token (RESERVED_*) is preceded by dot (.)
* Ensures that no keyword token (RESERVED_*) is preceded or followed by a dot (.)
* or any other property-access operator.
*
* Ensures that all RESERVED_FUNCTION_NAME tokens are followed by "(".
* If they're not, converts the token to RESERVED_KEYWORD.
* If they're not, converts the token to IDENTIFIER.
*
* Converts RESERVED_DATA_TYPE tokens followed by "(" to RESERVED_PARAMETERIZED_DATA_TYPE.
*
Expand All @@ -19,7 +19,7 @@ import { isReserved, Token, TokenType } from './token.js';
export function disambiguateTokens(tokens: Token[]): Token[] {
return tokens
.map(propertyNameKeywordToIdent)
.map(funcNameToKeyword)
.map(funcNameToIdent)
.map(dataTypeToParameterizedDataType)
.map(identToArrayIdent)
.map(dataTypeToArrayKeyword);
Expand All @@ -39,11 +39,11 @@ const propertyNameKeywordToIdent = (token: Token, i: number, tokens: Token[]): T
return token;
};

const funcNameToKeyword = (token: Token, i: number, tokens: Token[]): Token => {
const funcNameToIdent = (token: Token, i: number, tokens: Token[]): Token => {
if (token.type === TokenType.RESERVED_FUNCTION_NAME) {
const nextToken = nextNonCommentToken(tokens, i);
if (!nextToken || !isOpenParen(nextToken)) {
return { ...token, type: TokenType.RESERVED_KEYWORD };
return { ...token, type: TokenType.IDENTIFIER, text: token.raw };
}
}
return token;
Expand Down
5 changes: 2 additions & 3 deletions test/unit/__snapshots__/Parser.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -496,10 +496,9 @@ Array [
Object {
"children": Array [
Object {
"raw": "CURRENT_TIME",
"quoted": false,
"text": "CURRENT_TIME",
"tokenType": "RESERVED_KEYWORD",
"type": "keyword",
"type": "identifier",
},
Object {
"quoted": false,
Expand Down

0 comments on commit 0d39810

Please sign in to comment.