NumericLiteral Production as a Regular Expression

node v14.20.1
version: 1.0.0
endpointsharetweet
const OR = (args) => `(?:${args.map(expression => `(?:${expression})`).join("|")})`; const x = require("templated-regular-expression") ({ // https://262.ecma-international.org/13.0/#prod-NumericLiteralSeparator NumericLiteralSeparator: /_/, // https://262.ecma-international.org/13.0/#prod-NumericLiteral NumericLiteral: new RegExp(`^${OR ([ "${<DecimalLiteral>}", "${<DecimalBigIntegerLiteral>}", "${<NonDecimalIntegerLiteralSep>}", "${<NonDecimalBigIntegeralLiteralSep>}", "${<LegacyOctalIntegerLiteral>}" ])} RunKit), // https://262.ecma-international.org/13.0/#prod-DecimalBigIntegerLiteral DecimalBigIntegerLiteral: new RegExp(OR ([ "0${BigIntLiteralSuffix}", "${NonZeroDigit}${DecimalDigitsSep}?${BigIntLiteralSuffix}", "${NonZeroDigit}${NumericLiteralSeparator}${DecimalDigitsSep}${BigIntLiteralSuffix}" ])), NonDecimalBigIntegeralLiteralSep: /${NonDecimalIntegerLiteralSep}${BigIntLiteralSuffix}/, // https://262.ecma-international.org/13.0/#prod-BigIntLiteralSuffix BigIntLiteralSuffix: /n/, // https://262.ecma-international.org/13.0/#prod-DecimalLiteral DecimalLiteral: new RegExp(OR ([ "${DecimalIntegerLiteral}\\.${DecimalDigitsSep}?${ExponentPartSep}?", "\\.${DecimalDigitsSep}${ExponentPartSep}?", "${DecimalIntegerLiteral}${ExponentPartSep}?" ])), // https://262.ecma-international.org/13.0/#prod-DecimalIntegerLiteral DecimalIntegerLiteral: new RegExp(OR ([ "0", "${NonZeroDigit}", "${NonZeroDigit}${NumericLiteralSeparator}?${DecimalDigitsSep}", "${NonOctalDecimalIntegerLiteral}" ])), NonDecimalIntegerLiteral: new RegExp(OR ([ "${BinaryIntegerLiteral}", "${OctalIntegerLiteral}", "${HexIntegerLiteral}" ])), NonDecimalIntegerLiteralSep: new RegExp(OR ([ "${BinaryIntegerLiteralSep}", "${OctalIntegerLiteralSep}", "${HexIntegerLiteralSep}", ])), // https://262.ecma-international.org/13.0/#prod-DecimalDigits DecimalDigits: /${DecimalDigit}+/, DecimalDigitsSep: /(${DecimalDigit}(${NumericLiteralSeparator}${DecimalDigit})?)+/, // https://262.ecma-international.org/13.0/#prod-DecimalDigit DecimalDigit: /[0-9]/, // https://262.ecma-international.org/13.0/#prod-NonZeroDigit NonZeroDigit: /[1-9]/, // https://262.ecma-international.org/13.0/#prod-ExponentPart ExponentPart: /${ExponentIndicator}${SignedInteger}/, ExponentPartSep: /${ExponentIndicator}${SignedIntegerSep}/, // https://262.ecma-international.org/13.0/#prod-ExponentIndicator ExponentIndicator: /[eE]/, // https://262.ecma-international.org/13.0/#prod-SignedInteger SignedInteger: /[-+]?${DecimalDigits}/, SignedIntegerSep: /[-+]?${DecimalDigitsSep}/, // https://262.ecma-international.org/13.0/#prod-BinaryIntegerLiteral BinaryIntegerLiteral: /0[bB]${BinaryDigits}/, BinaryIntegerLiteralSep: /0[bB]${BinaryDigitsSep}/, // https://262.ecma-international.org/13.0/#prod-BinaryDigits BinaryDigits: /${BinaryDigit}+/, BinaryDigitsSep: /(${BinaryDigit}(${NumericLiteralSeparator}${BinaryDigit})?)+/, // https://262.ecma-international.org/13.0/#prod-SignedInteger BinaryDigit: /[01]/, // https://262.ecma-international.org/13.0/#prod-OctalIntegerLiteral OctalIntegerLiteral: /0[oO]${OctalDigits}/, OctalIntegerLiteralSep: /0[oO]${OctalDigitsSep}/, // https://262.ecma-international.org/13.0/#prod-OctalDigits OctalDigits: /${OctalDigit}+/, OctalDigitsSep: /(${OctalDigit}(${NumericLiteralSeparator}${OctalDigit})?)+/, // https://262.ecma-international.org/13.0/#prod-LegacyOctalIntegerLiteral LegacyOctalIntegerLiteral: /0${OctalDigit}+/, // https://262.ecma-international.org/13.0/#prod-NonOctalDecimalIntegerLiteral NonOctalDecimalIntegerLiteral: new RegExp(OR ([ "0${NonOctalDigit}${DecimalDigit}*", "${LegacyOctalLikeDecimalIntegerLiteral}${NonOctalDigit}" ])), // https://262.ecma-international.org/13.0/#prod-LegacyOctalLikeDecimalIntegerLiteral LegacyOctalLikeDecimalIntegerLiteral: /0${OctalDigit}+/, // https://262.ecma-international.org/13.0/#prod-OctalDigit OctalDigit: /[0-7]/, // https://262.ecma-international.org/13.0/#prod-HexIntegerLiteral NonOctalDigit: /[89]/, // https://262.ecma-international.org/13.0/#prod-HexIntegerLiteral HexIntegerLiteral: /0[xX]${HexDigits}/, HexIntegerLiteralSep: /0[xX]${HexDigitsSep}/, // https://262.ecma-international.org/13.0/#prod-HexDigit HexDigits: /${HexDigit}+/, HexDigitsSep: /(${HexDigit}(${NumericLiteralSeparator}${HexDigit})?)+/, // https://262.ecma-international.org/13.0/#prod-HexDigit HexDigit: /[0-9a-fA-F]/ });
x.NumericLiteral.test("075")
"07p5".match(x.NumericLiteral)
"075".match(x.NumericLiteral).groups
"10_0n".match(x.NumericLiteral).groups
"0b10_0n".match(x.NumericLiteral).groups
"100e10".match(x.NumericLiteral).groups
Loading…

no comments

    sign in to comment