Skip to content

Commit 640c982

Browse files
committed
Replace numberRegex option with underscoresInNumbers option
To keep the regexes in the same place and avoid repeating them.
1 parent 285278d commit 640c982

File tree

4 files changed

+7
-11
lines changed

4 files changed

+7
-11
lines changed

src/languages/duckdb/duckdb.formatter.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -155,9 +155,7 @@ export const duckdb: DialectOptions = {
155155
reservedFunctionNames: functions,
156156
nestedBlockComments: true,
157157
extraParens: ['[]', '{}'],
158-
// Support underscore separators in numeric literals (e.g., 1_000_000)
159-
numberRegex:
160-
/(?:0x[0-9a-fA-F_]+|0b[01_]+|(?:-\s*)?(?:[0-9_]*\.[0-9_]+|[0-9_]+(?:\.[0-9_]*)?)(?:[eE][-+]?[0-9_]+(?:\.[0-9_]+)?)?)(?![\w\p{Alphabetic}])/uy,
158+
underscoresInNumbers: true,
161159
stringTypes: [
162160
'$$',
163161
"''-qq",

src/languages/postgresql/postgresql.formatter.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -277,9 +277,7 @@ export const postgresql: DialectOptions = {
277277
reservedFunctionNames: functions,
278278
nestedBlockComments: true,
279279
extraParens: ['[]'],
280-
// Support underscore separators in numeric literals (e.g., 1_000_000)
281-
numberRegex:
282-
/(?:0x[0-9a-fA-F_]+|0b[01_]+|(?:-\s*)?(?:[0-9_]*\.[0-9_]+|[0-9_]+(?:\.[0-9_]*)?)(?:[eE][-+]?[0-9_]+(?:\.[0-9_]+)?)?)(?![\w\p{Alphabetic}])/uy,
280+
underscoresInNumbers: true,
283281
stringTypes: [
284282
'$$',
285283
{ quote: "''-qq", prefixes: ['U&'] },

src/lexer/Tokenizer.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,9 @@ export default class Tokenizer {
5050
},
5151
{
5252
type: TokenType.NUMBER,
53-
regex:
54-
cfg.numberRegex ??
55-
/(?:0x[0-9a-fA-F]+|0b[01]+|(?:-\s*)?(?:[0-9]*\.[0-9]+|[0-9]+(?:\.[0-9]*)?)(?:[eE][-+]?[0-9]+(?:\.[0-9]+)?)?)(?![\w\p{Alphabetic}])/uy,
53+
regex: cfg.underscoresInNumbers
54+
? /(?:0x[0-9a-fA-F_]+|0b[01_]+|(?:-\s*)?(?:[0-9_]*\.[0-9_]+|[0-9_]+(?:\.[0-9_]*)?)(?:[eE][-+]?[0-9_]+(?:\.[0-9_]+)?)?)(?![\w\p{Alphabetic}])/uy
55+
: /(?:0x[0-9a-fA-F]+|0b[01]+|(?:-\s*)?(?:[0-9]*\.[0-9]+|[0-9]+(?:\.[0-9]*)?)(?:[eE][-+]?[0-9]+(?:\.[0-9]+)?)?)(?![\w\p{Alphabetic}])/uy,
5656
},
5757
// RESERVED_PHRASE is matched before all other keyword tokens
5858
// to e.g. prioritize matching "TIMESTAMP WITH TIME ZONE" phrase over "WITH" clause.

src/lexer/TokenizerOptions.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,8 @@ export interface TokenizerOptions {
100100
propertyAccessOperators?: string[];
101101
// Enables PostgreSQL-specific OPERATOR(...) syntax
102102
operatorKeyword?: boolean;
103-
// Custom regex pattern for number tokens (defaults to standard SQL number pattern)
104-
numberRegex?: RegExp;
103+
// True to support underscores in number literals (e.g., 1_000_000)
104+
underscoresInNumbers?: boolean;
105105
// Allows custom modifications on the token array.
106106
// Called after the whole input string has been split into tokens.
107107
// The result of this will be the output of the tokenizer.

0 commit comments

Comments
 (0)