Skip to content

Commit a8435b5

Browse files
committed
added support for decimal values without leading digits
1 parent 2ad4028 commit a8435b5

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

src/lexer/Tokenizer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ export default class Tokenizer {
5151
{
5252
type: TokenType.NUMBER,
5353
regex:
54-
/(?:0x[0-9a-fA-F]+|0b[01]+|(?:-\s*)?[0-9]+(?:\.[0-9]*)?(?:[eE][-+]?[0-9]+(?:\.[0-9]+)?)?)(?![\w\p{Alphabetic}])/uy,
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,
5555
},
5656
// RESERVED_PHRASE is matched before all other keyword tokens
5757
// to e.g. prioritize matching "TIMESTAMP WITH TIME ZONE" phrase over "WITH" clause.

test/behavesLikeSqlFormatter.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,4 +279,19 @@ export default function behavesLikeSqlFormatter(format: FormatFn) {
279279
tbl;
280280
`);
281281
});
282+
283+
it('supports decimal values without leading digits', () => {
284+
const result = format(`
285+
SELECT employee_id FROM employees WHERE salary > .456 * 1000000 AND bonus < .0000239 * salary;
286+
`);
287+
expect(result).toBe(dedent`
288+
SELECT
289+
employee_id
290+
FROM
291+
employees
292+
WHERE
293+
salary > .456 * 1000000
294+
AND bonus < .0000239 * salary;
295+
`);
296+
});
282297
}

0 commit comments

Comments
 (0)