Methods
-
parse(parser, string, opts)
-
Executes a parser and returns the result.
Parameters:
Name Type Argument Description parserFunction The parser to execute.
stringString String to parse.
optsObject <optional>
Options object.
Properties
Name Type Argument Default Description throwOnErrorBoolean <optional>
true If truthy, throws a ParserError if the parser fails and returns ParserState instead of its value.
fileNameString <optional>
filename to use for error messages.
Example
parse(token(), "a"); // => "a"
-
parseAsync(parser, callback, opts)
-
Executes a parser asynchronously, returning an object that can be used to manage the parser state. Unless the parser given tries to match eof(), parsing will continue until the parser's done() function is called.
Parameters:
Name Type Argument Description parserFunction The parser to execute.
callbackAsyncParserCallback node-style 2-arg callback executed once per successful application of
parser.optsObject <optional>
Options object.
Properties
Name Type Argument Description fileNameString <optional>
filename to use for error messages.
Example
var handle = parseAsync(token(), function(tok) { console.log("Got a token: ", tok); }); handle.data("foobarbaz");
Type Definitions
-
ParserError
-
Information about a parsing failure.
Type:
- Object
-
SourcePosition
-
Represents a source location.
Type:
- Object