good-enough-parser
Advanced tools
Comparing version 1.1.7 to 1.1.8
import type { Cursor } from '../parser/types'; | ||
import { QueryBuilder } from '../query/types'; | ||
import type { QueryBuilder } from '../query/types'; | ||
import type { LanguageConfig } from './types'; | ||
@@ -12,5 +12,10 @@ export * from './types'; | ||
} | ||
declare type LanguagePreset = 'groovy' | 'python'; | ||
declare const languagePresets: { | ||
groovy: LanguageConfig; | ||
python: LanguageConfig; | ||
starlark: LanguageConfig; | ||
}; | ||
declare type LanguagePreset = keyof typeof languagePresets; | ||
export declare function createLang(key: LanguagePreset): Language; | ||
export declare function createLang(config: LanguageConfig): Language; | ||
//# sourceMappingURL=index.d.ts.map |
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); | ||
var desc = Object.getOwnPropertyDescriptor(m, k); | ||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
desc = { enumerable: true, get: function() { return m[k]; } }; | ||
} | ||
Object.defineProperty(o, k2, desc); | ||
}) : (function(o, m, k, k2) { | ||
@@ -20,2 +24,3 @@ if (k2 === undefined) k2 = k; | ||
const python_1 = require("./python"); | ||
const starlark_1 = require("./starlark"); | ||
__exportStar(require("./types"), exports); | ||
@@ -44,2 +49,3 @@ class Language { | ||
python: python_1.lang, | ||
starlark: starlark_1.lang, | ||
}; | ||
@@ -46,0 +52,0 @@ function createLang(arg1) { |
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); | ||
var desc = Object.getOwnPropertyDescriptor(m, k); | ||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
desc = { enumerable: true, get: function() { return m[k]; } }; | ||
} | ||
Object.defineProperty(o, k2, desc); | ||
}) : (function(o, m, k, k2) { | ||
@@ -6,0 +10,0 @@ if (k2 === undefined) k2 = k; |
@@ -1,2 +0,2 @@ | ||
import { FallbackRule, StateDefinition, StatesMap } from './types'; | ||
import type { FallbackRule, StateDefinition, StatesMap } from './types'; | ||
export declare const fallbackRule: FallbackRule; | ||
@@ -3,0 +3,0 @@ export declare function sortStateRules(state: StateDefinition): StateDefinition; |
import type { Token as MooToken } from 'moo'; | ||
import { Token } from './types'; | ||
import type { Token } from './types'; | ||
export declare function coerceToken({ type, value, offset, line, col, lineBreaks, }: MooToken): Token; | ||
//# sourceMappingURL=token.d.ts.map |
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); | ||
var desc = Object.getOwnPropertyDescriptor(m, k); | ||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
desc = { enumerable: true, get: function() { return m[k]; } }; | ||
} | ||
Object.defineProperty(o, k2, desc); | ||
}) : (function(o, m, k, k2) { | ||
@@ -6,0 +10,0 @@ if (k2 === undefined) k2 = k; |
@@ -1,2 +0,2 @@ | ||
import type { StringTree, TreeType } from '../parser/types'; | ||
import type { TreeType } from '../parser/types'; | ||
import { AltMatcher, ManyMatcher, OpMatcher, SeqMatcher, SymMatcher } from './matchers'; | ||
@@ -8,3 +8,3 @@ import { AnchorMatcher } from './matchers/anchor-matcher'; | ||
import { TreeMatcher } from './matchers/tree-matcher'; | ||
import type { CommentMatcherHandler, CommentMatcherOptions, CommentMatcherValue, Matcher, NodeHandler, NumMatcherHandler, NumMatcherOptions, NumMatcherValue, OpMatcherHandler, OpMatcherOptions, OpMatcherValue, QueryBuilder, SymMatcherHandler, SymMatcherOptions, SymMatcherValue, TreeOptionsBase } from './types'; | ||
import type { CommentMatcherHandler, CommentMatcherOptions, CommentMatcherValue, ManyBuilderOpts, Matcher, NumMatcherHandler, NumMatcherOptions, NumMatcherValue, OpMatcherHandler, OpMatcherOptions, OpMatcherValue, QueryBuilder, StrBuilderOptions, StrTreeBuilderOptions, StrTreeBuilderOptionsBase, SymMatcherHandler, SymMatcherOptions, SymMatcherValue, TreeBuilderOptions } from './types'; | ||
declare abstract class TerminalBuilder<Ctx> implements QueryBuilder<Ctx> { | ||
@@ -102,7 +102,2 @@ abstract build(): Matcher<Ctx>; | ||
export declare function num<Ctx>(opts: NumMatcherOptions<Ctx>): NumBuilder<Ctx>; | ||
export interface ManyBuilderOpts<Ctx> { | ||
builder: QueryBuilder<Ctx>; | ||
min: number; | ||
max: number | null; | ||
} | ||
declare class ManyBuilder<Ctx> extends AbstractBuilder<Ctx> { | ||
@@ -122,5 +117,2 @@ private opts; | ||
export declare function alt<Ctx>(...builders: QueryBuilder<Ctx>[]): AltBuilder<Ctx>; | ||
export interface TreeBuilderOptions<Ctx> extends TreeOptionsBase<Ctx> { | ||
search?: QueryBuilder<Ctx> | null; | ||
} | ||
declare class TreeBuilder<Ctx> extends AbstractBuilder<Ctx> { | ||
@@ -134,19 +126,2 @@ private opts; | ||
export declare function tree<Ctx>(opts: TreeBuilderOptions<Ctx>): TreeBuilder<Ctx>; | ||
export interface StrContentBuilderOptionsBase<Ctx> { | ||
match?: string | RegExp | null; | ||
handler?: StrContentMatcherHandler<Ctx> | null; | ||
} | ||
export interface StrTreeBuilderOptionsBase<Ctx> { | ||
match?: (string | RegExp | QueryBuilder<Ctx>)[] | null; | ||
preHandler?: NodeHandler<Ctx, StringTree> | null; | ||
postHandler?: NodeHandler<Ctx, StringTree> | null; | ||
} | ||
export declare type StrBuilderOptionsBase<Ctx> = StrContentBuilderOptionsBase<Ctx> | StrTreeBuilderOptionsBase<Ctx>; | ||
export interface StrContentBuilderOptions<Ctx> extends StrContentBuilderOptionsBase<Ctx> { | ||
type: 'str-content'; | ||
} | ||
export interface StrTreeBuilderOptions<Ctx> extends StrTreeBuilderOptionsBase<Ctx> { | ||
type: 'str-tree'; | ||
} | ||
export declare type StrBuilderOptions<Ctx> = StrContentBuilderOptions<Ctx> | StrTreeBuilderOptions<Ctx>; | ||
declare class StrBuilder<Ctx> extends AbstractBuilder<Ctx> { | ||
@@ -153,0 +128,0 @@ private opts; |
@@ -10,2 +10,3 @@ "use strict"; | ||
const tree_matcher_1 = require("./matchers/tree-matcher"); | ||
const options_1 = require("./options"); | ||
const regex_1 = require("./regex"); | ||
@@ -16,3 +17,3 @@ class TerminalBuilder { | ||
sym(arg1, arg2) { | ||
const opts = coerceSymOptions(arg1, arg2); | ||
const opts = (0, options_1.coerceSymOptions)(arg1, arg2); | ||
const builder = new SymBuilder(opts); | ||
@@ -22,3 +23,3 @@ return new SeqBuilder(this, builder); | ||
op(arg1, arg2) { | ||
const opts = coerceOpOptions(arg1, arg2); | ||
const opts = (0, options_1.coerceOpOptions)(arg1, arg2); | ||
const builder = new OpBuilder(opts); | ||
@@ -28,3 +29,3 @@ return new SeqBuilder(this, builder); | ||
comment(arg1, arg2) { | ||
const opts = coerceCommentOptions(arg1, arg2); | ||
const opts = (0, options_1.coerceCommentOptions)(arg1, arg2); | ||
const builder = new CommentBuilder(opts); | ||
@@ -34,3 +35,3 @@ return new SeqBuilder(this, builder); | ||
num(arg1, arg2) { | ||
const opts = coerceNumOptions(arg1, arg2); | ||
const opts = (0, options_1.coerceNumOptions)(arg1, arg2); | ||
const builder = new NumBuilder(opts); | ||
@@ -40,3 +41,3 @@ return new SeqBuilder(this, builder); | ||
many(arg1, arg2, arg3) { | ||
const opts = coerceManyOptions(arg1, arg2, arg3); | ||
const opts = (0, options_1.coerceManyOptions)(arg1, arg2, arg3); | ||
const builder = new ManyBuilder(opts); | ||
@@ -46,3 +47,3 @@ return new SeqBuilder(this, builder); | ||
opt(innerBuilder) { | ||
const opts = coerceManyOptions(innerBuilder, 0, 1); | ||
const opts = (0, options_1.coerceManyOptions)(innerBuilder, 0, 1); | ||
const builder = new ManyBuilder(opts); | ||
@@ -56,3 +57,3 @@ return new SeqBuilder(this, builder); | ||
tree(arg1) { | ||
const opts = coerceTreeOptions(arg1); | ||
const opts = (0, options_1.coerceTreeOptions)(arg1); | ||
const builder = new TreeBuilder(opts); | ||
@@ -62,3 +63,3 @@ return new SeqBuilder(this, builder); | ||
str(arg1, arg2) { | ||
const opts = coerceStrOptions(arg1, arg2); | ||
const opts = (0, options_1.coerceStrOptions)(arg1, arg2); | ||
const builder = new StrBuilder(opts); | ||
@@ -117,22 +118,4 @@ return new SeqBuilder(this, builder); | ||
} | ||
function coerceSymOptions(arg1, arg2) { | ||
if (typeof arg1 === 'string' || (0, regex_1.isRegex)(arg1)) { | ||
return { | ||
value: arg1, | ||
handler: arg2 !== null && arg2 !== void 0 ? arg2 : null, | ||
}; | ||
} | ||
if (typeof arg1 === 'function') { | ||
return { | ||
value: null, | ||
handler: arg1, | ||
}; | ||
} | ||
if (arg1 !== null && typeof arg1 === 'object') { | ||
return arg1; | ||
} | ||
return { value: null, handler: null }; | ||
} | ||
function sym(arg1, arg2) { | ||
const opts = coerceSymOptions(arg1, arg2); | ||
const opts = (0, options_1.coerceSymOptions)(arg1, arg2); | ||
return new SymBuilder(opts); | ||
@@ -151,22 +134,4 @@ } | ||
} | ||
function coerceOpOptions(arg1, arg2) { | ||
if (typeof arg1 === 'string' || (0, regex_1.isRegex)(arg1)) { | ||
return { | ||
value: arg1, | ||
handler: arg2 !== null && arg2 !== void 0 ? arg2 : null, | ||
}; | ||
} | ||
if (typeof arg1 === 'function') { | ||
return { | ||
value: null, | ||
handler: arg1, | ||
}; | ||
} | ||
if (arg1 !== null && typeof arg1 === 'object') { | ||
return arg1; | ||
} | ||
return { value: null, handler: null }; | ||
} | ||
function op(arg1, arg2) { | ||
const opts = coerceOpOptions(arg1, arg2); | ||
const opts = (0, options_1.coerceOpOptions)(arg1, arg2); | ||
return new OpBuilder(opts); | ||
@@ -185,22 +150,4 @@ } | ||
} | ||
function coerceCommentOptions(arg1, arg2) { | ||
if (typeof arg1 === 'string' || (0, regex_1.isRegex)(arg1)) { | ||
return { | ||
value: arg1, | ||
handler: arg2 !== null && arg2 !== void 0 ? arg2 : null, | ||
}; | ||
} | ||
if (typeof arg1 === 'function') { | ||
return { | ||
value: null, | ||
handler: arg1, | ||
}; | ||
} | ||
if (arg1 !== null && typeof arg1 === 'object') { | ||
return arg1; | ||
} | ||
return { value: null, handler: null }; | ||
} | ||
function comment(arg1, arg2) { | ||
const opts = coerceCommentOptions(arg1, arg2); | ||
const opts = (0, options_1.coerceCommentOptions)(arg1, arg2); | ||
return new CommentBuilder(opts); | ||
@@ -219,25 +166,8 @@ } | ||
} | ||
function coerceNumOptions(arg1, arg2) { | ||
if (typeof arg1 === 'string' || (0, regex_1.isRegex)(arg1)) { | ||
return { | ||
value: arg1, | ||
handler: arg2 !== null && arg2 !== void 0 ? arg2 : null, | ||
}; | ||
} | ||
if (typeof arg1 === 'function') { | ||
return { | ||
value: null, | ||
handler: arg1, | ||
}; | ||
} | ||
if (arg1 !== null && typeof arg1 === 'object') { | ||
return arg1; | ||
} | ||
return { value: null, handler: null }; | ||
} | ||
function num(arg1, arg2) { | ||
const opts = coerceNumOptions(arg1, arg2); | ||
const opts = (0, options_1.coerceNumOptions)(arg1, arg2); | ||
return new NumBuilder(opts); | ||
} | ||
exports.num = num; | ||
// Repetitive patterns | ||
class ManyBuilder extends AbstractBuilder { | ||
@@ -253,10 +183,4 @@ constructor(opts) { | ||
} | ||
function coerceManyOptions(builder, arg2, arg3) { | ||
if (typeof arg2 === 'number' && typeof arg3 === 'number') { | ||
return { builder, min: arg2, max: arg3 }; | ||
} | ||
return { builder, min: 1, max: null }; | ||
} | ||
function many(arg1, arg2, arg3) { | ||
const opts = coerceManyOptions(arg1, arg2, arg3); | ||
const opts = (0, options_1.coerceManyOptions)(arg1, arg2, arg3); | ||
return new ManyBuilder(opts); | ||
@@ -266,3 +190,3 @@ } | ||
function opt(builder) { | ||
const opts = coerceManyOptions(builder, 0, 1); | ||
const opts = (0, options_1.coerceManyOptions)(builder, 0, 1); | ||
return new ManyBuilder(opts); | ||
@@ -286,2 +210,3 @@ } | ||
exports.alt = alt; | ||
// Trees | ||
class TreeBuilder extends AbstractBuilder { | ||
@@ -299,18 +224,8 @@ constructor(opts) { | ||
} | ||
function coerceTreeOptions(arg1) { | ||
if (typeof arg1 === 'string') { | ||
return { type: arg1 }; | ||
} | ||
else if (!arg1) { | ||
return { type: null }; | ||
} | ||
else { | ||
return arg1; | ||
} | ||
} | ||
function tree(arg1) { | ||
const opts = coerceTreeOptions(arg1); | ||
const opts = (0, options_1.coerceTreeOptions)(arg1); | ||
return new TreeBuilder(opts); | ||
} | ||
exports.tree = tree; | ||
// Strings | ||
class StrBuilder extends AbstractBuilder { | ||
@@ -376,53 +291,4 @@ constructor(opts) { | ||
} | ||
function coerceStrOptions(arg1, arg2) { | ||
if (typeof arg1 === 'string' || (0, regex_1.isRegex)(arg1)) { | ||
if (arg1 === '') { | ||
return { | ||
type: 'str-tree', | ||
match: [], | ||
postHandler: arg2 | ||
? (ctx, tree) => arg2(ctx, { | ||
...tree.startsWith, | ||
type: 'string-value', | ||
value: arg1, | ||
}) | ||
: null, | ||
}; | ||
} | ||
return { | ||
type: 'str-content', | ||
match: arg1, | ||
handler: arg2 !== null && arg2 !== void 0 ? arg2 : null, | ||
}; | ||
} | ||
else if (typeof arg1 === 'function') { | ||
return { | ||
type: 'str-content', | ||
match: null, | ||
handler: arg1, | ||
}; | ||
} | ||
else if (arg1) { | ||
if (arg1['handler'] || | ||
typeof arg1.match === 'string' || | ||
(0, regex_1.isRegex)(arg1.match)) { | ||
return { | ||
type: 'str-content', | ||
...arg1, | ||
}; | ||
} | ||
return { | ||
type: 'str-tree', | ||
...arg1, | ||
}; | ||
} | ||
return { | ||
type: 'str-tree', | ||
match: null, | ||
preHandler: null, | ||
postHandler: null, | ||
}; | ||
} | ||
function str(arg1, arg2) { | ||
const opts = coerceStrOptions(arg1, arg2); | ||
const opts = (0, options_1.coerceStrOptions)(arg1, arg2); | ||
return new StrBuilder(opts); | ||
@@ -429,0 +295,0 @@ } |
@@ -1,3 +0,3 @@ | ||
import { Node } from '../parser/types'; | ||
import type { Node } from '../parser/types'; | ||
export declare function safeHandler<Ctx, T extends Node = Node>(handler: ((ctx: Ctx, token: T) => Ctx) | null | undefined): (ctx: Ctx, token: T) => Ctx; | ||
//# sourceMappingURL=handler.d.ts.map |
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); | ||
var desc = Object.getOwnPropertyDescriptor(m, k); | ||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
desc = { enumerable: true, get: function() { return m[k]; } }; | ||
} | ||
Object.defineProperty(o, k2, desc); | ||
}) : (function(o, m, k, k2) { | ||
@@ -6,0 +10,0 @@ if (k2 === undefined) k2 = k; |
@@ -1,2 +0,2 @@ | ||
import { Node } from '../../parser'; | ||
import type { Node } from '../../parser'; | ||
import type { Checkpoint, CommentMatcherHandler, CommentMatcherOptions, CommentMatcherValue } from '../types'; | ||
@@ -3,0 +3,0 @@ import { AbstractMatcher } from './abstract-matcher'; |
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); | ||
var desc = Object.getOwnPropertyDescriptor(m, k); | ||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
desc = { enumerable: true, get: function() { return m[k]; } }; | ||
} | ||
Object.defineProperty(o, k2, desc); | ||
}) : (function(o, m, k, k2) { | ||
@@ -6,0 +10,0 @@ if (k2 === undefined) k2 = k; |
@@ -1,3 +0,3 @@ | ||
import { StringValueToken } from '../../lexer/types'; | ||
import { TemplateTree } from '../../parser/types'; | ||
import type { StringValueToken } from '../../lexer/types'; | ||
import type { TemplateTree } from '../../parser/types'; | ||
import type { Checkpoint, Matcher, NodeHandler, StrTplOptionsBase, StrTreeHandler, StrTreeOptionsBase } from '../types'; | ||
@@ -4,0 +4,0 @@ import { AbstractMatcher } from './abstract-matcher'; |
import type { CommentToken, MinorToken, NumberToken, OperatorToken, SymbolToken } from '../lexer/types'; | ||
import type { Cursor, Node, StringTree, TemplateTree, Tree, TreeType } from '../parser/types'; | ||
import type { StrContentMatcherHandler } from './matchers/str-matcher'; | ||
export interface Checkpoint<Ctx> { | ||
@@ -50,2 +51,7 @@ cursor: Cursor; | ||
} | ||
export interface ManyBuilderOpts<Ctx> { | ||
builder: QueryBuilder<Ctx>; | ||
min: number; | ||
max: number | null; | ||
} | ||
export interface ManyMatcherOptions<Ctx> { | ||
@@ -56,2 +62,5 @@ matcher: Matcher<Ctx>; | ||
} | ||
export interface TreeBuilderOptions<Ctx> extends TreeOptionsBase<Ctx> { | ||
search?: QueryBuilder<Ctx> | null; | ||
} | ||
export interface AltMatcherOptions<Ctx> { | ||
@@ -70,2 +79,19 @@ matchers: Matcher<Ctx>[]; | ||
} | ||
export interface StrContentBuilderOptionsBase<Ctx> { | ||
match?: string | RegExp | null; | ||
handler?: StrContentMatcherHandler<Ctx> | null; | ||
} | ||
export interface StrTreeBuilderOptionsBase<Ctx> { | ||
match?: (string | RegExp | QueryBuilder<Ctx>)[] | null; | ||
preHandler?: NodeHandler<Ctx, StringTree> | null; | ||
postHandler?: NodeHandler<Ctx, StringTree> | null; | ||
} | ||
export declare type StrBuilderOptionsBase<Ctx> = StrContentBuilderOptionsBase<Ctx> | StrTreeBuilderOptionsBase<Ctx>; | ||
export interface StrContentBuilderOptions<Ctx> extends StrContentBuilderOptionsBase<Ctx> { | ||
type: 'str-content'; | ||
} | ||
export interface StrTreeBuilderOptions<Ctx> extends StrTreeBuilderOptionsBase<Ctx> { | ||
type: 'str-tree'; | ||
} | ||
export declare type StrBuilderOptions<Ctx> = StrContentBuilderOptions<Ctx> | StrTreeBuilderOptions<Ctx>; | ||
export interface QueryBuilder<Ctx> { | ||
@@ -72,0 +98,0 @@ build(): Matcher<Ctx>; |
import type { Cursor } from '../parser/types'; | ||
import { QueryBuilder } from '../query/types'; | ||
import type { QueryBuilder } from '../query/types'; | ||
import type { LanguageConfig } from './types'; | ||
@@ -12,5 +12,10 @@ export * from './types'; | ||
} | ||
declare type LanguagePreset = 'groovy' | 'python'; | ||
declare const languagePresets: { | ||
groovy: LanguageConfig; | ||
python: LanguageConfig; | ||
starlark: LanguageConfig; | ||
}; | ||
declare type LanguagePreset = keyof typeof languagePresets; | ||
export declare function createLang(key: LanguagePreset): Language; | ||
export declare function createLang(config: LanguageConfig): Language; | ||
//# sourceMappingURL=index.d.ts.map |
@@ -7,2 +7,3 @@ import { createLexer } from '../lexer'; | ||
import { lang as python } from './python'; | ||
import { lang as starlark } from './starlark'; | ||
export * from './types'; | ||
@@ -30,2 +31,3 @@ export class Language { | ||
python, | ||
starlark, | ||
}; | ||
@@ -32,0 +34,0 @@ export function createLang(arg1) { |
@@ -1,2 +0,2 @@ | ||
import { FallbackRule, StateDefinition, StatesMap } from './types'; | ||
import type { FallbackRule, StateDefinition, StatesMap } from './types'; | ||
export declare const fallbackRule: FallbackRule; | ||
@@ -3,0 +3,0 @@ export declare function sortStateRules(state: StateDefinition): StateDefinition; |
import type { Token as MooToken } from 'moo'; | ||
import { Token } from './types'; | ||
import type { Token } from './types'; | ||
export declare function coerceToken({ type, value, offset, line, col, lineBreaks, }: MooToken): Token; | ||
//# sourceMappingURL=token.d.ts.map |
@@ -1,2 +0,2 @@ | ||
import type { StringTree, TreeType } from '../parser/types'; | ||
import type { TreeType } from '../parser/types'; | ||
import { AltMatcher, ManyMatcher, OpMatcher, SeqMatcher, SymMatcher } from './matchers'; | ||
@@ -8,3 +8,3 @@ import { AnchorMatcher } from './matchers/anchor-matcher'; | ||
import { TreeMatcher } from './matchers/tree-matcher'; | ||
import type { CommentMatcherHandler, CommentMatcherOptions, CommentMatcherValue, Matcher, NodeHandler, NumMatcherHandler, NumMatcherOptions, NumMatcherValue, OpMatcherHandler, OpMatcherOptions, OpMatcherValue, QueryBuilder, SymMatcherHandler, SymMatcherOptions, SymMatcherValue, TreeOptionsBase } from './types'; | ||
import type { CommentMatcherHandler, CommentMatcherOptions, CommentMatcherValue, ManyBuilderOpts, Matcher, NumMatcherHandler, NumMatcherOptions, NumMatcherValue, OpMatcherHandler, OpMatcherOptions, OpMatcherValue, QueryBuilder, StrBuilderOptions, StrTreeBuilderOptions, StrTreeBuilderOptionsBase, SymMatcherHandler, SymMatcherOptions, SymMatcherValue, TreeBuilderOptions } from './types'; | ||
declare abstract class TerminalBuilder<Ctx> implements QueryBuilder<Ctx> { | ||
@@ -102,7 +102,2 @@ abstract build(): Matcher<Ctx>; | ||
export declare function num<Ctx>(opts: NumMatcherOptions<Ctx>): NumBuilder<Ctx>; | ||
export interface ManyBuilderOpts<Ctx> { | ||
builder: QueryBuilder<Ctx>; | ||
min: number; | ||
max: number | null; | ||
} | ||
declare class ManyBuilder<Ctx> extends AbstractBuilder<Ctx> { | ||
@@ -122,5 +117,2 @@ private opts; | ||
export declare function alt<Ctx>(...builders: QueryBuilder<Ctx>[]): AltBuilder<Ctx>; | ||
export interface TreeBuilderOptions<Ctx> extends TreeOptionsBase<Ctx> { | ||
search?: QueryBuilder<Ctx> | null; | ||
} | ||
declare class TreeBuilder<Ctx> extends AbstractBuilder<Ctx> { | ||
@@ -134,19 +126,2 @@ private opts; | ||
export declare function tree<Ctx>(opts: TreeBuilderOptions<Ctx>): TreeBuilder<Ctx>; | ||
export interface StrContentBuilderOptionsBase<Ctx> { | ||
match?: string | RegExp | null; | ||
handler?: StrContentMatcherHandler<Ctx> | null; | ||
} | ||
export interface StrTreeBuilderOptionsBase<Ctx> { | ||
match?: (string | RegExp | QueryBuilder<Ctx>)[] | null; | ||
preHandler?: NodeHandler<Ctx, StringTree> | null; | ||
postHandler?: NodeHandler<Ctx, StringTree> | null; | ||
} | ||
export declare type StrBuilderOptionsBase<Ctx> = StrContentBuilderOptionsBase<Ctx> | StrTreeBuilderOptionsBase<Ctx>; | ||
export interface StrContentBuilderOptions<Ctx> extends StrContentBuilderOptionsBase<Ctx> { | ||
type: 'str-content'; | ||
} | ||
export interface StrTreeBuilderOptions<Ctx> extends StrTreeBuilderOptionsBase<Ctx> { | ||
type: 'str-tree'; | ||
} | ||
export declare type StrBuilderOptions<Ctx> = StrContentBuilderOptions<Ctx> | StrTreeBuilderOptions<Ctx>; | ||
declare class StrBuilder<Ctx> extends AbstractBuilder<Ctx> { | ||
@@ -153,0 +128,0 @@ private opts; |
@@ -7,2 +7,3 @@ import { AltMatcher, ManyMatcher, OpMatcher, SeqMatcher, SymMatcher, } from './matchers'; | ||
import { TreeMatcher } from './matchers/tree-matcher'; | ||
import { coerceCommentOptions, coerceManyOptions, coerceNumOptions, coerceOpOptions, coerceStrOptions, coerceSymOptions, coerceTreeOptions, } from './options'; | ||
import { isRegex } from './regex'; | ||
@@ -105,20 +106,2 @@ class TerminalBuilder { | ||
} | ||
function coerceSymOptions(arg1, arg2) { | ||
if (typeof arg1 === 'string' || isRegex(arg1)) { | ||
return { | ||
value: arg1, | ||
handler: arg2 !== null && arg2 !== void 0 ? arg2 : null, | ||
}; | ||
} | ||
if (typeof arg1 === 'function') { | ||
return { | ||
value: null, | ||
handler: arg1, | ||
}; | ||
} | ||
if (arg1 !== null && typeof arg1 === 'object') { | ||
return arg1; | ||
} | ||
return { value: null, handler: null }; | ||
} | ||
export function sym(arg1, arg2) { | ||
@@ -138,20 +121,2 @@ const opts = coerceSymOptions(arg1, arg2); | ||
} | ||
function coerceOpOptions(arg1, arg2) { | ||
if (typeof arg1 === 'string' || isRegex(arg1)) { | ||
return { | ||
value: arg1, | ||
handler: arg2 !== null && arg2 !== void 0 ? arg2 : null, | ||
}; | ||
} | ||
if (typeof arg1 === 'function') { | ||
return { | ||
value: null, | ||
handler: arg1, | ||
}; | ||
} | ||
if (arg1 !== null && typeof arg1 === 'object') { | ||
return arg1; | ||
} | ||
return { value: null, handler: null }; | ||
} | ||
export function op(arg1, arg2) { | ||
@@ -171,20 +136,2 @@ const opts = coerceOpOptions(arg1, arg2); | ||
} | ||
function coerceCommentOptions(arg1, arg2) { | ||
if (typeof arg1 === 'string' || isRegex(arg1)) { | ||
return { | ||
value: arg1, | ||
handler: arg2 !== null && arg2 !== void 0 ? arg2 : null, | ||
}; | ||
} | ||
if (typeof arg1 === 'function') { | ||
return { | ||
value: null, | ||
handler: arg1, | ||
}; | ||
} | ||
if (arg1 !== null && typeof arg1 === 'object') { | ||
return arg1; | ||
} | ||
return { value: null, handler: null }; | ||
} | ||
export function comment(arg1, arg2) { | ||
@@ -204,20 +151,2 @@ const opts = coerceCommentOptions(arg1, arg2); | ||
} | ||
function coerceNumOptions(arg1, arg2) { | ||
if (typeof arg1 === 'string' || isRegex(arg1)) { | ||
return { | ||
value: arg1, | ||
handler: arg2 !== null && arg2 !== void 0 ? arg2 : null, | ||
}; | ||
} | ||
if (typeof arg1 === 'function') { | ||
return { | ||
value: null, | ||
handler: arg1, | ||
}; | ||
} | ||
if (arg1 !== null && typeof arg1 === 'object') { | ||
return arg1; | ||
} | ||
return { value: null, handler: null }; | ||
} | ||
export function num(arg1, arg2) { | ||
@@ -227,2 +156,3 @@ const opts = coerceNumOptions(arg1, arg2); | ||
} | ||
// Repetitive patterns | ||
class ManyBuilder extends AbstractBuilder { | ||
@@ -238,8 +168,2 @@ constructor(opts) { | ||
} | ||
function coerceManyOptions(builder, arg2, arg3) { | ||
if (typeof arg2 === 'number' && typeof arg3 === 'number') { | ||
return { builder, min: arg2, max: arg3 }; | ||
} | ||
return { builder, min: 1, max: null }; | ||
} | ||
export function many(arg1, arg2, arg3) { | ||
@@ -267,2 +191,3 @@ const opts = coerceManyOptions(arg1, arg2, arg3); | ||
} | ||
// Trees | ||
class TreeBuilder extends AbstractBuilder { | ||
@@ -280,13 +205,2 @@ constructor(opts) { | ||
} | ||
function coerceTreeOptions(arg1) { | ||
if (typeof arg1 === 'string') { | ||
return { type: arg1 }; | ||
} | ||
else if (!arg1) { | ||
return { type: null }; | ||
} | ||
else { | ||
return arg1; | ||
} | ||
} | ||
export function tree(arg1) { | ||
@@ -296,2 +210,3 @@ const opts = coerceTreeOptions(arg1); | ||
} | ||
// Strings | ||
class StrBuilder extends AbstractBuilder { | ||
@@ -357,51 +272,2 @@ constructor(opts) { | ||
} | ||
function coerceStrOptions(arg1, arg2) { | ||
if (typeof arg1 === 'string' || isRegex(arg1)) { | ||
if (arg1 === '') { | ||
return { | ||
type: 'str-tree', | ||
match: [], | ||
postHandler: arg2 | ||
? (ctx, tree) => arg2(ctx, { | ||
...tree.startsWith, | ||
type: 'string-value', | ||
value: arg1, | ||
}) | ||
: null, | ||
}; | ||
} | ||
return { | ||
type: 'str-content', | ||
match: arg1, | ||
handler: arg2 !== null && arg2 !== void 0 ? arg2 : null, | ||
}; | ||
} | ||
else if (typeof arg1 === 'function') { | ||
return { | ||
type: 'str-content', | ||
match: null, | ||
handler: arg1, | ||
}; | ||
} | ||
else if (arg1) { | ||
if (arg1['handler'] || | ||
typeof arg1.match === 'string' || | ||
isRegex(arg1.match)) { | ||
return { | ||
type: 'str-content', | ||
...arg1, | ||
}; | ||
} | ||
return { | ||
type: 'str-tree', | ||
...arg1, | ||
}; | ||
} | ||
return { | ||
type: 'str-tree', | ||
match: null, | ||
preHandler: null, | ||
postHandler: null, | ||
}; | ||
} | ||
export function str(arg1, arg2) { | ||
@@ -408,0 +274,0 @@ const opts = coerceStrOptions(arg1, arg2); |
@@ -1,3 +0,3 @@ | ||
import { Node } from '../parser/types'; | ||
import type { Node } from '../parser/types'; | ||
export declare function safeHandler<Ctx, T extends Node = Node>(handler: ((ctx: Ctx, token: T) => Ctx) | null | undefined): (ctx: Ctx, token: T) => Ctx; | ||
//# sourceMappingURL=handler.d.ts.map |
@@ -1,2 +0,2 @@ | ||
import { Node } from '../../parser'; | ||
import type { Node } from '../../parser'; | ||
import type { Checkpoint, CommentMatcherHandler, CommentMatcherOptions, CommentMatcherValue } from '../types'; | ||
@@ -3,0 +3,0 @@ import { AbstractMatcher } from './abstract-matcher'; |
@@ -1,3 +0,3 @@ | ||
import { StringValueToken } from '../../lexer/types'; | ||
import { TemplateTree } from '../../parser/types'; | ||
import type { StringValueToken } from '../../lexer/types'; | ||
import type { TemplateTree } from '../../parser/types'; | ||
import type { Checkpoint, Matcher, NodeHandler, StrTplOptionsBase, StrTreeHandler, StrTreeOptionsBase } from '../types'; | ||
@@ -4,0 +4,0 @@ import { AbstractMatcher } from './abstract-matcher'; |
import type { CommentToken, MinorToken, NumberToken, OperatorToken, SymbolToken } from '../lexer/types'; | ||
import type { Cursor, Node, StringTree, TemplateTree, Tree, TreeType } from '../parser/types'; | ||
import type { StrContentMatcherHandler } from './matchers/str-matcher'; | ||
export interface Checkpoint<Ctx> { | ||
@@ -50,2 +51,7 @@ cursor: Cursor; | ||
} | ||
export interface ManyBuilderOpts<Ctx> { | ||
builder: QueryBuilder<Ctx>; | ||
min: number; | ||
max: number | null; | ||
} | ||
export interface ManyMatcherOptions<Ctx> { | ||
@@ -56,2 +62,5 @@ matcher: Matcher<Ctx>; | ||
} | ||
export interface TreeBuilderOptions<Ctx> extends TreeOptionsBase<Ctx> { | ||
search?: QueryBuilder<Ctx> | null; | ||
} | ||
export interface AltMatcherOptions<Ctx> { | ||
@@ -70,2 +79,19 @@ matchers: Matcher<Ctx>[]; | ||
} | ||
export interface StrContentBuilderOptionsBase<Ctx> { | ||
match?: string | RegExp | null; | ||
handler?: StrContentMatcherHandler<Ctx> | null; | ||
} | ||
export interface StrTreeBuilderOptionsBase<Ctx> { | ||
match?: (string | RegExp | QueryBuilder<Ctx>)[] | null; | ||
preHandler?: NodeHandler<Ctx, StringTree> | null; | ||
postHandler?: NodeHandler<Ctx, StringTree> | null; | ||
} | ||
export declare type StrBuilderOptionsBase<Ctx> = StrContentBuilderOptionsBase<Ctx> | StrTreeBuilderOptionsBase<Ctx>; | ||
export interface StrContentBuilderOptions<Ctx> extends StrContentBuilderOptionsBase<Ctx> { | ||
type: 'str-content'; | ||
} | ||
export interface StrTreeBuilderOptions<Ctx> extends StrTreeBuilderOptionsBase<Ctx> { | ||
type: 'str-tree'; | ||
} | ||
export declare type StrBuilderOptions<Ctx> = StrContentBuilderOptions<Ctx> | StrTreeBuilderOptions<Ctx>; | ||
export interface QueryBuilder<Ctx> { | ||
@@ -72,0 +98,0 @@ build(): Matcher<Ctx>; |
{ | ||
"name": "good-enough-parser", | ||
"description": "Parse and query computer programs source code", | ||
"version": "1.1.7", | ||
"version": "1.1.8", | ||
"repository": "git@github.com:zharinov/good-enough-parser.git", | ||
@@ -43,31 +43,31 @@ "author": "Sergei Zharinov", | ||
"devDependencies": { | ||
"@homer0/prettier-plugin-jsdoc": "4.0.6", | ||
"@homer0/prettier-plugin-jsdoc": "5.1.1", | ||
"@renovate/eslint-plugin": "https://github.com/renovatebot/eslint-plugin#v0.0.4", | ||
"@types/jest": "27.4.0", | ||
"@types/node": "16.11.18", | ||
"@typescript-eslint/eslint-plugin": "5.9.0", | ||
"@typescript-eslint/parser": "5.9.0", | ||
"eslint": "8.6.0", | ||
"eslint-config-prettier": "8.3.0", | ||
"eslint-plugin-import": "2.25.4", | ||
"@types/jest": "27.5.2", | ||
"@types/node": "16.11.32", | ||
"@typescript-eslint/eslint-plugin": "5.21.0", | ||
"@typescript-eslint/parser": "5.21.0", | ||
"eslint": "8.20.0", | ||
"eslint-config-prettier": "8.5.0", | ||
"eslint-plugin-import": "2.26.0", | ||
"eslint-plugin-only-warn": "1.0.3", | ||
"http-server": "14.0.0", | ||
"http-server": "14.1.1", | ||
"husky": "7.0.4", | ||
"jest": "27.4.5", | ||
"jest": "28.1.3", | ||
"jest-watch-select-projects": "2.0.0", | ||
"jest-watch-suspend": "1.1.2", | ||
"jest-watch-typeahead": "1.0.0", | ||
"jest-watch-typeahead": "1.1.0", | ||
"npm-run-all": "4.1.5", | ||
"prettier": "2.5.1", | ||
"prettier": "2.6.2", | ||
"pretty-quick": "3.1.3", | ||
"release-it": "14.11.8", | ||
"ts-jest": "27.1.2", | ||
"ts-node": "10.4.0", | ||
"release-it": "14.14.3", | ||
"ts-jest": "28.0.7", | ||
"ts-node": "10.8.0", | ||
"ttypescript": "1.5.13", | ||
"typescript": "4.5.4", | ||
"typescript": "4.7.4", | ||
"upath": "2.0.1" | ||
}, | ||
"resolutions": { | ||
"comment-parser": "1.3.0" | ||
"comment-parser": "1.3.1" | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
403916
315
5316