@memberjunction/sql-parser 0.0.1 → 5.15.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -0
- package/dist/mj-ast-types.d.ts +234 -0
- package/dist/mj-ast-types.d.ts.map +1 -0
- package/dist/mj-ast-types.js +8 -0
- package/dist/mj-ast-types.js.map +1 -0
- package/dist/mj-lexer.d.ts +88 -0
- package/dist/mj-lexer.d.ts.map +1 -0
- package/dist/mj-lexer.js +431 -0
- package/dist/mj-lexer.js.map +1 -0
- package/dist/mj-placeholder.d.ts +55 -0
- package/dist/mj-placeholder.d.ts.map +1 -0
- package/dist/mj-placeholder.js +156 -0
- package/dist/mj-placeholder.js.map +1 -0
- package/dist/sql-parser.d.ts +288 -0
- package/dist/sql-parser.d.ts.map +1 -0
- package/dist/sql-parser.js +1096 -0
- package/dist/sql-parser.js.map +1 -0
- package/package.json +27 -7
- package/README.md +0 -45
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { SQLParser } from './sql-parser.js';
|
|
2
|
+
export type { MJAstifyResult, SQLTableReference, SQLColumnReference, SQLCTEExtraction, MJParameterInfo, SQLParseResult, SQLParseOptions, } from './sql-parser.js';
|
|
3
|
+
export type { AST as SQLAst } from 'node-sql-parser';
|
|
4
|
+
export type { MJNode, MJNodeType, MJTemplateExpr, MJFilter, MJCompositionRef, MJCompositionParam, MJConditionalBlock, MJBranch, MJLoopBlock, MJComment, MJSetBlock, MJSQLFragment, MJRawSQL, MJTokenType, MJToken, MJTokenParsedContent, MJTemplateExprContent, MJCompositionRefContent, MJBlockTagContent, MJCommentContent, MJSetContent, MJSQLTextContent, PlaceholderContext, PlaceholderEntry, PlaceholderSubstitutionResult, MJParseResult, SQLClauseContext, MJASTAnnotation, MJASTWalkResult, } from './mj-ast-types.js';
|
|
5
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,YAAY,EACR,cAAc,EACd,iBAAiB,EACjB,kBAAkB,EAClB,gBAAgB,EAChB,eAAe,EACf,cAAc,EACd,eAAe,GAClB,MAAM,iBAAiB,CAAC;AAGzB,YAAY,EAAE,GAAG,IAAI,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAGrD,YAAY,EAER,MAAM,EACN,UAAU,EACV,cAAc,EACd,QAAQ,EACR,gBAAgB,EAChB,kBAAkB,EAClB,kBAAkB,EAClB,QAAQ,EACR,WAAW,EACX,SAAS,EACT,UAAU,EACV,aAAa,EACb,QAAQ,EAER,WAAW,EACX,OAAO,EACP,oBAAoB,EACpB,qBAAqB,EACrB,uBAAuB,EACvB,iBAAiB,EACjB,gBAAgB,EAChB,YAAY,EACZ,gBAAgB,EAEhB,kBAAkB,EAClB,gBAAgB,EAChB,6BAA6B,EAE7B,aAAa,EAEb,gBAAgB,EAChB,eAAe,EACf,eAAe,GAClB,MAAM,mBAAmB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,uDAAuD;AACvD,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC"}
|
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MJ SQL Parser AST Type Definitions
|
|
3
|
+
*
|
|
4
|
+
* These types extend the node-sql-parser AST with MemberJunction-specific nodes
|
|
5
|
+
* for Nunjucks templates, composition tokens, and other MJ SQL extensions.
|
|
6
|
+
*/
|
|
7
|
+
/** Discriminated union of all MJ node types */
|
|
8
|
+
export type MJNode = MJTemplateExpr | MJCompositionRef | MJConditionalBlock | MJLoopBlock | MJComment | MJSetBlock | MJRawSQL;
|
|
9
|
+
/** Discriminated union of all MJ node type strings */
|
|
10
|
+
export type MJNodeType = 'mj_template_expr' | 'mj_composition_ref' | 'mj_conditional' | 'mj_loop' | 'mj_comment' | 'mj_set' | 'mj_raw_sql';
|
|
11
|
+
/** A {{ variable | filter1 | filter2 }} expression */
|
|
12
|
+
export interface MJTemplateExpr {
|
|
13
|
+
type: 'mj_template_expr';
|
|
14
|
+
/** The variable name (e.g., "Region", "MinActivityCount") */
|
|
15
|
+
variable: string;
|
|
16
|
+
/** Filter chain applied to the variable */
|
|
17
|
+
filters: MJFilter[];
|
|
18
|
+
/** Original raw text including delimiters */
|
|
19
|
+
raw: string;
|
|
20
|
+
}
|
|
21
|
+
/** A single Nunjucks filter with optional arguments */
|
|
22
|
+
export interface MJFilter {
|
|
23
|
+
/** Filter name (e.g., "sqlString", "sqlNumber", "default") */
|
|
24
|
+
name: string;
|
|
25
|
+
/** Filter arguments (e.g., for default('N/A') → args: ['N/A']) */
|
|
26
|
+
args: (string | number)[];
|
|
27
|
+
}
|
|
28
|
+
/** A {{query:"path/Name(params)"}} composition reference */
|
|
29
|
+
export interface MJCompositionRef {
|
|
30
|
+
type: 'mj_composition_ref';
|
|
31
|
+
/** Category path segments (e.g., "Engagement Analytics") */
|
|
32
|
+
categoryPath: string;
|
|
33
|
+
/** Query name (e.g., "Member Activity Counts") */
|
|
34
|
+
queryName: string;
|
|
35
|
+
/** Parameters passed to the referenced query */
|
|
36
|
+
parameters: MJCompositionParam[];
|
|
37
|
+
/** Original raw text including delimiters */
|
|
38
|
+
raw: string;
|
|
39
|
+
}
|
|
40
|
+
/** A single parameter in a composition reference */
|
|
41
|
+
export interface MJCompositionParam {
|
|
42
|
+
/** Parameter key name */
|
|
43
|
+
key: string;
|
|
44
|
+
/** Parameter value (literal string or variable name) */
|
|
45
|
+
value: string;
|
|
46
|
+
/** true if value is a pass-through variable name, false if literal */
|
|
47
|
+
isPassThrough: boolean;
|
|
48
|
+
}
|
|
49
|
+
/** A {% if %}...{% elif %}...{% else %}...{% endif %} block */
|
|
50
|
+
export interface MJConditionalBlock {
|
|
51
|
+
type: 'mj_conditional';
|
|
52
|
+
/** Ordered branches: first is the if, middle are elifs, last may be else */
|
|
53
|
+
branches: MJBranch[];
|
|
54
|
+
/** Original raw text of the entire block */
|
|
55
|
+
raw: string;
|
|
56
|
+
}
|
|
57
|
+
/** A single branch within a conditional block */
|
|
58
|
+
export interface MJBranch {
|
|
59
|
+
/** Condition expression string, or null for {% else %} */
|
|
60
|
+
condition: string | null;
|
|
61
|
+
/** SQL content inside this branch */
|
|
62
|
+
body: MJSQLFragment;
|
|
63
|
+
}
|
|
64
|
+
/** A {% for x in arr %}...{% endfor %} loop */
|
|
65
|
+
export interface MJLoopBlock {
|
|
66
|
+
type: 'mj_loop';
|
|
67
|
+
/** Loop variable name (e.g., "status") */
|
|
68
|
+
variable: string;
|
|
69
|
+
/** Iterable expression (e.g., "statusList") */
|
|
70
|
+
iterable: string;
|
|
71
|
+
/** SQL content inside the loop body */
|
|
72
|
+
body: MJSQLFragment;
|
|
73
|
+
/** Original raw text of the entire block */
|
|
74
|
+
raw: string;
|
|
75
|
+
}
|
|
76
|
+
/** A {# comment #} */
|
|
77
|
+
export interface MJComment {
|
|
78
|
+
type: 'mj_comment';
|
|
79
|
+
/** Comment text (without delimiters) */
|
|
80
|
+
text: string;
|
|
81
|
+
/** Original raw text including delimiters */
|
|
82
|
+
raw: string;
|
|
83
|
+
}
|
|
84
|
+
/** A {% set var = expr %} assignment */
|
|
85
|
+
export interface MJSetBlock {
|
|
86
|
+
type: 'mj_set';
|
|
87
|
+
/** Variable name being assigned */
|
|
88
|
+
variable: string;
|
|
89
|
+
/** Expression being assigned */
|
|
90
|
+
expression: string;
|
|
91
|
+
/** Original raw text including delimiters */
|
|
92
|
+
raw: string;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* SQL fragment inside conditional/loop blocks.
|
|
96
|
+
* May be incomplete SQL (e.g., "AND Status = {{ Status | sqlString }}").
|
|
97
|
+
* Stored as raw text with extracted MJ tokens.
|
|
98
|
+
*/
|
|
99
|
+
export interface MJSQLFragment {
|
|
100
|
+
/** Original raw SQL text (may contain MJ tokens) */
|
|
101
|
+
raw: string;
|
|
102
|
+
/** Ordered list of MJ nodes found within this fragment */
|
|
103
|
+
nodes: MJNode[];
|
|
104
|
+
}
|
|
105
|
+
/** Unparseable SQL text preserved verbatim */
|
|
106
|
+
export interface MJRawSQL {
|
|
107
|
+
type: 'mj_raw_sql';
|
|
108
|
+
/** The raw SQL text */
|
|
109
|
+
text: string;
|
|
110
|
+
}
|
|
111
|
+
/** Discriminated union of all lexer token types */
|
|
112
|
+
export type MJTokenType = 'MJ_TEMPLATE_EXPR' | 'MJ_COMPOSITION_REF' | 'MJ_IF_OPEN' | 'MJ_ELIF' | 'MJ_ELSE' | 'MJ_ENDIF' | 'MJ_FOR_OPEN' | 'MJ_ENDFOR' | 'MJ_SET' | 'MJ_COMMENT' | 'SQL_TEXT';
|
|
113
|
+
/** A single lexer token with position tracking */
|
|
114
|
+
export interface MJToken {
|
|
115
|
+
/** Token type */
|
|
116
|
+
type: MJTokenType;
|
|
117
|
+
/** Start position in original SQL (inclusive) */
|
|
118
|
+
start: number;
|
|
119
|
+
/** End position in original SQL (exclusive) */
|
|
120
|
+
end: number;
|
|
121
|
+
/** Original raw text */
|
|
122
|
+
raw: string;
|
|
123
|
+
/** Parsed content specific to the token type */
|
|
124
|
+
parsed: MJTokenParsedContent;
|
|
125
|
+
}
|
|
126
|
+
/** Union of parsed content types for each token type */
|
|
127
|
+
export type MJTokenParsedContent = MJTemplateExprContent | MJCompositionRefContent | MJBlockTagContent | MJCommentContent | MJSetContent | MJSQLTextContent;
|
|
128
|
+
/** Parsed content for MJ_TEMPLATE_EXPR tokens */
|
|
129
|
+
export interface MJTemplateExprContent {
|
|
130
|
+
kind: 'template_expr';
|
|
131
|
+
variable: string;
|
|
132
|
+
filters: MJFilter[];
|
|
133
|
+
}
|
|
134
|
+
/** Parsed content for MJ_COMPOSITION_REF tokens */
|
|
135
|
+
export interface MJCompositionRefContent {
|
|
136
|
+
kind: 'composition_ref';
|
|
137
|
+
categoryPath: string;
|
|
138
|
+
queryName: string;
|
|
139
|
+
parameters: MJCompositionParam[];
|
|
140
|
+
}
|
|
141
|
+
/** Parsed content for block tags (if/elif/else/endif/for/endfor) */
|
|
142
|
+
export interface MJBlockTagContent {
|
|
143
|
+
kind: 'block_tag';
|
|
144
|
+
/** The condition expression for if/elif, loop variable for for, null for else/endif/endfor */
|
|
145
|
+
expression: string | null;
|
|
146
|
+
/** For {% for %}: the loop variable name */
|
|
147
|
+
loopVariable?: string;
|
|
148
|
+
/** For {% for %}: the iterable expression */
|
|
149
|
+
loopIterable?: string;
|
|
150
|
+
}
|
|
151
|
+
/** Parsed content for MJ_COMMENT tokens */
|
|
152
|
+
export interface MJCommentContent {
|
|
153
|
+
kind: 'comment';
|
|
154
|
+
text: string;
|
|
155
|
+
}
|
|
156
|
+
/** Parsed content for MJ_SET tokens */
|
|
157
|
+
export interface MJSetContent {
|
|
158
|
+
kind: 'set';
|
|
159
|
+
variable: string;
|
|
160
|
+
expression: string;
|
|
161
|
+
}
|
|
162
|
+
/** Parsed content for SQL_TEXT tokens */
|
|
163
|
+
export interface MJSQLTextContent {
|
|
164
|
+
kind: 'sql_text';
|
|
165
|
+
text: string;
|
|
166
|
+
}
|
|
167
|
+
/** The SQL context in which a placeholder appears */
|
|
168
|
+
export type PlaceholderContext = 'string' | 'number' | 'identifier' | 'in_list' | 'boolean';
|
|
169
|
+
/** A single placeholder entry in the position map */
|
|
170
|
+
export interface PlaceholderEntry {
|
|
171
|
+
/** The placeholder string inserted into SQL (e.g., "'__MJT_001__'", "42001") */
|
|
172
|
+
placeholder: string;
|
|
173
|
+
/** The original MJ token that was replaced */
|
|
174
|
+
originalToken: MJToken;
|
|
175
|
+
/** The SQL context type of this placeholder */
|
|
176
|
+
context: PlaceholderContext;
|
|
177
|
+
}
|
|
178
|
+
/** Result of placeholder substitution */
|
|
179
|
+
export interface PlaceholderSubstitutionResult {
|
|
180
|
+
/** Clean SQL with all MJ tokens replaced by SQL-safe placeholders */
|
|
181
|
+
cleanSQL: string;
|
|
182
|
+
/** Map from placeholder string to the original token info */
|
|
183
|
+
positionMap: Map<string, PlaceholderEntry>;
|
|
184
|
+
/** Tokens that were NOT substituted (block tags, comments) — they were stripped */
|
|
185
|
+
strippedTokens: MJToken[];
|
|
186
|
+
}
|
|
187
|
+
/** Result of the full MJ SQL parsing pipeline */
|
|
188
|
+
export interface MJParseResult {
|
|
189
|
+
/** All MJ tokens found in the SQL, in source order */
|
|
190
|
+
tokens: MJToken[];
|
|
191
|
+
/** Whether the SQL contains any MJ extensions */
|
|
192
|
+
hasMJExtensions: boolean;
|
|
193
|
+
/** Whether the SQL contains Nunjucks template expressions */
|
|
194
|
+
hasTemplateExpressions: boolean;
|
|
195
|
+
/** Whether the SQL contains composition references */
|
|
196
|
+
hasCompositionRefs: boolean;
|
|
197
|
+
/** Whether the SQL contains conditional blocks */
|
|
198
|
+
hasConditionalBlocks: boolean;
|
|
199
|
+
/** Whether the SQL contains loop blocks */
|
|
200
|
+
hasLoopBlocks: boolean;
|
|
201
|
+
}
|
|
202
|
+
/** The SQL clause where an MJ node was found */
|
|
203
|
+
export type SQLClauseContext = 'select' | 'from' | 'where' | 'join_on' | 'group_by' | 'order_by' | 'having' | 'cte' | 'subquery' | 'unknown';
|
|
204
|
+
/** An annotation mapping a placeholder in the AST to its original MJ node */
|
|
205
|
+
export interface MJASTAnnotation {
|
|
206
|
+
/** Dot-separated path in the AST (e.g., "where.right", "columns[0].expr") */
|
|
207
|
+
path: string;
|
|
208
|
+
/** The placeholder value found in the AST */
|
|
209
|
+
placeholder: string;
|
|
210
|
+
/** The SQL clause context where this placeholder appears */
|
|
211
|
+
clauseContext: SQLClauseContext;
|
|
212
|
+
/** The resolved MJ template expression (if this is a template expr placeholder) */
|
|
213
|
+
templateExpr: MJTemplateExpr | null;
|
|
214
|
+
/** The resolved MJ composition ref (if this is a composition ref placeholder) */
|
|
215
|
+
compositionRef: MJCompositionRef | null;
|
|
216
|
+
/** The placeholder context type (string, number, identifier, etc.) */
|
|
217
|
+
placeholderContext: PlaceholderContext;
|
|
218
|
+
/** The raw AST node that contains the placeholder */
|
|
219
|
+
astNode: Record<string, unknown>;
|
|
220
|
+
}
|
|
221
|
+
/** Result of walking the AST to annotate MJ placeholder positions */
|
|
222
|
+
export interface MJASTWalkResult {
|
|
223
|
+
/** All annotations found, in walk order */
|
|
224
|
+
annotations: MJASTAnnotation[];
|
|
225
|
+
/** Annotations grouped by SQL clause context */
|
|
226
|
+
byClause: Map<SQLClauseContext, MJASTAnnotation[]>;
|
|
227
|
+
/** Annotations indexed by placeholder string for quick lookup */
|
|
228
|
+
byPlaceholder: Map<string, MJASTAnnotation>;
|
|
229
|
+
/** Annotations for template expressions only */
|
|
230
|
+
templateExprs: MJASTAnnotation[];
|
|
231
|
+
/** Annotations for composition refs only */
|
|
232
|
+
compositionRefs: MJASTAnnotation[];
|
|
233
|
+
}
|
|
234
|
+
//# sourceMappingURL=mj-ast-types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mj-ast-types.d.ts","sourceRoot":"","sources":["../src/mj-ast-types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAMH,+CAA+C;AAC/C,MAAM,MAAM,MAAM,GACZ,cAAc,GACd,gBAAgB,GAChB,kBAAkB,GAClB,WAAW,GACX,SAAS,GACT,UAAU,GACV,QAAQ,CAAC;AAEf,sDAAsD;AACtD,MAAM,MAAM,UAAU,GAChB,kBAAkB,GAClB,oBAAoB,GACpB,gBAAgB,GAChB,SAAS,GACT,YAAY,GACZ,QAAQ,GACR,YAAY,CAAC;AAEnB,sDAAsD;AACtD,MAAM,WAAW,cAAc;IAC3B,IAAI,EAAE,kBAAkB,CAAC;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M,WAAW,eAAe;IAC5B,2CAA2C;IAC3C,WAAW,EAAE,eAAe,EAAE,CAAC;IAC/B,gDAAgD;IAChD,QAAQ,EAAE,GAAG,CAAC,gBAAgB,EAAE,eAAe,EAAE,CAAC,CAAC;IACnD,iEAAiE;IACjE,aAAa,EAAE,GAAG,CAAC,MAAM,EAAE,eAAe,CAAC,CAAC;IAC5C,gDAAgD;IAChD,aAAa,EAAE,eAAe,EAAE,CAAC;IACjC,4CAA4C;IAC5C,eAAe,EAAE,eAAe,EAAE,CAAC;CACtC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MJ SQL Parser AST Type Definitions
|
|
3
|
+
*
|
|
4
|
+
* These types extend the node-sql-parser AST with MemberJunction-specific nodes
|
|
5
|
+
* for Nunjucks templates, composition tokens, and other MJ SQL extensions.
|
|
6
|
+
*/
|
|
7
|
+
export {};
|
|
8
|
+
//# sourceMappingURL=mj-ast-types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mj-ast-types.js","sourceRoot":"","sources":["../src/mj-ast-types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG"}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MJ Lexer — Tokenizes MJ SQL extensions (Nunjucks templates, composition tokens)
|
|
3
|
+
*
|
|
4
|
+
* Scans SQL character-by-character, extracting MJ tokens while preserving
|
|
5
|
+
* position information for later placeholder substitution and reconstruction.
|
|
6
|
+
*
|
|
7
|
+
* The three MJ syntax layers have unambiguous delimiters:
|
|
8
|
+
* - {{ ... }} — Template expressions and composition references
|
|
9
|
+
* - {% ... %} — Block tags (if/elif/else/endif/for/endfor/set)
|
|
10
|
+
* - {# ... #} — Template comments
|
|
11
|
+
*
|
|
12
|
+
* None of these sequences appear in valid SQL, so the lexer can reliably
|
|
13
|
+
* distinguish MJ tokens from SQL text without context-sensitive parsing.
|
|
14
|
+
*/
|
|
15
|
+
import { MJToken, MJFilter, MJParseResult } from './mj-ast-types.js';
|
|
16
|
+
/**
|
|
17
|
+
* Tokenizes MJ SQL into an ordered list of MJ tokens and SQL text segments.
|
|
18
|
+
*/
|
|
19
|
+
export declare class MJLexer {
|
|
20
|
+
/**
|
|
21
|
+
* Tokenize a SQL string containing MJ extensions.
|
|
22
|
+
* Returns tokens in source order, with SQL_TEXT tokens for non-MJ segments.
|
|
23
|
+
*/
|
|
24
|
+
static Tokenize(sql: string): MJToken[];
|
|
25
|
+
/**
|
|
26
|
+
* Convenience method that tokenizes and returns a summary result.
|
|
27
|
+
*/
|
|
28
|
+
static Parse(sql: string): MJParseResult;
|
|
29
|
+
/**
|
|
30
|
+
* Reads a double-delimited token (e.g., {{ ... }}, {% ... %}, {# ... #}).
|
|
31
|
+
* Returns null if the closing delimiter is not found.
|
|
32
|
+
*/
|
|
33
|
+
private static readDoubleDelimited;
|
|
34
|
+
/**
|
|
35
|
+
* Flushes accumulated SQL text as a SQL_TEXT token.
|
|
36
|
+
*/
|
|
37
|
+
private static flushSQLText;
|
|
38
|
+
/**
|
|
39
|
+
* Parses the content of a {{ ... }} token.
|
|
40
|
+
* Determines if it's a composition reference or a template expression.
|
|
41
|
+
*/
|
|
42
|
+
private static parseExpressionToken;
|
|
43
|
+
/**
|
|
44
|
+
* Parses a template expression like: Region | sqlString | default('US')
|
|
45
|
+
*/
|
|
46
|
+
private static parseTemplateExpr;
|
|
47
|
+
/**
|
|
48
|
+
* Parses a filter chain like: "varName | filter1 | filter2('arg')"
|
|
49
|
+
* into a variable name and filter array.
|
|
50
|
+
*/
|
|
51
|
+
static parseFilterChain(content: string): {
|
|
52
|
+
variable: string;
|
|
53
|
+
filters: MJFilter[];
|
|
54
|
+
};
|
|
55
|
+
/**
|
|
56
|
+
* Splits on pipe characters, respecting quoted strings and parentheses.
|
|
57
|
+
*/
|
|
58
|
+
private static splitPipes;
|
|
59
|
+
/**
|
|
60
|
+
* Parses a single filter like "sqlString", "default('N/A')", or "sqlNumber".
|
|
61
|
+
*/
|
|
62
|
+
private static parseSingleFilter;
|
|
63
|
+
/**
|
|
64
|
+
* Parses filter arguments, handling quoted strings and numeric literals.
|
|
65
|
+
*/
|
|
66
|
+
private static parseFilterArgs;
|
|
67
|
+
/**
|
|
68
|
+
* Parses a composition reference like: query:"Path/Name(p1='v1', p2=var)"
|
|
69
|
+
*/
|
|
70
|
+
private static parseCompositionRef;
|
|
71
|
+
/**
|
|
72
|
+
* Parses composition parameters like: p1='literal', p2=variable, p3={{nunjucks}}
|
|
73
|
+
*/
|
|
74
|
+
private static parseCompositionParams;
|
|
75
|
+
/**
|
|
76
|
+
* Splits composition argument string on commas, respecting nested {{ }} and quotes.
|
|
77
|
+
*/
|
|
78
|
+
private static splitCompositionArgs;
|
|
79
|
+
/**
|
|
80
|
+
* Parses a block tag and returns the appropriate token type.
|
|
81
|
+
*/
|
|
82
|
+
private static parseBlockTag;
|
|
83
|
+
/**
|
|
84
|
+
* Creates a block tag token with standard MJBlockTagContent.
|
|
85
|
+
*/
|
|
86
|
+
private static makeBlockToken;
|
|
87
|
+
}
|
|
88
|
+
//# sourceMappingURL=mj-lexer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mj-lexer.d.ts","sourceRoot":"","sources":["../src/mj-lexer.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,EACH,OAAO,EAEP,QAAQ,EAQR,aAAa,EAChB,MAAM,mBAAmB,CAAC;AAE3B;;GAEG;AACH,qBAAa,OAAO;IAChB;;;OAGG;WACW,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,EAAE;IA+D9C;;OAEG;WACW,KAAK,CAAC,GAAG,EAAE,MAAM,GAAG,aAAa;IAmB/C;;;OAGG;IACH,OAAO,CAAC,MAAM,CAAC,mBAAmB;IAelC;;OAEG;IACH,OAAO,CAAC,MAAM,CAAC,YAAY;IAoB3B;;;OAGG;IACH,OAAO,CAAC,MAAM,CAAC,oBAAoB;IAYnC;;OAEG;IACH,OAAO,CAAC,MAAM,CAAC,iBAAiB;IAkBhC;;;OAGG;IACH,MAAM,CAAC,gBAAgB,CAAC,OAAO,EAAE,MAAM,GAAG;QAAE,QAAQ,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,QAAQ,EAAE,CAAA;KAAE;IAcnF;;OAEG;IACH,OAAO,CAAC,MAAM,CAAC,UAAU;IAgCzB;;OAEG;IACH,OAAO,CAAC,MAAM,CAAC,iBAAiB;IAchC;;OAEG;IACH,OAAO,CAAC,MAAM,CAAC,eAAe;IAsB9B;;OAEG;IACH,OAAO,CAAC,MAAM,CAAC,mBAAmB;IA+ClC;;OAEG;IACH,OAAO,CAAC,MAAM,CAAC,sBAAsB;IA6BrC;;OAEG;IACH,OAAO,CAAC,MAAM,CAAC,oBAAoB;IAqCnC;;OAEG;IACH,OAAO,CAAC,MAAM,CAAC,aAAa;IA8D5B;;OAEG;IACH,OAAO,CAAC,MAAM,CAAC,cAAc;CAahC"}
|