From a8435b56aa82629678c0c03f0b6cff45f4d029b5 Mon Sep 17 00:00:00 2001 From: JagmitSwami Date: Fri, 25 Oct 2024 21:32:57 +0530 Subject: [PATCH] added support for decimal values without leading digits --- src/lexer/Tokenizer.ts | 2 +- test/behavesLikeSqlFormatter.ts | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/lexer/Tokenizer.ts b/src/lexer/Tokenizer.ts index cd6f9bd650..59571720aa 100644 --- a/src/lexer/Tokenizer.ts +++ b/src/lexer/Tokenizer.ts @@ -51,7 +51,7 @@ export default class Tokenizer { { type: TokenType.NUMBER, regex: - /(?:0x[0-9a-fA-F]+|0b[01]+|(?:-\s*)?[0-9]+(?:\.[0-9]*)?(?:[eE][-+]?[0-9]+(?:\.[0-9]+)?)?)(?![\w\p{Alphabetic}])/uy, + /(?: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, }, // RESERVED_PHRASE is matched before all other keyword tokens // to e.g. prioritize matching "TIMESTAMP WITH TIME ZONE" phrase over "WITH" clause. diff --git a/test/behavesLikeSqlFormatter.ts b/test/behavesLikeSqlFormatter.ts index d8c90f5e0d..21e94dccad 100644 --- a/test/behavesLikeSqlFormatter.ts +++ b/test/behavesLikeSqlFormatter.ts @@ -279,4 +279,19 @@ export default function behavesLikeSqlFormatter(format: FormatFn) { tbl; `); }); + + it('supports decimal values without leading digits', () => { + const result = format(` + SELECT employee_id FROM employees WHERE salary > .456 * 1000000 AND bonus < .0000239 * salary; + `); + expect(result).toBe(dedent` + SELECT + employee_id + FROM + employees + WHERE + salary > .456 * 1000000 + AND bonus < .0000239 * salary; + `); + }); }