Skip to content

Commit

Permalink
Fix readme
Browse files Browse the repository at this point in the history
  • Loading branch information
barsdeveloper committed Jan 3, 2024
1 parent f634e45 commit 93e754e
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 21 deletions.
20 changes: 10 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ import P from "parsernostrum"
// Create a parser
/** @type {P<any>} */
const palindromeParser = P.alt(
P.regexp(/[a-z]/).chain(c =>
P.reg(/[a-z]/).chain(c =>
P.seq(
P.lazy(() => palindromeParser).opt(),
P.str(c)
).map(([recursion, _]) => c + recursion + c)
),
P.regexp(/([a-z])\1?/)
P.reg(/([a-z])\1?/)
).opt()

// Use the parsing methods to check the text
Expand All @@ -46,16 +46,16 @@ Parses exact string literals.
P.str("A string!")
```

### `regexp(value, group)`
### `reg(value, group)`
Parses a regular expression and possibly returns a captured group.
```JavaScript
P.regexp(/\d+/)
P.reg(/\d+/)
```

### `regexpGroups(value)`
Parses a regular expression and returns all its captured groups exactly as returned by the `RegExp.exec()` method.
### `regArray(value)`
Parses a regular expression and returns all its captured groups array exactly as returned by the `RegExp.exec()` method.
```JavaScript
P.regexpGroups(/begin\s*(\w*)\s*(\w*)\s*end/)
P.regArray(/begin\s*(\w*)\s*(\w*)\s*end/)
```

### `seq(...parsers)`
Expand Down Expand Up @@ -83,7 +83,7 @@ const matcheParentheses = P.seq(
P.str("("),
P.alt(
P.lazy(() => matcheParentheses),
P.regexp(/\w*/),
P.reg(/\w*/),
),
P.str(")"),
)
Expand Down Expand Up @@ -126,7 +126,7 @@ myParser.opt()
### `.sepBy(separator)`
Parses a list of elements separated by a given separator.
```JavaScript
myParser.sepBy(P.regexp(/\s*,\s*/))
myParser.sepBy(P.reg(/\s*,\s*/))
```

### `.skipSpace()`
Expand All @@ -144,7 +144,7 @@ myParser.map(n => `Number: ${n}`)
### `.chain(fn)`
Chains the output of one parser to another.
```JavaScript
const p = P.regexp(/[([{]/).chain(v => (
const p = P.reg(/[([{]/).chain(v => (
{
"(": P.str(")"),
"[": P.str("]"),
Expand Down
8 changes: 4 additions & 4 deletions dist/parsernostrum.js
Original file line number Diff line number Diff line change
Expand Up @@ -784,15 +784,15 @@ class Parsernostrum {
static whitespaceMultiline = this.reg(/\s*?\n\s*/)

/** Parser accepting a double quoted string and returns the content */
static doubleQuotedString = this.regArr(new RegExp(`"(${this.#createEscapeable('"')})"`))
static doubleQuotedString = this.regArray(new RegExp(`"(${this.#createEscapeable('"')})"`))
.map(this.#secondElementGetter)

/** Parser accepting a single quoted string and returns the content */
static singleQuotedString = this.regArr(new RegExp(`'(${this.#createEscapeable("'")})'`))
static singleQuotedString = this.regArray(new RegExp(`'(${this.#createEscapeable("'")})'`))
.map(this.#secondElementGetter)

/** Parser accepting a backtick quoted string and returns the content */
static backtickQuotedString = this.regArr(new RegExp(`\`(${this.#createEscapeable("`")})\``))
static backtickQuotedString = this.regArray(new RegExp(`\`(${this.#createEscapeable("`")})\``))
.map(this.#secondElementGetter)

/** @param {T} parser */
Expand Down Expand Up @@ -843,7 +843,7 @@ class Parsernostrum {
}

/** @param {RegExp} value */
static regArr(value) {
static regArray(value) {
return new this(new RegExpParser(value, -1))
}

Expand Down
2 changes: 1 addition & 1 deletion dist/parsernostrum.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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.0.10",
"version": "1.0.11",
"description": "A tiny LL parser combinator library for javascript",
"main": "src/Parsernostrum.js",
"types": "src/types.js",
Expand Down
Loading

0 comments on commit 93e754e

Please sign in to comment.