PComb API
This is meant to be a complete reference for all of the functions and
data types that comprise PComb. Being complete, they can not necessarily be in
order of how a programmer would use them. If the information that is presented
here is too confusing, consider looking at the
Getting
Started page. Also, the PComb repo has a full demo application in the app/ subdirectory,
and that would be an excellent starting point for learning how to use the
library.
This document is incomplete. It is still being
written.
Types
Parser
export type Parser = (input: ParserInput, output: ParserOutput, action?: ParserAction) => ParseResult;
The Parser type is a function signature that should be implemented by
any function that wants to acts as a parser. All the standard parsers that are
supplied by the PComb library do so, but client code can also implement its own
special-purpose parsers by implementing this signature.
ParseResult
export type ParseResult = boolean, ParserInput, ParserOutput;
The ParseResult tuple is returned by all parser
functions. The first value indicates if the parser successfully matched its
input. If the value if false, the remaining parameters will be identical
to the objects that were supplied in the call to the Parse function.
If true is returned, the ParserInput returned will have
its text field set to have only the input data that was not
consumed by parsing, and the ParserOutput will have its matched list
set to contain all of the individual strings that were matched by each discrete
parsing step as well as any application-specific fields that were set by ParserAction functions.
ParserOutput
export interface ParserOutput {
/** The text that was matched by the parser. */
matched: Array<string>;
copy(): ParserOutput;
}
The ParserOutput interface must be implemented by a class that is
supplied by the client code. The object may implement any number of other
properties and methods, but any such custom values must be copied by the
implementation of the copy method.
ParserInput
export interface ParserInput {
/** What is the text that is being parsed? */
text: string;
copy(): ParserInput;
}
The ParserInput interface must be implemented by a class that
is supplied by the client code.