Methods
-
parse(parser, string, opts)
-
Executes a parser and returns the result.
Parameters:
Name Type Argument Description parser
Function The parser to execute.
string
String String to parse.
opts
Object <optional>
Options object.
Properties
Name Type Argument Default Description throwOnError
Boolean <optional>
true If truthy, throws a ParserError if the parser fails and returns ParserState instead of its value.
fileName
String <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 parser
Function The parser to execute.
callback
AsyncParserCallback node-style 2-arg callback executed once per successful application of
parser
.opts
Object <optional>
Options object.
Properties
Name Type Argument Description fileName
String <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