Class: Grammar

@citation-js/core.util.Grammar(rules, state)

new Grammar(rules, state)

Parameters:
Name Type Description
rules Object.<module:@citation-js/core.util.Grammar~ruleName, module:@citation-js/core.util.Grammar~rule>
state Object
Source:

Methods

consumeRule(rule)

Parameters:
Name Type Description
rule String

a rule name

Source:
Returns:

whatever the rule function returns

consumeToken(typeopt, optionalopt) → {Object}

Parameters:
Name Type Attributes Default Description
type String <optional>

a token type

optional Boolean <optional>
false

false if it should throw an error if the type does not match

Source:
Throws:

detailed syntax error if the current token is not the expected type or if there are no tokens left

Type
SyntaxError
Returns:

token information

Type
Object

matchEndOfFile() → {Boolean}

Source:
Returns:

true if there are no more tokens

Type
Boolean

matchToken(type) → {Boolean}

Parameters:
Name Type Description
type String

a token type

Source:
Returns:

true if the current token has the given type

Type
Boolean

parse(iterator, mainRuleopt)

Parameters:
Name Type Attributes Description
iterator

lexer supporting formatError() and next()

mainRule <optional>

defaults to the first rule

Source:
Returns:

result of the main rule

Type Definitions

rule()

This:
Source:

ruleName

Type:
  • String
Source: