mirror of
https://github.com/voson-wang/toon.git
synced 2026-01-29 15:24:10 +08:00
refactor: consolidate numeric literal pattern definition
This commit is contained in:
@@ -1,5 +1,7 @@
|
|||||||
import { FALSE_LITERAL, NULL_LITERAL, TRUE_LITERAL } from '../constants'
|
import { FALSE_LITERAL, NULL_LITERAL, TRUE_LITERAL } from '../constants'
|
||||||
|
|
||||||
|
const NUMERIC_LITERAL_PATTERN = /^-?(?:0|[1-9]\d*)(?:\.\d+)?(?:e[+-]?\d+)?$/i
|
||||||
|
|
||||||
export function isBooleanOrNullLiteral(token: string): boolean {
|
export function isBooleanOrNullLiteral(token: string): boolean {
|
||||||
return token === TRUE_LITERAL || token === FALSE_LITERAL || token === NULL_LITERAL
|
return token === TRUE_LITERAL || token === FALSE_LITERAL || token === NULL_LITERAL
|
||||||
}
|
}
|
||||||
@@ -15,8 +17,7 @@ export function isNumericLiteral(token: string): boolean {
|
|||||||
return false
|
return false
|
||||||
|
|
||||||
// Enforce JSON-like grammar with no forbidden leading zeros
|
// Enforce JSON-like grammar with no forbidden leading zeros
|
||||||
const numericPattern = /^-?(?:0|[1-9]\d*)(?:\.\d+)?(?:e[+-]?\d+)?$/i
|
if (!NUMERIC_LITERAL_PATTERN.test(token))
|
||||||
if (!numericPattern.test(token))
|
|
||||||
return false
|
return false
|
||||||
|
|
||||||
const numericValue = Number(token)
|
const numericValue = Number(token)
|
||||||
|
|||||||
Reference in New Issue
Block a user