Scope

Scope

A scope is just a group of cases and parsers Parserror can make use of.

Constructor

new Scope(name)

Source:
Parameters:
Name Type Description
name string

The name of the scope.

Throws:

If the name is not a string.

Type
TypeError

Members

name :string

Source:

The scope's name.

Type:

Methods

addCase(theCase) → {Scope}

Source:

Adds a new case to the scope.

Parameters:
Name Type Description
theCase ErrorCase

The case to add.

Throws:
  • If there's already a case with the same name on the scope.

    Type
    Error
  • If theCase is not an instance of ErrorCase.

    Type
    Error
Returns:

For chaining purposes.

Type
Scope

addParser(parser) → {Scope}

Source:

Adds a reusable parser to the scope.

Parameters:
Name Type Description
parser CaseParser

The parser to add.

Throws:
  • If there's already a parser with the same name on the scope.

    Type
    Error
  • If parser is not an instance of CaseParser.

    Type
    Error
Returns:

For chaining purposes.

Type
Scope

getCase(name, failWithErroropt) → (nullable) {ErrorCase}

Source:

Returns a case by its name.

Parameters:
Name Type Attributes Default Description
name string

The name of the case.

failWithError boolean <optional>
true

Whether or not the method should throw an error if the case can't be found.

Throws:

If failWithError is true and the case can't be found.

Type
Error
Returns:
Type
ErrorCase

getCases() → {Array.<ErrorCase>}

Source:

Returns all available cases for this scope.

Returns:
Type
Array.<ErrorCase>

getParser(name, failWithErroropt) → (nullable) {CaseParser}

Source:

Returns a parser by its name.

Parameters:
Name Type Attributes Default Description
name string

The name of the parser.

failWithError boolean <optional>
true

Whether or not the method should throw an error if the parser can't be found.

Throws:

If failWithError is true and the parser can't be found.

Type
Error
Returns:
Type
CaseParser

hasCase(name) → {boolean}

Source:

Checks whether or not there's a case based on its name.

Parameters:
Name Type Description
name string

The case's name.

Returns:
Type
boolean

hasParser(name) → {boolean}

Source:

Checks whether or not there's a parser based on its name.

Parameters:
Name Type Description
name string

The parser's name.

Returns:
Type
boolean

removeCase(theCase) → {Scope}

Source:

Removes a case from the scope.

Parameters:
Name Type Description
theCase string | ErrorCase

The name or the reference for the case to remove.

Throws:
  • If the case doesn't exist on the scope.

    Type
    Error
  • If theCase is a reference but is not an instance of ErrorCase.

    Type
    Error
Returns:

For chaining purposes.

Type
Scope

removeParser(parser) → {Scope}

Source:

Removes a parser from the scope.

Parameters:
Name Type Description
parser string | CaseParser

The name or the reference for the parser to remove.

Throws:
  • If the parser doesn't exist on the scope.

    Type
    Error
  • If parser is a reference but is not an instance of CaseParser.

    Type
    Error
Returns:

For chaining purposes.

Type
Scope