Show / Hide Table of Contents

    Class CoreSyncHost

    Package: grammarkdown

    A Host is a user-provided service that indicates how various Grammarkdown services can interact with a file system. The CoreSyncHost class provides the API surface that Grammarkdown uses to interact with a host that is able to access the file system synchronously.

    Inheritance
    HostBase
    CoreSyncHost
    Examples

    The following example shows how you can create a CoreSyncHost from a Map:

    const files = new Map([
      ["a.grammar", "..."],
      ["b.grammar", "..."]
    ]);
    const host = new CoreSyncHost({
      ignoreCase: false,
      useBuiltinGrammers: false,
      resolveFile: file => file,
      readFileSync: file => files.get(file)
    });
    

    Constructors

    constructor(options, hostFallback)

    Constructs a new instance of the CoreSyncHost class

    Declaration
    constructor(options: CoreSyncHostOptions, hostFallback?: CoreSyncHost);
    Parameters
    options
    CoreSyncHostOptions

    The options used to configure the host.

    hostFallback
    CoreSyncHost

    An optional host to use as a fallback for operations not supported by this host.

    Methods

    | Improve this Doc

    forFile(content, file, hostFallback)

    Creates a StringSyncHost for the provided content.

    Declaration
    static forFile(content: string, file?: string, hostFallback?: CoreSyncHost): StringSyncHost;
    Parameters
    content
    string

    The content of the file.

    file
    string

    The file name for the content.

    hostFallback
    CoreSyncHost

    An optional host to use as a fallback for operations not supported by this host.

    Returns
    StringSyncHost

    Examples

    The following example shows how you can create a CoreSyncHost for a string:

    const content = "...";
    const host = CoreSyncHost.forFile(content);
    

    from(options, hostFallback)

    Creates a CoreSyncHost.

    Declaration
    static from(options: CoreSyncHostOptions, hostFallback?: CoreSyncHost): CoreSyncHost;
    Parameters
    options
    CoreSyncHostOptions

    The options used to configure the host.

    hostFallback
    CoreSyncHost

    An optional host to use as a fallback for operations not supported by this host.

    Returns
    CoreSyncHost

    getSourceFileSync(file, cancelable)

    Reads and parses a source file from the host.

    Declaration
    getSourceFileSync(file: string, cancelable?: Cancelable): SourceFile | undefined;
    Parameters
    file
    string

    The path to the file.

    cancelable
    Cancelable

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

    Returns
    SourceFile | undefined

    The parsed SourceFile of the file if the file could be read; otherwise, undefined.

    getSourceFileSync(file, cancelable)

    Warning

    Deprecated

    since 2.1.0 - `prex.CancellationToken` may no longer be accepted in future releases. Please use a token that implements `@esfx/cancelable.Cancelable`

    Reads and parses a source file from the host.

    Declaration
    getSourceFileSync(file: string, cancelable?: CancellationToken | Cancelable): SourceFile | undefined;
    Parameters
    file
    string

    The path to the file.

    cancelable
    CancellationToken | Cancelable

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

    Returns
    SourceFile | undefined

    The parsed SourceFile of the file if the file could be read; otherwise, undefined.

    normalizeFileCore(file)

    When overridden in a derived class, normalizes a file path's string representation for use as a key based on the case sensitivity of the host.

    Declaration
    /** @override */
    protected normalizeFileCore(file: string): string;
    Parameters
    file
    string

    The file path.

    Returns
    string

    readFileSync(file, cancelable)

    Reads a file from the host.

    Declaration
    readFileSync(file: string, cancelable?: Cancelable): string | undefined;
    Parameters
    file
    string

    The path to the file.

    cancelable
    Cancelable

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

    Returns
    string | undefined

    A string containing the content if the file could be read; otherwise, undefined.

    readFileSync(file, cancelable)

    Warning

    Deprecated

    since 2.1.0 - `prex.CancellationToken` may no longer be accepted in future releases. Please use a token that implements `@esfx/cancelable.Cancelable`

    Reads a file from the host.

    Declaration
    readFileSync(file: string, cancelable?: CancellationToken | Cancelable): string | undefined;
    Parameters
    file
    string

    The path to the file.

    cancelable
    CancellationToken | Cancelable

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

    Returns
    string | undefined

    A string containing the content if the file could be read; otherwise, undefined.

    readFileSyncCore(file, cancelToken)

    When overridden in a derived class, reads a file from the host.

    Declaration
    /** @virtual */
    protected readFileSyncCore(file: string, cancelToken?: CancelToken): string | undefined;
    Parameters
    file
    string

    The path to the file.

    cancelToken
    CancelToken

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

    Returns
    string | undefined

    A string containing the content if the file could be read; otherwise, undefined.

    registerKnownGrammarCore(name, file)

    When overridden in a derived clas, registers a known grammar for use with @import directives.

    Declaration
    /** @override */
    protected registerKnownGrammarCore(name: string, file: string): void;
    Parameters
    name
    string

    The name for the grammar.

    file
    string

    The file path of the grammar.

    Returns
    void

    resolveFileCore(file, referer)

    When overridden in a derived class, resolves the full path of a file relative to the provided referer.

    Declaration
    /** @override */
    protected resolveFileCore(file: string, referer?: string): string;
    Parameters
    file
    string

    The path to the requested file.

    referer
    string

    An optional path indicating the file from which the path should be resolved.

    Returns
    string

    resolveKnownGrammarCore(name)

    When overridden in a derived class, returns the path for a known or built-in grammar based on its name (i.e., "es2015", etc.)

    Declaration
    /** @override */
    protected resolveKnownGrammarCore(name: string): string | undefined;
    Parameters
    name
    string

    The name of the grammar.

    Returns
    string | undefined

    writeFileSync(file, text, cancelable)

    Writes a file to the host.

    Declaration
    writeFileSync(file: string, text: string, cancelable?: Cancelable): void;
    Parameters
    file
    string

    The path to the file.

    text
    string

    The contents of the file.

    cancelable
    Cancelable

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

    Returns
    void

    writeFileSync(file, text, cancelable)

    Warning

    Deprecated

    since 2.1.0 - `prex.CancellationToken` may no longer be accepted in future releases. Please use a token that implements `@esfx/cancelable.Cancelable`

    Writes a file to the host.

    Declaration
    writeFileSync(file: string, text: string, cancelable?: CancellationToken | Cancelable): void;
    Parameters
    file
    string

    The path to the file.

    text
    string

    The contents of the file.

    cancelable
    CancellationToken | Cancelable

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

    Returns
    void

    writeFileSyncCore(file, content, cancelToken)

    When overridden in a derived class, writes a file to the host.

    Declaration
    /** @virtual */
    protected writeFileSyncCore(file: string, content: string, cancelToken?: CancelToken): 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
    void

    • Improve this Doc
    Back to top Generated by DocFX