Skip to content
Ron Buckton edited this page Jun 23, 2015 · 6 revisions

Grammar Class

A container for a syntactic grammar.

Syntax

export declare class Grammar {
    constructor(rootNames: string[], options?: CompilerOptions, 
      readFile?: (file: string) => string);

    public get rootFiles(): SourceFile[];
    public get sourceFiles(): SourceFile[];
    public get options(): CompilerOptions;
    public get diagnostics(): DiagnosticMessages;

    protected get parser(): Parser;
    protected get binder(): Binder;
    protected get checker(): Checker;
    protected get emitter(): Emitter;

    public getSourceFile(file: string): SourceFile;
    public bind(sourceFile?: SourceFile): void;
    public check(sourceFile?: SourceFile): void;
    public emit(
      sourceFile?: SourceFile, 
      writeFile?: (file: string, output: string) => void): void;

    protected createParser(options: CompilerOptions): Parser;
    protected createBinder(options: CompilerOptions, 
      bindings: BindingTable): Binder;
    protected createChecker(options: CompilerOptions, 
      bindings: BindingTable): Checker;
    protected createEmitter(options: CompilerOptions, 
      resolver: Resolver): Emitter;
    protected readFile(file: string): string;
}

Usage

import { Grammar } from "grammarkdown";

let g = new Grammar(["input.grammar"], { out: "output.md" });
g.emit();

Constructors

new Grammar(Array, CompilerOptions?, Function?)
Creates a new instance of the Grammar class

Properties

rootFiles
The root source files for the grammar.
sourceFiles
All source files for the grammar, including imports.
options
The options to pass to each phase of the compiler.
diagnostics
The diagnostic messages reported by the compiler.
protected parser
The Parser for the grammar. (This property is intended to be used by subclasses only)
protected binder
The Binder for the grammar. (This property is intended to be used by subclasses only)
protected checker
The Checker for the grammar. (This property is intended to be used by subclasses only)
protected emitter
The Emitter for the grammar. (This property is intended to be used by subclasses only)

Methods

getSourceFile(String)
Gets the parsed SourceFile for the provided file name.
bind(SourceFile?)
Binds a SourceFile, if provided; otherwise, binds all source files.
check(SourceFile?)
Checks a SourceFile, if provided; otherwise, checks all source files.
emit(SourceFile?, Function?)
Binds a SourceFile, if provided; otherwise, emits all root files.
protected createParser(CompilerOptions)
Creates a Parser instance for this grammar. (This property is intended to be used by subclasses only)
protected createBinder(CompilerOptions, BindingTable)
Creates a Binder instance for this grammar. (This property is intended to be used by subclasses only)
protected createChecker(CompilerOptions, BindingTable)
Creates a Checker instance for this grammar. (This property is intended to be used by subclasses only)
protected createEmitter(CompilerOptions, Resolver)
Creates an Emitter instance for this grammar. (This property is intended to be used by subclasses only)
protected readFile(String)
Reads a file using the callback supplied to the constructor. (This property is intended to be used by subclasses only)

Requirements

  • Supported Platforms: nodejs, iojs
  • Module: grammarkdown
Clone this wiki locally