Home Reference Source Test Repository
import Rule from 'elenpi/src/rule.js'
public class | source

Rule

The Rule base class.

Constructor Summary

Public Constructor
public

the Rule constructor

Method Summary

Public Methods
public

char(test: String): Rule

match a single character

public

done(callback: Function): Rule

the base handler for every other lexems

public

end(): Rule

match the end of string

public

error(msg: String): Rule

force end parsing with error.

public

maybeOne(rule: Rule | Object): Rule

maybe match one element from string with provided rule

public

maybeOneOf(rules: Rule | Object): Rule

maybe match one element from string with one of provided rules

public

one(rule: Rule | Object): Rule

match one element from string with provided rule

public

oneOf(rules: Rule | Object): Rule

match one element from string with one of provided rules

public

match 1 or more element from string with provided rule

public

skip(): Rule

skip current descriptor

public

space(needed: Boolean): Rule

match a space (any spaces, or carriage returns, or new lines)

public

catch a terminal

public

use(rule: String | Rule): Rule

use another rule

public

xOrMore(rule: Rule | Object): Rule

match x or more element from string with provided rule

public

match 0 or more element from string with provided rule

Public Constructors

public constructor() source

the Rule constructor

Public Methods

public char(test: String): Rule source

match a single character

Params:

NameTypeAttributeDescription
test String

the caracter to match

Return:

Rule

this rule handler

public done(callback: Function): Rule source

the base handler for every other lexems

Params:

NameTypeAttributeDescription
callback Function

the callback to handle string

Return:

Rule

this rule handler

public end(): Rule source

match the end of string

Return:

Rule

this rule handler

public error(msg: String): Rule source

force end parsing with error. Only aimed to be used in .oneOf().

Params:

NameTypeAttributeDescription
msg String

the error message.

Return:

Rule

this rule handler

public maybeOne(rule: Rule | Object): Rule source

maybe match one element from string with provided rule

Params:

NameTypeAttributeDescription
rule Rule | Object

either a rule instance or an option object

Return:

Rule

this rule handler

public maybeOneOf(rules: Rule | Object): Rule source

maybe match one element from string with one of provided rules

Params:

NameTypeAttributeDescription
rules Rule | Object

either a rule instance or an option object

Return:

Rule

this rule handler

public one(rule: Rule | Object): Rule source

match one element from string with provided rule

Params:

NameTypeAttributeDescription
rule Rule | Object

either a rule instance or an option object

Return:

Rule

this rule handler

public oneOf(rules: Rule | Object): Rule source

match one element from string with one of provided rules

Params:

NameTypeAttributeDescription
rules Rule | Object

either a rule instance or an option object

Return:

Rule

this rule handler

public oneOrMore(rule: Rule | Object): Rule source

match 1 or more element from string with provided rule

Params:

NameTypeAttributeDescription
rule Rule | Object

either a rule instance or an option object

Return:

Rule

this rule handler

public skip(): Rule source

skip current descriptor

Return:

Rule

this rule handler

public space(needed: Boolean): Rule source

match a space (any spaces, or carriage returns, or new lines)

Params:

NameTypeAttributeDescription
needed Boolean

true if space is needed. false otherwise.

Return:

Rule

this rule handler

public terminal(reg: RegExp, set: String | Function): Rule source

catch a terminal

Params:

NameTypeAttributeDescription
reg RegExp

the terminal's regexp

set String | Function

either the name of the property (in current descriptor) where store the catched value or a function to handle captured object by hand

Return:

Rule

this rule handler

public use(rule: String | Rule): Rule source

use another rule

Params:

NameTypeAttributeDescription
rule String | Rule

the rule to use

Return:

Rule

this rule handler

public xOrMore(rule: Rule | Object): Rule source

match x or more element from string with provided rule

Params:

NameTypeAttributeDescription
rule Rule | Object

either a rule instance or an option object

Return:

Rule

this rule handler

public zeroOrMore(rule: Rule | Object): Rule source

match 0 or more element from string with provided rule

Params:

NameTypeAttributeDescription
rule Rule | Object

either a rule instance or an option object

Return:

Rule

this rule handler