Update tsd to include changes since 8e9be9a

master
Futago-za Ryuu 6 years ago
parent 2ac387e1c9
commit 15d364587c

@ -71,6 +71,7 @@ const compiler = {
dependencies: {},
exportVar: null,
format: "bare",
header: null,
optimize: "speed",
output: "parser",
trace: false

@ -20,19 +20,19 @@ function fatal( message, location ) {
class Session {
constructor( options ) {
constructor( config ) {
options = typeof options !== "undefined" ? options : {};
config = typeof config !== "undefined" ? config : {};
this.grammar = options.grammar;
this.opcodes = options.opcodes || opcodes;
this.parser = options.parser || parser;
this.passes = options.passes || [];
this.visitor = options.visitor || ast.visitor;
this.vm = options.vm || vm;
this.grammar = config.grammar;
this.opcodes = config.opcodes || opcodes;
this.parser = config.parser || parser;
this.passes = config.passes || {};
this.visitor = config.visitor || ast.visitor;
this.vm = config.vm || vm;
if ( typeof options.warn === "function" ) this.warn = options.warn;
if ( typeof options.error === "function" ) this.error = options.error;
if ( typeof config.warn === "function" ) this.warn = config.warn;
if ( typeof config.error === "function" ) this.error = config.error;
Object.defineProperty( this, "fatal", { value: fatal } );

157
lib/typings/api.d.ts vendored

@ -28,6 +28,9 @@ declare namespace peg {
}
/**
* PEG.js AST
*/
namespace ast {
/**
@ -296,19 +299,32 @@ declare namespace peg {
}
interface IVisitor<R = any> {
( node: Object, ...args ): R;
}
class ASTVisitor implements IVisitorMap {
visit<R = any>( node: Object, ...args ): R;
visit: IVisitor;
}
interface IVisitor<R = any> {
interface IVisitorBuilder<T = void, R = any> {
( node: Object, ...args ): R;
( functions: IVisitorMap<T> ): IVisitor<R>;
}
function build<T = void, R = any>( functions: IVisitorMap<T> ): IVisitor<R>;
const build: IVisitorBuilder;
}
interface visitor {
ASTVisitor: visitor.ASTVisitor;
build: visitor.IVisitorBuilder;
}
@ -331,6 +347,9 @@ declare namespace peg {
}
/**
* The PEG.js compiler.
*/
namespace compiler {
type FormatOptions = "amd" | "bare" | "commonjs" | "es" | "globals" | "umd";
@ -342,6 +361,7 @@ declare namespace peg {
[ key: string ]: any;
allowedStartRules?: string[];
cache?: boolean;
context?: { [ name: string ]: any; };
dependencies?: { [ name: string ]: string; };
exportVar?: string;
format?: FormatOptions;
@ -356,6 +376,7 @@ declare namespace peg {
allowedStartRules: string[];
cache: boolean;
context: { [ name: string ]: any; };
dependencies: { [ name: string ]: string; };
exportVar: string;
format: FormatOptions;
@ -369,7 +390,8 @@ declare namespace peg {
interface ICompilerPass {
( node: Grammar ): void;
( node: Grammar, options: ICompilerPassOptions ): void;
( node: Grammar, session: Session ): void;
( node: Grammar, session: Session, options: ICompilerPassOptions ): void;
}
@ -379,30 +401,78 @@ declare namespace peg {
}
interface IOpcodes {
[ name: string ]: number;
}
interface vm {
runInContext( code: string, vm$context?: { [ name: string ]: any; } ): any;
}
const vm: vm;
interface ISessionMessageEmitter {
( message: string, location: SourceLocation ): any;
}
interface ISessionConfig {
[ key: string ]: any;
grammar?: string;
opcodes?: IOpcodes;
parser?: GeneratedParser<Grammar>;
passes?: IPassesMap;
visitor?: ast.visitor;
vm?: vm;
warn?: ISessionMessageEmitter;
error?: ISessionMessageEmitter;
}
class Session implements ISessionConfig {
constructor( config?: ISessionConfig );
parse( input: string, options?: parser.IOptions ): Grammar;
buildVisitor: ast.visitor.IVisitorBuilder;
warn: ISessionMessageEmitter;
error: ISessionMessageEmitter;
fatal: ISessionMessageEmitter;
}
namespace passes {
namespace check {
function reportUndefinedRules( ast: Grammar, options: ICompilerPassOptions ): void;
function reportDuplicateRules( ast: Grammar ): void;
function reportDuplicateLabels( ast: Grammar ): void;
function reportInfiniteRecursion( ast: Grammar ): void;
function reportInfiniteRepetition( ast: Grammar ): void;
function reportUndefinedRules( ast: Grammar, session: Session, options: ICompilerPassOptions ): void;
function reportDuplicateRules( ast: Grammar, session: Session ): void;
function reportUnusedRules( ast: Grammar, session: Session, options: ICompilerPassOptions ): void;
function reportDuplicateLabels( ast: Grammar, session: Session ): void;
function reportInfiniteRecursion( ast: Grammar, session: Session ): void;
function reportInfiniteRepetition( ast: Grammar, session: Session ): void;
}
namespace transform {
function removeProxyRules( ast: Grammar, options: ICompilerPassOptions ): void;
function removeProxyRules( ast: Grammar, session: Session, options: ICompilerPassOptions ): void;
}
namespace generate {
function calcReportFailures( ast: Grammar, options: ICompilerPassOptions ): void;
function inferenceMatchResult( ast: Grammar ): void;
function generateBytecode( ast: Grammar ): void;
function generateJS( ast: Grammar, options: ICompilerPassOptions ): void;
function calcReportFailures( ast: Grammar, session: Session, options: ICompilerPassOptions ): void;
function inferenceMatchResult( ast: Grammar, session: Session ): void;
function generateBytecode( ast: Grammar, session: Session ): void;
function generateJS( ast: Grammar, session: Session, options: ICompilerPassOptions ): void;
}
@ -411,60 +481,63 @@ declare namespace peg {
/**
* Generate's a parser from the PEG.js AST and returns it.
*/
function compile( ast: Grammar, passes: IPassesMap, options?: ICompilerOptions ): GeneratedParser | string;
function compile( ast: Grammar, session: Session, options?: ICompilerOptions ): GeneratedParser | string;
/**
* Generate's a parser from the PEG.js AST, then evaluates's the source before returning the parser object.
*/
function compile( ast: Grammar, passes: IPassesMap, options?: ICompilerOptions<"parser"> ): GeneratedParser;
function compile( ast: Grammar, session: Session, options?: ICompilerOptions<"parser"> ): GeneratedParser;
/**
* Generate's a parser from the PEG.js AST and returns the JavaScript based source.
*/
function compile( ast: Grammar, passes: IPassesMap, options?: ICompilerOptions<"source"> ): string;
function compile( ast: Grammar, session: Session, options?: ICompilerOptions<"source"> ): string;
}
namespace util {
// peg.util
interface IStageMap {
interface IStageMap {
[ stage: string ]
: compiler.ICompilerPass[]
| { [ pass: string ]: compiler.ICompilerPass };
[ stage: string ]
: compiler.ICompilerPass[]
| { [ pass: string ]: compiler.ICompilerPass };
}
}
function convertPasses( stages: IStageMap ): compiler.IPassesMap;
interface IIterator<R = any> {
interface IIterator<R = any> {
( value: any ): R;
( value: any, key: string ): R;
( value: any ): R;
( value: any, key: string ): R;
}
}
interface IObjectUtils {
function clone( source: {} ): {};
function each( object: {}, iterator: IIterator<void> ): void;
function extend( target: {}, source: {} ): {};
function map( object: {}, transformer: IIterator ): {};
function values( object: {}, transformer?: IIterator ): any[];
function enforceFastProperties( o: {} ): {};
convertPasses( stages: IStageMap ): compiler.IPassesMap;
}
clone( source: {} ): {};
each( object: {}, iterator: IIterator<void> ): void;
extend( target: {}, source: {} ): {};
map( object: {}, transformer: IIterator ): {};
values( object: {}, transformer?: IIterator ): any[];
enforceFastProperties( o: {} ): {};
interface IBuildConfig<T = any> {
}
interface util extends IObjectUtils {
parser: GeneratedParser<T>;
passes: compiler.IPassesMap;
convertPasses( stages: IStageMap ): compiler.IPassesMap;
}
const util: util;
// peg.generate
interface IPlugin<T = compiler.OutputOptions, U = any> {
interface IPlugin<T = compiler.OutputOptions> {
[ key: string ]: any;
use( config: IBuildConfig<U> ): void;
use( config: IBuildConfig<U>, options: IBuildOptions<T> ): void;
use( session: compiler.Session ): void;
use( session: compiler.Session, options: IBuildOptions<T> ): void;
}

@ -26,14 +26,7 @@ declare module "pegjs/lib/peg" {
declare module "pegjs/lib/ast" {
export const Node: peg.ast.Node;
export const Grammar: peg.ast.Grammar;
export const visitor: {
ASTVisitor: peg.ast.visitor.ASTVisitor;
build<T = void, R = any>( functions: peg.ast.visitor.IVisitorMap<T> ): peg.ast.visitor.IVisitor<R>;
};
export default peg.ast;
}
@ -81,11 +74,23 @@ declare module "pegjs/lib/compiler/js" {
declare module "pegjs/lib/compiler/opcodes" {
const opcodes: { [ name: string ]: number };
const opcodes: peg.compiler.IOpcodes;
export default opcodes;
}
declare module "pegjs/lib/compiler/session" {
export default peg.compiler.Session;
}
declare module "pegjs/lib/compiler/vm" {
export default peg.compiler.vm;
}
declare module "pegjs/lib/compiler/passes/calc-report-failures" {
export default peg.compiler.passes.generate.calcReportFailures;
@ -146,6 +151,12 @@ declare module "pegjs/lib/compiler/passes/report-undefined-rules" {
}
declare module "pegjs/lib/compiler/passes/report-unused-rules" {
export default peg.compiler.passes.check.reportUnusedRules;
}
declare module "pegjs/lib/util" {
export default peg.util;
@ -166,16 +177,7 @@ declare module "pegjs/lib/util/index" {
declare module "pegjs/lib/util/objects" {
namespace objects {
function clone( source: {} ): {};
function each( object: {}, iterator: peg.util.IIterator<void> ): void;
function extend( target: {}, source: {} ): {};
function map( object: {}, transformer: peg.util.IIterator ): {};
function values( object: {}, transformer?: peg.util.IIterator ): any[];
function enforceFastProperties( o: {} ): {};
}
const objects: peg.IObjectUtils;
export default objects;
}

Loading…
Cancel
Save