Show / Hide Table of Contents

    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.

    options
    CompilerOptions

    The CompilerOptions used by the grammar.

    host
    CoreAsyncHost

    The [Host](xref:hosts) the grammar uses to interact with the file system.

    Properties

    binder

    Gets the Binder used to bind the grammar.

    Declaration
    protected get binder(): Binder;
    Property Value
    Binder

    checker

    Gets the Checker used to check the grammar.

    Declaration
    protected get checker(): Checker;
    Property Value
    Checker

    diagnostics

    The diagnostic messages produced by the grammar.

    Declaration
    readonly diagnostics: DiagnosticMessages;
    Property Value
    DiagnosticMessages

    emitter

    Gets the Emitter used to emit the grammar.

    Declaration
    protected get emitter(): Emitter;
    Property Value
    Emitter

    host

    The CoreAsyncHost the grammar uses to interact with the file system.

    Declaration
    readonly host: CoreAsyncHost;
    Property Value
    CoreAsyncHost

    isBound

    Indicates whether the grammar has been bound.

    Declaration
    get isBound(): boolean;
    Property Value
    boolean

    isParsed

    Indicates whether the grammar has been parsed.

    Declaration
    get isParsed(): boolean;
    Property Value
    boolean

    options

    The CompilerOptions used by the grammar.

    Declaration
    readonly options: Readonly<CompilerOptions>;
    Property Value
    Readonly<CompilerOptions>

    resolver

    Gets the resolver used to resolve references to bound nodes.

    Declaration
    get resolver(): Resolver;
    Property Value
    Resolver

    rootFiles

    Gets the root files parsed by the grammar.

    Declaration
    get rootFiles(): readonly SourceFile[];
    Property Value
    readonly SourceFile[]

    sourceFiles

    Gets the source files parsed by the grammar.

    Declaration
    get sourceFiles(): readonly SourceFile[];
    Property Value
    readonly SourceFile[]

    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
    cancelable
    Cancelable

    A cancelable object that can be used to abort the operation.

    Returns
    Promise<void>

    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

    cancelable
    Cancelable

    A cancelable object that can be used to abort the operation.

    Returns
    Promise<void>

    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.

    options
    CompilerOptions & { file?: string; }

    The CompilerOptions used by the grammar.

    hostFallback
    CoreAsyncHost

    An optional host to use as a fallback for file system operations.

    cancelable
    Cancelable

    A cancelable object that can be used to abort the operation.

    Returns
    Promise<string>

    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
    options
    Readonly<CompilerOptions>

    The options to pass on to the Binder.

    Returns
    Binder

    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
    options
    Readonly<CompilerOptions>

    The options to pass on to the Checker.

    Returns
    Checker

    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
    options
    CompilerOptions

    The options to pass on to the Emitter.

    Returns
    Emitter

    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
    bindings
    BindingTable

    A BindingTable used by the resolver to resolve references to nodes.

    Returns
    Resolver

    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.

    cancelable
    Cancelable

    A cancelable object that can be used to abort the operation.

    Returns
    Promise<void>

    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
    sourceFile
    SourceFile

    The SourceFile to emit.

    cancelable
    Cancelable

    A cancelable object that can be used to abort the operation.

    Returns
    Promise<string>

    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
    SourceFile | undefined

    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
    cancelable
    Cancelable

    A cancelable object that can be used to abort the operation.

    Returns
    Promise<void>

    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.

    cancelToken
    CancelToken

    A cancellation token that can be used by the caller to abort the operation.

    Returns
    Promise<string | undefined> | string | undefined

    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

    cancelToken
    CancelToken

    A cancellation token that can be used by the caller to abort the operation.

    Returns
    Promise<void>

    A Promise that is settled when the operation completes.

    Back to top Generated by DocFX