メインコンテンツまでスキップ

Class: Parser<U>

Parser class

Type parameters

Name
U

Constructors

constructor

new Parser<U>(opts)

Parser constructor

Type parameters

Name
U

Parameters

NameType
optsStrictParserOpts<U>

Defined in

index.ts:68

new Parser<U>(opts)

Parser constructor (Lazy parser)

Type parameters

Name
U

Parameters

NameType
optsLazyParserOpts<U>

Defined in

index.ts:74

Properties

ctx

ctx: ParserContext<U> | LazyContext<U>

Defined in

index.ts:61


name

Optional name: string

Defined in

index.ts:60

Methods

_evalContext

_evalContext(): ParserContext<U>

Evaluate the lazy context.

Returns

ParserContext<U>

Defined in

index.ts:92


exec

exec(input, state?, offset?): Result<U>

Execute the parser handler.

Parameters

NameTypeDefault value
inputstringundefined
stateany{}
offsetnumber0

Returns

Result<U>

Defined in

index.ts:109


find

find(input, state?): undefined | { index: number ; input: string ; result: Result<U> }

Find a pattern from the input string.

Parameters

NameType
inputstring
stateany

Returns

undefined | { index: number ; input: string ; result: Result<U> }

Defined in

index.ts:129


findAll

findAll(input, state?): { index: number ; input: string ; result: Result<U> }[]

Find all patterns from the input string.

Parameters

NameType
inputstring
stateany

Returns

{ index: number ; input: string ; result: Result<U> }[]

Defined in

index.ts:145


many

many(min?, max?): Parser<U[]>

Create a new parser that tries to apply the parser iteratively.

Parameters

NameType
min?number
max?number

Returns

Parser<U[]>

Defined in

index.ts:195

many(opts): Parser<U[]>

Create a new parser that tries to apply the parser iteratively.

Parameters

NameType
optsObject
opts.max?number
opts.min?number
opts.notMatch?Parser<unknown>

Returns

Parser<U[]>

Defined in

index.ts:201


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

NameType
fn(value: U) => V

Returns

Parser<V>

Defined in

index.ts:163


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

index.ts:219


parse

parse(input, state?): Result<U>

Parse an input string.

Parameters

NameType
inputstring
stateany

Returns

Result<U>

Defined in

index.ts:119


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

NameType
keystring
value(state: any) => any

Returns

Parser<U>

Defined in

index.ts:234


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>

Defined in

index.ts:179