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

Parser

The Parser class.

Static Method Summary

Static Public Methods
public static

exec(rule: String | Rule, descriptor: Object, env: Object): Void

Execute a rule (only for those who developing grammars)

Constructor Summary

Public Constructor
public

constructor(rules: Object, defaultRule: String)

Member Summary

Public Members
public

the default rule's name to use

public

the rules map

Method Summary

Public Methods
public

getRule(name: String): Rule

find rule by name

public

parse(string: String, rule: String, descriptor: Object): Object

Parse provided string with specific rule

Static Public Methods

public static exec(rule: String | Rule, descriptor: Object, env: Object): Void source

Execute a rule (only for those who developing grammars)

Params:

NameTypeAttributeDescription
rule String | Rule

the name of the rule to use or the rule itself

descriptor Object

the descriptor to decorate

env Object

the inner-job main object where parser, parsed string and eventual errors are stored

Return:

Void

nothing

Throw:

Error

If rule is string (so it's a rule's name) and referenced rule could not be found with it.

Public Constructors

public constructor(rules: Object, defaultRule: String) source

Params:

NameTypeAttributeDescription
rules Object

an object containing rules

defaultRule String

the default rule to use when parsing

Public Members

public defaultRule: String source

the default rule's name to use

public rules: Object source

the rules map

Public Methods

public getRule(name: String): Rule source

find rule by name

Params:

NameTypeAttributeDescription
name String

the rule's name

Return:

Rule

the finded rule

Throw:

Error

If rule not found

public parse(string: String, rule: String, descriptor: Object): Object source

Parse provided string with specific rule

Params:

NameTypeAttributeDescription
string String

the string to parse

rule String

the name of the rule to apply. default is null (will use parser's default method if not provided).

descriptor Object

the main descriptor object

Return:

Object

the decorated descriptor

Throw:

Error

If parsing fail (for any reason)