Home Reference Source Repository
import {ParserBuilder} from 'pratt'
public class | source

ParserBuilder

Builds led/nud rules for a Parser

Constructor Summary

Public Constructor
public

constructor(parser: Parser<T>)

Constructs a ParserBuilder See also: Parser.builder

Method Summary

Public Methods
public

bp(tokenType: T, bp: number): ParserBuilder<T>

Define the binding power for a token type

public

build(): Parser<T>

Returns the parent Parser instance

public

either(tokenType: strTng, bp: number, fn: LedFunction<T>): ParserBuilder<T>

Define both led and nud for a token type at once.

public

led(tokenType: T, bp: number, fn: LedFunction<T>): ParserBuilder<T>

Define led for a token type

public

nud(tokenType: T, bp: number, fn: NudFunction<T>): ParserBuilder<T>

Define nud for a token type

Public Constructors

public constructor(parser: Parser<T>) source

Constructs a ParserBuilder See also: Parser.builder

Params:

NameTypeAttributeDescription
parser Parser<T>

The parser

Public Methods

public bp(tokenType: T, bp: number): ParserBuilder<T> source

Define the binding power for a token type

Params:

NameTypeAttributeDescription
tokenType T

The token type

bp number

The binding power

Return:

ParserBuilder<T>

Returns this ParserBuilder

public build(): Parser<T> source

Returns the parent Parser instance

Return:

Parser<T>

public either(tokenType: strTng, bp: number, fn: LedFunction<T>): ParserBuilder<T> source

Define both led and nud for a token type at once. The supplied LedFunction may be called with a null left parameter when invoked from a nud context.

Params:

NameTypeAttributeDescription
tokenType strTng

The token type

bp number

The binding power

fn LedFunction<T>

The function that will parse the token

Return:

ParserBuilder<T>

Returns this ParserBuilder

public led(tokenType: T, bp: number, fn: LedFunction<T>): ParserBuilder<T> source

Define led for a token type

Params:

NameTypeAttributeDescription
tokenType T

The token type

bp number

The binding power

fn LedFunction<T>

The function that will parse the token

Return:

ParserBuilder<T>

Returns this ParserBuilder

public nud(tokenType: T, bp: number, fn: NudFunction<T>): ParserBuilder<T> source

Define nud for a token type

Params:

NameTypeAttributeDescription
tokenType T

The token type

bp number

The binding power

fn NudFunction<T>

The function that will parse the token

Return:

ParserBuilder<T>

Returns this ParserBuilder