Updated utils and tsd
- Exposed 'visitor.ASTVisitor' - Remoed 'util.createVisitor' - Added type 'peg.SourceLocation' - Updated tsd for 'peg.compiler.visitor' - Added tsd for 'peg.util.enforceFastProperties' - Added tsd for new parser modules
This commit is contained in:
parent
27ec5ed9b1
commit
617b6b7425
|
@ -26,6 +26,7 @@ class ASTVisitor {
|
|||
}
|
||||
|
||||
}
|
||||
ASTVisitor.ASTVisitor = ASTVisitor;
|
||||
module.exports = ASTVisitor;
|
||||
|
||||
// Helper's to create visitor's for use with the ASTVisitor class
|
||||
|
|
82
lib/typings/api.d.ts
vendored
82
lib/typings/api.d.ts
vendored
|
@ -8,6 +8,7 @@ declare namespace peg {
|
|||
type Grammar = parser.ast.Grammar;
|
||||
type GeneratedParser<T = any> = gp.API<T>;
|
||||
type SyntaxError = gp.SyntaxErrorConstructor;
|
||||
type SourceLocation = gp.SourceLocation;
|
||||
|
||||
/**
|
||||
* PEG.js version (uses semantic versioning).
|
||||
|
@ -21,9 +22,9 @@ declare namespace peg {
|
|||
|
||||
name: string;
|
||||
message: string;
|
||||
location?: gp.SourceLocation;
|
||||
location?: SourceLocation;
|
||||
|
||||
constructor( message: string, location?: gp.SourceLocation );
|
||||
constructor( message: string, location?: SourceLocation );
|
||||
|
||||
}
|
||||
|
||||
|
@ -53,7 +54,7 @@ declare namespace peg {
|
|||
interface INode {
|
||||
|
||||
type: string;
|
||||
location: gp.SourceLocation;
|
||||
location: SourceLocation;
|
||||
|
||||
}
|
||||
|
||||
|
@ -294,42 +295,45 @@ declare namespace peg {
|
|||
|
||||
}
|
||||
|
||||
namespace visitor {
|
||||
interface IVisitor<R = any> {
|
||||
|
||||
interface Visitor<R = any> {
|
||||
|
||||
( node: Node, ...args ): R;
|
||||
( node: parser.ast.Node, ...args ): R;
|
||||
|
||||
}
|
||||
|
||||
interface VisitorMap<U = void> {
|
||||
interface IVisitorMap<U = void> {
|
||||
|
||||
[ type: string ]: any;
|
||||
grammar<R = U>( node: Grammar, ...args ): R;
|
||||
initializer<R = U>( node: parser.ast.Initializer, ...args ): R;
|
||||
rule<R = U>( node: parser.ast.Rule, ...args ): R;
|
||||
named<R = U>( node: parser.ast.Named, ...args ): R;
|
||||
choice<R = U>( node: parser.ast.ChoiceExpression, ...args ): R;
|
||||
action<R = U>( node: parser.ast.ActionExpression, ...args ): R;
|
||||
sequence<R = U>( node: parser.ast.SequenceExpression, ...args ): R;
|
||||
labeled<R = U>( node: parser.ast.LabeledExpression, ...args ): R;
|
||||
text<R = U>( node: parser.ast.PrefixedExpression, ...args ): R;
|
||||
simple_and<R = U>( node: parser.ast.PrefixedExpression, ...args ): R;
|
||||
simple_not<R = U>( node: parser.ast.PrefixedExpression, ...args ): R;
|
||||
optional<R = U>( node: parser.ast.SuffixedExpression, ...args ): R;
|
||||
zero_or_more<R = U>( node: parser.ast.SuffixedExpression, ...args ): R;
|
||||
one_or_more<R = U>( node: parser.ast.SuffixedExpression, ...args ): R;
|
||||
literal<R = U>( node: parser.ast.LiteralMatcher, ...args ): R;
|
||||
class<R = U>( node: parser.ast.CharacterClassMatcher, ...args ): R;
|
||||
any<R = U>( node: parser.ast.AnyMatcher, ...args ): R;
|
||||
rule_ref<R = U>( node: parser.ast.RuleReferenceExpression, ...args ): R;
|
||||
semantic_and<R = U>( node: parser.ast.SemanticPredicateExpression, ...args ): R;
|
||||
semantic_not<R = U>( node: parser.ast.SemanticPredicateExpression, ...args ): R;
|
||||
group<R = U>( node: parser.ast.GroupExpression, ...args ): R;
|
||||
[ key: string ]: any;
|
||||
grammar?<R = U>( node: Grammar, ...args ): R;
|
||||
initializer?<R = U>( node: parser.ast.Initializer, ...args ): R;
|
||||
rule?<R = U>( node: parser.ast.Rule, ...args ): R;
|
||||
named?<R = U>( node: parser.ast.Named, ...args ): R;
|
||||
choice?<R = U>( node: parser.ast.ChoiceExpression, ...args ): R;
|
||||
action?<R = U>( node: parser.ast.ActionExpression, ...args ): R;
|
||||
sequence?<R = U>( node: parser.ast.SequenceExpression, ...args ): R;
|
||||
labeled?<R = U>( node: parser.ast.LabeledExpression, ...args ): R;
|
||||
text?<R = U>( node: parser.ast.PrefixedExpression, ...args ): R;
|
||||
simple_and?<R = U>( node: parser.ast.PrefixedExpression, ...args ): R;
|
||||
simple_not?<R = U>( node: parser.ast.PrefixedExpression, ...args ): R;
|
||||
optional?<R = U>( node: parser.ast.SuffixedExpression, ...args ): R;
|
||||
zero_or_more?<R = U>( node: parser.ast.SuffixedExpression, ...args ): R;
|
||||
one_or_more?<R = U>( node: parser.ast.SuffixedExpression, ...args ): R;
|
||||
literal?<R = U>( node: parser.ast.LiteralMatcher, ...args ): R;
|
||||
class?<R = U>( node: parser.ast.CharacterClassMatcher, ...args ): R;
|
||||
any?<R = U>( node: parser.ast.AnyMatcher, ...args ): R;
|
||||
rule_ref?<R = U>( node: parser.ast.RuleReferenceExpression, ...args ): R;
|
||||
semantic_and?<R = U>( node: parser.ast.SemanticPredicateExpression, ...args ): R;
|
||||
semantic_not?<R = U>( node: parser.ast.SemanticPredicateExpression, ...args ): R;
|
||||
group?<R = U>( node: parser.ast.GroupExpression, ...args ): R;
|
||||
|
||||
}
|
||||
|
||||
function build<T = void, R = any>( functions: VisitorMap<T> ): Visitor<R>;
|
||||
class visitor implements IVisitorMap {
|
||||
|
||||
visit: IVisitor;
|
||||
|
||||
static build<T = void, R = any>( functions: IVisitorMap<T> ): IVisitor<R>;
|
||||
static ASTVisitor: visitor;
|
||||
|
||||
}
|
||||
|
||||
|
@ -403,21 +407,7 @@ declare namespace peg {
|
|||
function extend( target: {}, source: {} ): {};
|
||||
function map( object: {}, transformer: IIterator ): {};
|
||||
function values( object: {}, transformer?: IIterator ): any[];
|
||||
|
||||
interface IVisitor {
|
||||
|
||||
( value: {} ): void;
|
||||
|
||||
}
|
||||
|
||||
interface IVisitorCallback {
|
||||
|
||||
( value: any ): void;
|
||||
( value: any, args: any[] ): void;
|
||||
|
||||
}
|
||||
|
||||
function createVisitor( property: string | number, visit: IVisitorCallback ): IVisitor;
|
||||
function enforceFastProperties( o: {} ): {};
|
||||
|
||||
}
|
||||
|
||||
|
|
34
lib/typings/modules.d.ts
vendored
34
lib/typings/modules.d.ts
vendored
|
@ -18,6 +18,38 @@ declare module "pegjs/lib/parser" {
|
|||
|
||||
}
|
||||
|
||||
declare module "pegjs/lib/parser/ast" {
|
||||
|
||||
export class Node {
|
||||
|
||||
type: string;
|
||||
location: peg.SourceLocation;
|
||||
|
||||
constructor( type: string, location: peg.SourceLocation );
|
||||
|
||||
}
|
||||
|
||||
export class Grammar extends Node {
|
||||
|
||||
initializer?: peg.parser.ast.Initializer;
|
||||
rules: peg.parser.ast.Rule[];
|
||||
|
||||
constructor(
|
||||
initializer: void | peg.parser.ast.Initializer,
|
||||
rules: peg.parser.ast.Rule[],
|
||||
location: peg.SourceLocation,
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
declare module "pegjs/lib/parser/index" {
|
||||
|
||||
export default peg.parser;
|
||||
|
||||
}
|
||||
|
||||
declare module "pegjs/lib/peg" {
|
||||
|
||||
export default peg;
|
||||
|
@ -161,7 +193,7 @@ declare module "pegjs/lib/util/objects" {
|
|||
function extend( target: {}, source: {} ): {};
|
||||
function map( object: {}, transformer: peg.util.IIterator ): {};
|
||||
function values( object: {}, transformer?: peg.util.IIterator ): any[];
|
||||
function createVisitor( property: string | number, visit: peg.util.IVisitorCallback ): peg.util.IVisitor;
|
||||
function enforceFastProperties( o: {} ): {};
|
||||
|
||||
}
|
||||
export default objects;
|
||||
|
|
|
@ -97,18 +97,6 @@ const objects = {
|
|||
|
||||
},
|
||||
|
||||
// Will return a function that can be used to visit a specific property
|
||||
// no matter what object is passed to it.
|
||||
createVisitor( property, visit ) {
|
||||
|
||||
return function visitProperty( object ) {
|
||||
|
||||
visit( object[ property ], __slice.call( arguments, 1 ) );
|
||||
|
||||
};
|
||||
|
||||
},
|
||||
|
||||
// Will ensure on V8 that that property access is always in fast mode
|
||||
// See: https://stackoverflow.com/a/24989927/1518408
|
||||
enforceFastProperties( o ) {
|
||||
|
|
Loading…
Reference in a new issue