Skip to content

Commit

Permalink
better name
Browse files Browse the repository at this point in the history
  • Loading branch information
barsdeveloper committed Jan 26, 2024
1 parent 4c59cb0 commit 0f7dba2
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 38 deletions.
36 changes: 18 additions & 18 deletions dist/parsernostrum.js
Original file line number Diff line number Diff line change
Expand Up @@ -566,7 +566,7 @@ class RegExpParser extends Parser {

static #createEscapeable = character => String.raw`[^${character}\\]*(?:\\.[^${character}\\]*)*`
static #numberRegex = /[-\+]?(?:\d*\.)?\d+/
static commonParser = {
static common = {
number: new RegExp(this.#numberRegex.source + String.raw`(?!\.)`),
numberInteger: /[\-\+]?\d+(?!\.\d)/,
numberNatural: /\d+/,
Expand Down Expand Up @@ -620,7 +620,7 @@ class RegExpParser extends Parser {
doToString(context, indent, path) {
let result = "/" + this.#regexp.source + "/";
const shortname = Object
.entries(RegExpParser.commonParser)
.entries(RegExpParser.common)
.find(([k, v]) => v.source === this.#regexp.source)?.[0];
if (shortname) {
result = "P." + shortname;
Expand Down Expand Up @@ -685,9 +685,9 @@ class MapParser extends Parser {
}
let result = this.#parser.toString(context, indent, childrenPath);
if (this.#parser instanceof RegExpParser) {
if (Object.values(RegExpParser.commonParser).includes(this.#parser.regexp)) {
if (Object.values(RegExpParser.common).includes(this.#parser.regexp)) {
if (
this.#parser.regexp === RegExpParser.commonParser.numberInteger
this.#parser.regexp === RegExpParser.common.numberInteger
&& this.#mapper === /** @type {(v: any) => BigInt} */(BigInt)
) {
return "P.numberBigInteger"
Expand Down Expand Up @@ -914,49 +914,49 @@ class Parsernostrum {
// Prefedined parsers

/** Parser accepting any valid decimal, possibly signed number */
static number = this.reg(RegExpParser.commonParser.number).map(Number)
static number = this.reg(RegExpParser.common.number).map(Number)

/** Parser accepting any digits only number */
static numberInteger = this.reg(RegExpParser.commonParser.numberInteger).map(Number)
static numberInteger = this.reg(RegExpParser.common.numberInteger).map(Number)

/** Parser accepting any digits only number and returns a BigInt */
static numberBigInteger = this.reg(this.numberInteger.getParser().parser.regexp).map(BigInt)

/** Parser accepting any digits only number */
static numberNatural = this.reg(RegExpParser.commonParser.numberNatural).map(Number)
static numberNatural = this.reg(RegExpParser.common.numberNatural).map(Number)

/** Parser accepting any valid decimal, possibly signed, possibly in the exponential form number */
static numberExponential = this.reg(RegExpParser.commonParser.numberExponential).map(Number)
static numberExponential = this.reg(RegExpParser.common.numberExponential).map(Number)

/** Parser accepting any valid decimal number between 0 and 1 */
static numberUnit = this.reg(RegExpParser.commonParser.numberUnit).map(Number)
static numberUnit = this.reg(RegExpParser.common.numberUnit).map(Number)

/** Parser accepting any integer between 0 and 255 */
static numberByte = this.reg(RegExpParser.commonParser.numberByte).map(Number)
static numberByte = this.reg(RegExpParser.common.numberByte).map(Number)

/** Parser accepting whitespace */
static whitespace = this.reg(RegExpParser.commonParser.whitespace)
static whitespace = this.reg(RegExpParser.common.whitespace)

/** Parser accepting whitespace */
static whitespaceOpt = this.reg(RegExpParser.commonParser.whitespaceOpt)
static whitespaceOpt = this.reg(RegExpParser.common.whitespaceOpt)

/** Parser accepting whitespace that spans on a single line */
static whitespaceInline = this.reg(RegExpParser.commonParser.whitespaceInline)
static whitespaceInline = this.reg(RegExpParser.common.whitespaceInline)

/** Parser accepting whitespace that spans on a single line */
static whitespaceInlineOpt = this.reg(RegExpParser.commonParser.whitespaceInlineOpt)
static whitespaceInlineOpt = this.reg(RegExpParser.common.whitespaceInlineOpt)

/** Parser accepting whitespace that contains a list a newline */
static whitespaceMultiline = this.reg(RegExpParser.commonParser.whitespaceMultiline)
static whitespaceMultiline = this.reg(RegExpParser.common.whitespaceMultiline)

/** Parser accepting a double quoted string and returns the content */
static doubleQuotedString = this.reg(RegExpParser.commonParser.doubleQuotedString, 1)
static doubleQuotedString = this.reg(RegExpParser.common.doubleQuotedString, 1)

/** Parser accepting a single quoted string and returns the content */
static singleQuotedString = this.reg(RegExpParser.commonParser.singleQuotedString, 1)
static singleQuotedString = this.reg(RegExpParser.common.singleQuotedString, 1)

/** Parser accepting a backtick quoted string and returns the content */
static backtickQuotedString = this.reg(RegExpParser.commonParser.backtickQuotedString, 1)
static backtickQuotedString = this.reg(RegExpParser.common.backtickQuotedString, 1)

/** @param {T} parser */
constructor(parser, optimized = false) {
Expand Down
2 changes: 1 addition & 1 deletion dist/parsernostrum.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "parsernostrum",
"type": "module",
"version": "1.1.2",
"version": "1.1.3",
"description": "A tiny LL parser combinator library for javascript",
"main": "src/Parsernostrum.js",
"types": "src/types.js",
Expand Down
28 changes: 14 additions & 14 deletions src/Parsernostrum.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,49 +45,49 @@ export default class Parsernostrum {
// Prefedined parsers

/** Parser accepting any valid decimal, possibly signed number */
static number = this.reg(RegExpParser.commonParser.number).map(Number)
static number = this.reg(RegExpParser.common.number).map(Number)

/** Parser accepting any digits only number */
static numberInteger = this.reg(RegExpParser.commonParser.numberInteger).map(Number)
static numberInteger = this.reg(RegExpParser.common.numberInteger).map(Number)

/** Parser accepting any digits only number and returns a BigInt */
static numberBigInteger = this.reg(this.numberInteger.getParser().parser.regexp).map(BigInt)

/** Parser accepting any digits only number */
static numberNatural = this.reg(RegExpParser.commonParser.numberNatural).map(Number)
static numberNatural = this.reg(RegExpParser.common.numberNatural).map(Number)

/** Parser accepting any valid decimal, possibly signed, possibly in the exponential form number */
static numberExponential = this.reg(RegExpParser.commonParser.numberExponential).map(Number)
static numberExponential = this.reg(RegExpParser.common.numberExponential).map(Number)

/** Parser accepting any valid decimal number between 0 and 1 */
static numberUnit = this.reg(RegExpParser.commonParser.numberUnit).map(Number)
static numberUnit = this.reg(RegExpParser.common.numberUnit).map(Number)

/** Parser accepting any integer between 0 and 255 */
static numberByte = this.reg(RegExpParser.commonParser.numberByte).map(Number)
static numberByte = this.reg(RegExpParser.common.numberByte).map(Number)

/** Parser accepting whitespace */
static whitespace = this.reg(RegExpParser.commonParser.whitespace)
static whitespace = this.reg(RegExpParser.common.whitespace)

/** Parser accepting whitespace */
static whitespaceOpt = this.reg(RegExpParser.commonParser.whitespaceOpt)
static whitespaceOpt = this.reg(RegExpParser.common.whitespaceOpt)

/** Parser accepting whitespace that spans on a single line */
static whitespaceInline = this.reg(RegExpParser.commonParser.whitespaceInline)
static whitespaceInline = this.reg(RegExpParser.common.whitespaceInline)

/** Parser accepting whitespace that spans on a single line */
static whitespaceInlineOpt = this.reg(RegExpParser.commonParser.whitespaceInlineOpt)
static whitespaceInlineOpt = this.reg(RegExpParser.common.whitespaceInlineOpt)

/** Parser accepting whitespace that contains a list a newline */
static whitespaceMultiline = this.reg(RegExpParser.commonParser.whitespaceMultiline)
static whitespaceMultiline = this.reg(RegExpParser.common.whitespaceMultiline)

/** Parser accepting a double quoted string and returns the content */
static doubleQuotedString = this.reg(RegExpParser.commonParser.doubleQuotedString, 1)
static doubleQuotedString = this.reg(RegExpParser.common.doubleQuotedString, 1)

/** Parser accepting a single quoted string and returns the content */
static singleQuotedString = this.reg(RegExpParser.commonParser.singleQuotedString, 1)
static singleQuotedString = this.reg(RegExpParser.common.singleQuotedString, 1)

/** Parser accepting a backtick quoted string and returns the content */
static backtickQuotedString = this.reg(RegExpParser.commonParser.backtickQuotedString, 1)
static backtickQuotedString = this.reg(RegExpParser.common.backtickQuotedString, 1)

/** @param {T} parser */
constructor(parser, optimized = false) {
Expand Down
4 changes: 2 additions & 2 deletions src/parser/MapParser.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ export default class MapParser extends Parser {
}
let result = this.#parser.toString(context, indent, childrenPath)
if (this.#parser instanceof RegExpParser) {
if (Object.values(RegExpParser.commonParser).includes(this.#parser.regexp)) {
if (Object.values(RegExpParser.common).includes(this.#parser.regexp)) {
if (
this.#parser.regexp === RegExpParser.commonParser.numberInteger
this.#parser.regexp === RegExpParser.common.numberInteger
&& this.#mapper === /** @type {(v: any) => BigInt} */(BigInt)
) {
return "P.numberBigInteger"
Expand Down
4 changes: 2 additions & 2 deletions src/parser/RegExpParser.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export default class RegExpParser extends Parser {

static #createEscapeable = character => String.raw`[^${character}\\]*(?:\\.[^${character}\\]*)*`
static #numberRegex = /[-\+]?(?:\d*\.)?\d+/
static commonParser = {
static common = {
number: new RegExp(this.#numberRegex.source + String.raw`(?!\.)`),
numberInteger: /[\-\+]?\d+(?!\.\d)/,
numberNatural: /\d+/,
Expand Down Expand Up @@ -69,7 +69,7 @@ export default class RegExpParser extends Parser {
doToString(context, indent, path) {
let result = "/" + this.#regexp.source + "/"
const shortname = Object
.entries(RegExpParser.commonParser)
.entries(RegExpParser.common)
.find(([k, v]) => v.source === this.#regexp.source)?.[0]
if (shortname) {
result = "P." + shortname
Expand Down

0 comments on commit 0f7dba2

Please sign in to comment.