Class: Parser<U>
Parser class
Type parameters
| Name |
|---|
U |
Constructors
constructor
• new Parser<U>(opts)
Parser constructor
Type parameters
| Name |
|---|
U |
Parameters
| Name | Type |
|---|---|
opts | StrictParserOpts<U> |
Defined in
• new Parser<U>(opts)
Parser constructor (Lazy parser)
Type parameters
| Name |
|---|
U |
Parameters
| Name | Type |
|---|---|
opts | LazyParserOpts<U> |
Defined in
Properties
ctx
• ctx: ParserContext<U> | LazyContext<U>
Defined in
name
• Optional name: string
Defined in
Methods
_evalContext
▸ _evalContext(): ParserContext<U>
Evaluate the lazy context.
Returns
Defined in
exec
▸ exec(input, state?, offset?): Result<U>
Execute the parser handler.
Parameters
| Name | Type | Default value |
|---|---|---|
input | string | undefined |
state | any | {} |
offset | number | 0 |
Returns
Result<U>
Defined in
find
▸ find(input, state?): undefined | { index: number ; input: string ; result: Result<U> }
Find a pattern from the input string.
Parameters
| Name | Type |
|---|---|
input | string |
state | any |
Returns
undefined | { index: number ; input: string ; result: Result<U> }
Defined in
findAll
▸ findAll(input, state?): { index: number ; input: string ; result: Result<U> }[]
Find all patterns from the input string.
Parameters
| Name | Type |
|---|---|
input | string |
state | any |
Returns
{ index: number ; input: string ; result: Result<U> }[]
Defined in
many
▸ many(min?, max?): Parser<U[]>
Create a new parser that tries to apply the parser iteratively.
Parameters
| Name | Type |
|---|---|
min? | number |
max? | number |
Returns
Parser<U[]>
Defined in
▸ many(opts): Parser<U[]>
Create a new parser that tries to apply the parser iteratively.
Parameters
| Name | Type |
|---|---|
opts | Object |
opts.max? | number |
opts.min? | number |
opts.notMatch? | Parser<unknown> |
Returns
Parser<U[]>
Defined in
map
▸ map<V>(fn): Parser<V>
Create a new parser that wraps the current parser. The generated parser maps the result of the inner parser and returns it as a result.
Type parameters
| Name |
|---|
V |
Parameters
| Name | Type |
|---|---|
fn | (value: U) => V |
Returns
Parser<V>
Defined in
option
▸ option(): Parser<null | U>
Create a new parser that wraps the current parser. The generated parser returns success regardless of whether the inner parser successfully matched. If the inner parser fails, a null value is returned.
Returns
Parser<null | U>
Defined in
parse
▸ parse(input, state?): Result<U>
Parse an input string.
Parameters
| Name | Type |
|---|---|
input | string |
state | any |
Returns
Result<U>
Defined in
state
▸ state(key, value): Parser<U>
Create a new parser that wraps the current parser. The generated parser will set the value of the state variable from the given set function and run the inner parser. When the inner parser finishes executing, it restores the value of the state variable.
Parameters
| Name | Type |
|---|---|
key | string |
value | (state: any) => any |
Returns
Parser<U>
Defined in
text
▸ text(): Parser<string>
Create a new parser that wraps the current parser. The generated parser will return the text in the range matched by the inner parser.
Returns
Parser<string>