Class Grammar
Package: grammarkdown
The primary service used to interact with one or more Grammarkdown SourceFiles.
Constructors
constructor(rootNames, options, host)
Constructs a new instance of the Grammar
class
Declaration
constructor(rootNames: Iterable<string>, options?: CompilerOptions, host?: CoreAsyncHost);
Parameters
- rootNames
- Iterable<string>
The names of the root files used by the grammar.
Properties
binder
Gets the Binder used to bind the grammar.
Declaration
protected get binder(): Binder;
Property Value
checker
Gets the Checker used to check the grammar.
Declaration
protected get checker(): Checker;
Property Value
diagnostics
The diagnostic messages produced by the grammar.
Declaration
readonly diagnostics: DiagnosticMessages;
Property Value
emitter
Gets the Emitter used to emit the grammar.
Declaration
protected get emitter(): Emitter;
Property Value
host
The CoreAsyncHost the grammar uses to interact with the file system.
Declaration
readonly host: CoreAsyncHost;
Property Value
isBound
Indicates whether the grammar has been bound.
Declaration
get isBound(): boolean;
Property Value
isParsed
Indicates whether the grammar has been parsed.
Declaration
get isParsed(): boolean;
Property Value
options
The CompilerOptions used by the grammar.
Declaration
readonly options: Readonly<CompilerOptions>;
Property Value
resolver
Gets the resolver used to resolve references to bound nodes.
Declaration
get resolver(): Resolver;
Property Value
rootFiles
Gets the root files parsed by the grammar.
Declaration
get rootFiles(): readonly SourceFile[];
Property Value
sourceFiles
Gets the source files parsed by the grammar.
Declaration
get sourceFiles(): readonly SourceFile[];
Property Value
Methods
bind(cancelable)
Asynchronously binds each file in the grammar. Will also parse the grammar if it has not yet been parsed.
Declaration
bind(cancelable?: Cancelable): Promise<void>;
Parameters
Returns
A Promise
that is settled when the operation has completed.
check(sourceFile, cancelable)
Asynchronously checks each file in the grammar. Will also parse and bind the grammar if it has not yet been parsed or bound.
Declaration
check(sourceFile?: SourceFile, cancelable?: Cancelable): Promise<void>;
Parameters
- sourceFile
- SourceFile
Returns
A Promise
that is settled when the operation has completed.
convert(content, options, hostFallback, cancelable)
Converts a string containing Grammarkdown syntax into output based on the provided options.
Declaration
static convert(content: string, options?: CompilerOptions & {
file?: string;
}, hostFallback?: CoreAsyncHost, cancelable?: Cancelable): Promise<string>;
Parameters
- content
- string
The Grammarkdown source text to convert.
Returns
createBinder(options)
When overridden in a derived class, creates a Binder to be used by this grammar.
Declaration
/** @virtual */
protected createBinder(options: Readonly<CompilerOptions>): Binder;
Parameters
Returns
createChecker(options)
When overridden in a derived class, creates a Checker to be used by this grammar.
Declaration
/** @virtual */
protected createChecker(options: Readonly<CompilerOptions>): Checker;
Parameters
Returns
createEmitter(options)
When overridden in a derived class, creates an Emitter to be used by this grammar.
Declaration
/** @virtual */
protected createEmitter(options: CompilerOptions): Emitter;
Parameters
Returns
createResolver(bindings)
When overridden in a derived class, creates a Resolver to be used by this grammar.
Declaration
/** @virtual */
protected createResolver(bindings: BindingTable): Resolver;
Parameters
Returns
emit(sourceFile, writeFile, cancelable)
Asynchronously emits each file in the grammar. Will also parse, bind, and check the grammar if it has not yet been parsed, bound, or checked.
Declaration
emit(sourceFile?: SourceFile, writeFile?: (file: string, output: string, cancelToken?: CancelToken) => void | PromiseLike<void>, cancelable?: Cancelable): Promise<void>;
Parameters
- sourceFile
- SourceFile
The SourceFile to emit. If not provided, this method will generate output for all root files.
- writeFile
- (file: string, output: string, cancelToken?: CancelToken) => void | PromiseLike<void>
An optional callback used to write the output. If not provided, this method will emit output via this grammar's host.
Returns
A Promise
that is settled when the operation has completed.
emitString(sourceFile, cancelable)
Asynchronously emits the provided file in the grammar as a string. Will also parse, bind, and check the grammar if it has not yet been parsed, bound, or checked.
Declaration
emitString(sourceFile: SourceFile, cancelable?: Cancelable): Promise<string>;
Parameters
Returns
A Promise
for the emit output that is settled when the operation has completed.
getSourceFile(file)
Gets the SourceFile parsed for the provided file path.
Declaration
getSourceFile(file: string): SourceFile | undefined;
Parameters
- file
- string
The path to the source file.
Returns
The SourceFile for the provided path, if one was parsed; otherwise, undefined
.
parse(cancelable)
Asynchronously parses the root files provided to the grammar.
Declaration
parse(cancelable?: Cancelable): Promise<void>;
Parameters
Returns
A Promise
that is settled when the operation has completed.
readFile(file, cancelToken)
When overridden in a derived class, asynchronously reads the contents of the provided file.
Declaration
/** @virtual */
protected readFile(file: string, cancelToken?: CancelToken): Promise<string | undefined> | string | undefined;
Parameters
- file
- string
The file to read.
Returns
A Promise
for either a string
containing the content if the file could be read, or undefined
if the file could not be read.
writeFile(file, content, cancelToken)
When overridden in a derived class, asynchronously writes a file to the host.
Declaration
/** @virtual */
protected writeFile(file: string, content: string, cancelToken?: CancelToken): Promise<void>;
Parameters
- file
- string
The path to the file.
- content
- string
Returns
A Promise
that is settled when the operation completes.