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;
|
module.exports = ASTVisitor;
|
||||||
|
|
||||||
// Helper's to create visitor's for use with the ASTVisitor class
|
// Helper's to create visitor's for use with the ASTVisitor class
|
||||||
|
|
84
lib/typings/api.d.ts
vendored
84
lib/typings/api.d.ts
vendored
|
@ -8,6 +8,7 @@ declare namespace peg {
|
||||||
type Grammar = parser.ast.Grammar;
|
type Grammar = parser.ast.Grammar;
|
||||||
type GeneratedParser<T = any> = gp.API<T>;
|
type GeneratedParser<T = any> = gp.API<T>;
|
||||||
type SyntaxError = gp.SyntaxErrorConstructor;
|
type SyntaxError = gp.SyntaxErrorConstructor;
|
||||||
|
type SourceLocation = gp.SourceLocation;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* PEG.js version (uses semantic versioning).
|
* PEG.js version (uses semantic versioning).
|
||||||
|
@ -21,9 +22,9 @@ declare namespace peg {
|
||||||
|
|
||||||
name: string;
|
name: string;
|
||||||
message: 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 {
|
interface INode {
|
||||||
|
|
||||||
type: string;
|
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: parser.ast.Node, ...args ): R;
|
||||||
|
|
||||||
( node: Node, ...args ): R;
|
}
|
||||||
|
|
||||||
}
|
interface IVisitorMap<U = void> {
|
||||||
|
|
||||||
interface VisitorMap<U = void> {
|
[ 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;
|
||||||
|
|
||||||
[ 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;
|
|
||||||
|
|
||||||
}
|
class visitor implements IVisitorMap {
|
||||||
|
|
||||||
function build<T = void, R = any>( functions: VisitorMap<T> ): Visitor<R>;
|
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 extend( target: {}, source: {} ): {};
|
||||||
function map( object: {}, transformer: IIterator ): {};
|
function map( object: {}, transformer: IIterator ): {};
|
||||||
function values( object: {}, transformer?: IIterator ): any[];
|
function values( object: {}, transformer?: IIterator ): any[];
|
||||||
|
function enforceFastProperties( o: {} ): {};
|
||||||
interface IVisitor {
|
|
||||||
|
|
||||||
( value: {} ): void;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
interface IVisitorCallback {
|
|
||||||
|
|
||||||
( value: any ): void;
|
|
||||||
( value: any, args: any[] ): void;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
function createVisitor( property: string | number, visit: IVisitorCallback ): IVisitor;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
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" {
|
declare module "pegjs/lib/peg" {
|
||||||
|
|
||||||
export default peg;
|
export default peg;
|
||||||
|
@ -161,7 +193,7 @@ declare module "pegjs/lib/util/objects" {
|
||||||
function extend( target: {}, source: {} ): {};
|
function extend( target: {}, source: {} ): {};
|
||||||
function map( object: {}, transformer: peg.util.IIterator ): {};
|
function map( object: {}, transformer: peg.util.IIterator ): {};
|
||||||
function values( object: {}, transformer?: peg.util.IIterator ): any[];
|
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;
|
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
|
// Will ensure on V8 that that property access is always in fast mode
|
||||||
// See: https://stackoverflow.com/a/24989927/1518408
|
// See: https://stackoverflow.com/a/24989927/1518408
|
||||||
enforceFastProperties( o ) {
|
enforceFastProperties( o ) {
|
||||||
|
|
Loading…
Reference in a new issue