@renovatebot/good-enough-parser 1.1.24 → 1.2.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/README.md +6 -6
- package/dist/cjs/index.d.ts +4 -4
- package/dist/cjs/index.js +7 -7
- package/dist/cjs/lang/groovy.d.ts +6 -6
- package/dist/cjs/lang/groovy.js +83 -83
- package/dist/cjs/lang/index.d.ts +20 -20
- package/dist/cjs/lang/index.js +56 -56
- package/dist/cjs/lang/python.d.ts +6 -6
- package/dist/cjs/lang/python.js +73 -73
- package/dist/cjs/lang/scala.d.ts +6 -6
- package/dist/cjs/lang/scala.js +71 -71
- package/dist/cjs/lang/starlark.d.ts +6 -6
- package/dist/cjs/lang/starlark.js +58 -58
- package/dist/cjs/lang/types.d.ts +6 -6
- package/dist/cjs/lang/types.js +2 -2
- package/dist/cjs/lexer/bracket.d.ts +6 -6
- package/dist/cjs/lexer/bracket.js +57 -57
- package/dist/cjs/lexer/comment.d.ts +3 -3
- package/dist/cjs/lexer/comment.js +44 -44
- package/dist/cjs/lexer/index.d.ts +5 -5
- package/dist/cjs/lexer/index.js +155 -155
- package/dist/cjs/lexer/number.d.ts +2 -2
- package/dist/cjs/lexer/number.js +18 -18
- package/dist/cjs/lexer/operator.d.ts +2 -2
- package/dist/cjs/lexer/operator.js +24 -24
- package/dist/cjs/lexer/rules.d.ts +4 -4
- package/dist/cjs/lexer/rules.js +74 -74
- package/dist/cjs/lexer/string.d.ts +2 -2
- package/dist/cjs/lexer/string.js +181 -181
- package/dist/cjs/lexer/symbol.d.ts +2 -2
- package/dist/cjs/lexer/symbol.js +18 -18
- package/dist/cjs/lexer/token.d.ts +3 -3
- package/dist/cjs/lexer/token.js +64 -64
- package/dist/cjs/lexer/types.d.ts +142 -142
- package/dist/cjs/lexer/types.js +2 -2
- package/dist/cjs/parser/cursor.d.ts +2 -2
- package/dist/cjs/parser/cursor.js +13 -13
- package/dist/cjs/parser/index.d.ts +3 -3
- package/dist/cjs/parser/index.js +19 -19
- package/dist/cjs/parser/tree.d.ts +4 -4
- package/dist/cjs/parser/tree.js +246 -246
- package/dist/cjs/parser/types.d.ts +33 -33
- package/dist/cjs/parser/types.js +2 -2
- package/dist/cjs/query/builder.d.ts +144 -144
- package/dist/cjs/query/builder.js +332 -332
- package/dist/cjs/query/handler.d.ts +2 -2
- package/dist/cjs/query/handler.js +10 -10
- package/dist/cjs/query/index.d.ts +2 -2
- package/dist/cjs/query/index.js +32 -32
- package/dist/cjs/query/matchers/abstract-matcher.d.ts +9 -9
- package/dist/cjs/query/matchers/abstract-matcher.js +36 -36
- package/dist/cjs/query/matchers/alt-matcher.d.ts +10 -10
- package/dist/cjs/query/matchers/alt-matcher.js +33 -33
- package/dist/cjs/query/matchers/anchor-matcher.d.ts +17 -17
- package/dist/cjs/query/matchers/anchor-matcher.js +50 -50
- package/dist/cjs/query/matchers/comment-matcher.d.ts +10 -10
- package/dist/cjs/query/matchers/comment-matcher.js +39 -39
- package/dist/cjs/query/matchers/index.d.ts +6 -6
- package/dist/cjs/query/matchers/index.js +22 -22
- package/dist/cjs/query/matchers/many-matcher.d.ts +13 -13
- package/dist/cjs/query/matchers/many-matcher.js +61 -61
- package/dist/cjs/query/matchers/num-matcher.d.ts +8 -8
- package/dist/cjs/query/matchers/num-matcher.js +34 -34
- package/dist/cjs/query/matchers/op-matcher.d.ts +8 -8
- package/dist/cjs/query/matchers/op-matcher.js +34 -34
- package/dist/cjs/query/matchers/seq-matcher.d.ts +14 -14
- package/dist/cjs/query/matchers/seq-matcher.js +76 -76
- package/dist/cjs/query/matchers/str-matcher.d.ts +38 -38
- package/dist/cjs/query/matchers/str-matcher.js +108 -108
- package/dist/cjs/query/matchers/sym-matcher.d.ts +8 -8
- package/dist/cjs/query/matchers/sym-matcher.js +34 -34
- package/dist/cjs/query/matchers/tree-matcher.d.ts +23 -23
- package/dist/cjs/query/matchers/tree-matcher.js +121 -121
- package/dist/cjs/query/options.d.ts +10 -10
- package/dist/cjs/query/options.js +149 -149
- package/dist/cjs/query/regex.d.ts +1 -1
- package/dist/cjs/query/regex.js +13 -13
- package/dist/cjs/query/types.d.ts +100 -100
- package/dist/cjs/query/types.js +2 -2
- package/dist/cjs/util/clone.d.ts +1 -1
- package/dist/cjs/util/clone.js +5 -5
- package/dist/cjs/util/regex.d.ts +1 -1
- package/dist/cjs/util/regex.js +7 -7
- package/dist/esm/index.d.ts +4 -4
- package/dist/esm/index.js +8 -8
- package/dist/esm/lang/groovy.d.ts +6 -6
- package/dist/esm/lang/groovy.js +80 -80
- package/dist/esm/lang/index.d.ts +20 -20
- package/dist/esm/lang/index.js +37 -37
- package/dist/esm/lang/python.d.ts +6 -6
- package/dist/esm/lang/python.js +70 -70
- package/dist/esm/lang/scala.d.ts +6 -6
- package/dist/esm/lang/scala.js +68 -68
- package/dist/esm/lang/starlark.d.ts +6 -6
- package/dist/esm/lang/starlark.js +55 -55
- package/dist/esm/lang/types.d.ts +6 -6
- package/dist/esm/lang/types.js +1 -1
- package/dist/esm/lexer/bracket.d.ts +6 -6
- package/dist/esm/lexer/bracket.js +49 -49
- package/dist/esm/lexer/comment.d.ts +3 -3
- package/dist/esm/lexer/comment.js +39 -39
- package/dist/esm/lexer/index.d.ts +5 -5
- package/dist/esm/lexer/index.js +136 -136
- package/dist/esm/lexer/number.d.ts +2 -2
- package/dist/esm/lexer/number.js +14 -14
- package/dist/esm/lexer/operator.d.ts +2 -2
- package/dist/esm/lexer/operator.js +20 -20
- package/dist/esm/lexer/rules.d.ts +4 -4
- package/dist/esm/lexer/rules.js +69 -69
- package/dist/esm/lexer/string.d.ts +2 -2
- package/dist/esm/lexer/string.js +177 -177
- package/dist/esm/lexer/symbol.d.ts +2 -2
- package/dist/esm/lexer/symbol.js +14 -14
- package/dist/esm/lexer/token.d.ts +3 -3
- package/dist/esm/lexer/token.js +60 -60
- package/dist/esm/lexer/types.d.ts +142 -142
- package/dist/esm/lexer/types.js +1 -1
- package/dist/esm/parser/cursor.d.ts +2 -2
- package/dist/esm/parser/cursor.js +9 -9
- package/dist/esm/parser/index.d.ts +3 -3
- package/dist/esm/parser/index.js +3 -3
- package/dist/esm/parser/tree.d.ts +4 -4
- package/dist/esm/parser/tree.js +241 -241
- package/dist/esm/parser/types.d.ts +33 -33
- package/dist/esm/parser/types.js +1 -1
- package/dist/esm/query/builder.d.ts +144 -144
- package/dist/esm/query/builder.js +304 -304
- package/dist/esm/query/handler.d.ts +2 -2
- package/dist/esm/query/handler.js +6 -6
- package/dist/esm/query/index.d.ts +2 -2
- package/dist/esm/query/index.js +2 -2
- package/dist/esm/query/matchers/abstract-matcher.d.ts +9 -9
- package/dist/esm/query/matchers/abstract-matcher.js +32 -32
- package/dist/esm/query/matchers/alt-matcher.d.ts +10 -10
- package/dist/esm/query/matchers/alt-matcher.js +29 -29
- package/dist/esm/query/matchers/anchor-matcher.d.ts +17 -17
- package/dist/esm/query/matchers/anchor-matcher.js +44 -44
- package/dist/esm/query/matchers/comment-matcher.d.ts +10 -10
- package/dist/esm/query/matchers/comment-matcher.js +35 -35
- package/dist/esm/query/matchers/index.d.ts +6 -6
- package/dist/esm/query/matchers/index.js +6 -6
- package/dist/esm/query/matchers/many-matcher.d.ts +13 -13
- package/dist/esm/query/matchers/many-matcher.js +57 -57
- package/dist/esm/query/matchers/num-matcher.d.ts +8 -8
- package/dist/esm/query/matchers/num-matcher.js +30 -30
- package/dist/esm/query/matchers/op-matcher.d.ts +8 -8
- package/dist/esm/query/matchers/op-matcher.js +30 -30
- package/dist/esm/query/matchers/seq-matcher.d.ts +14 -14
- package/dist/esm/query/matchers/seq-matcher.js +72 -72
- package/dist/esm/query/matchers/str-matcher.d.ts +38 -38
- package/dist/esm/query/matchers/str-matcher.js +102 -102
- package/dist/esm/query/matchers/sym-matcher.d.ts +8 -8
- package/dist/esm/query/matchers/sym-matcher.js +30 -30
- package/dist/esm/query/matchers/tree-matcher.d.ts +23 -23
- package/dist/esm/query/matchers/tree-matcher.js +117 -117
- package/dist/esm/query/options.d.ts +10 -10
- package/dist/esm/query/options.js +139 -139
- package/dist/esm/query/regex.d.ts +1 -1
- package/dist/esm/query/regex.js +9 -9
- package/dist/esm/query/types.d.ts +100 -100
- package/dist/esm/query/types.js +1 -1
- package/dist/esm/util/clone.d.ts +1 -1
- package/dist/esm/util/clone.js +1 -1
- package/dist/esm/util/regex.d.ts +1 -1
- package/dist/esm/util/regex.js +3 -3
- package/package.json +3 -3
package/dist/esm/lang/groovy.js
CHANGED
|
@@ -1,81 +1,81 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @see https://docs.groovy-lang.org/latest/html/documentation/#groovy-operators
|
|
3
|
-
*/
|
|
4
|
-
const operators =
|
|
5
|
-
/* prettier-ignore */ [
|
|
6
|
-
'+', '-', '*', '/', '%', '**',
|
|
7
|
-
'++', '--',
|
|
8
|
-
'+=', '-=', '*=', '/=', '%=', '**=',
|
|
9
|
-
'==', '!=', '<', '<=', '>', '>=', '===', '!==', '<=>',
|
|
10
|
-
'&&', '||', '!',
|
|
11
|
-
'&', '|', '^', '~',
|
|
12
|
-
'<<', '>>', '>>>',
|
|
13
|
-
'?', '?:',
|
|
14
|
-
'=', '?=',
|
|
15
|
-
'.', '?.', '.@', '.&', '::',
|
|
16
|
-
'=~', '==~',
|
|
17
|
-
'*.', ':',
|
|
18
|
-
'..', '..<',
|
|
19
|
-
'<>',
|
|
20
|
-
'<<=', '>>=', '>>>=', '&=', '^=', '|=', '?=',
|
|
21
|
-
'->',
|
|
22
|
-
',', ';',
|
|
23
|
-
];
|
|
24
|
-
/**
|
|
25
|
-
* Borrowed from Python implementation:
|
|
26
|
-
*
|
|
27
|
-
* @see https://docs.python.org/3/reference/lexical_analysis.html#numeric-literals
|
|
28
|
-
*/
|
|
29
|
-
const bindigit = '[01]';
|
|
30
|
-
const octdigit = '[0-7]';
|
|
31
|
-
const digit = '[0-9]';
|
|
32
|
-
const nonzerodigit = '[1-9]';
|
|
33
|
-
const hexdigit = `(?:${digit}|[a-fA-F])`;
|
|
34
|
-
const bininteger = `(?:0[bB](?:_?${bindigit})+)`;
|
|
35
|
-
const octinteger = `(?:0[oO](?:_?${octdigit})+)`;
|
|
36
|
-
const hexinteger = `(?:0[xX](?:_?${hexdigit})+)`;
|
|
37
|
-
const decinteger = `(?:${nonzerodigit}(?:_?${digit})*|0+(?:_?0)*)`;
|
|
38
|
-
const integer = `(?:${decinteger}|${bininteger}|${octinteger}|${hexinteger})`;
|
|
39
|
-
const digitpart = `(?:${digit}(?:_?${digit})*)`;
|
|
40
|
-
const fraction = `(?:\\.${digitpart})`;
|
|
41
|
-
const exponent = `(?:[eE][-+]?${digitpart})`;
|
|
42
|
-
const pointfloat = `(?:${digitpart}?${fraction}|${digitpart}\\.)`;
|
|
43
|
-
const exponentfloat = `(?:(?:${digitpart}|${pointfloat})${exponent})`;
|
|
44
|
-
const floatnumber = `(?:${pointfloat}|${exponentfloat})`;
|
|
45
|
-
const numbers = new RegExp(`(?:${integer}|${floatnumber})`);
|
|
46
|
-
const templates = [
|
|
47
|
-
{
|
|
48
|
-
type: 'var',
|
|
49
|
-
startsWith: '$',
|
|
50
|
-
symbols: /[a-zA-Z_][a-zA-Z0-9_]*/,
|
|
51
|
-
operators: ['.'],
|
|
52
|
-
},
|
|
53
|
-
{ type: 'expr', startsWith: '${', endsWith: '}' },
|
|
54
|
-
];
|
|
55
|
-
export const lexer = {
|
|
56
|
-
joinLines: '\\',
|
|
57
|
-
comments: [
|
|
58
|
-
{ type: 'line-comment', startsWith: '#!' },
|
|
59
|
-
{ type: 'line-comment', startsWith: '//' },
|
|
60
|
-
{ type: 'multiline-comment', startsWith: '/*', endsWith: '*/' },
|
|
61
|
-
],
|
|
62
|
-
symbols: /[a-zA-Z$_][a-zA-Z0-9$_]*/,
|
|
63
|
-
numbers,
|
|
64
|
-
operators,
|
|
65
|
-
brackets: [
|
|
66
|
-
{ startsWith: '{', endsWith: '}' },
|
|
67
|
-
{ startsWith: '[', endsWith: ']' },
|
|
68
|
-
{ startsWith: '(', endsWith: ')' },
|
|
69
|
-
],
|
|
70
|
-
strings: [
|
|
71
|
-
{ startsWith: "'", escapeChar: '\\' },
|
|
72
|
-
{ startsWith: "'''", escapeChar: '\\' },
|
|
73
|
-
{ startsWith: '"', templates, escapeChar: '\\' },
|
|
74
|
-
{ startsWith: '"""', templates, escapeChar: '\\' },
|
|
75
|
-
],
|
|
76
|
-
};
|
|
77
|
-
export const parser = {
|
|
78
|
-
useIndentBlocks: false,
|
|
79
|
-
};
|
|
80
|
-
export const lang = { lexer, parser };
|
|
1
|
+
/**
|
|
2
|
+
* @see https://docs.groovy-lang.org/latest/html/documentation/#groovy-operators
|
|
3
|
+
*/
|
|
4
|
+
const operators =
|
|
5
|
+
/* prettier-ignore */ [
|
|
6
|
+
'+', '-', '*', '/', '%', '**',
|
|
7
|
+
'++', '--',
|
|
8
|
+
'+=', '-=', '*=', '/=', '%=', '**=',
|
|
9
|
+
'==', '!=', '<', '<=', '>', '>=', '===', '!==', '<=>',
|
|
10
|
+
'&&', '||', '!',
|
|
11
|
+
'&', '|', '^', '~',
|
|
12
|
+
'<<', '>>', '>>>',
|
|
13
|
+
'?', '?:',
|
|
14
|
+
'=', '?=',
|
|
15
|
+
'.', '?.', '.@', '.&', '::',
|
|
16
|
+
'=~', '==~',
|
|
17
|
+
'*.', ':',
|
|
18
|
+
'..', '..<',
|
|
19
|
+
'<>',
|
|
20
|
+
'<<=', '>>=', '>>>=', '&=', '^=', '|=', '?=',
|
|
21
|
+
'->',
|
|
22
|
+
',', ';',
|
|
23
|
+
];
|
|
24
|
+
/**
|
|
25
|
+
* Borrowed from Python implementation:
|
|
26
|
+
*
|
|
27
|
+
* @see https://docs.python.org/3/reference/lexical_analysis.html#numeric-literals
|
|
28
|
+
*/
|
|
29
|
+
const bindigit = '[01]';
|
|
30
|
+
const octdigit = '[0-7]';
|
|
31
|
+
const digit = '[0-9]';
|
|
32
|
+
const nonzerodigit = '[1-9]';
|
|
33
|
+
const hexdigit = `(?:${digit}|[a-fA-F])`;
|
|
34
|
+
const bininteger = `(?:0[bB](?:_?${bindigit})+)`;
|
|
35
|
+
const octinteger = `(?:0[oO](?:_?${octdigit})+)`;
|
|
36
|
+
const hexinteger = `(?:0[xX](?:_?${hexdigit})+)`;
|
|
37
|
+
const decinteger = `(?:${nonzerodigit}(?:_?${digit})*|0+(?:_?0)*)`;
|
|
38
|
+
const integer = `(?:${decinteger}|${bininteger}|${octinteger}|${hexinteger})`;
|
|
39
|
+
const digitpart = `(?:${digit}(?:_?${digit})*)`;
|
|
40
|
+
const fraction = `(?:\\.${digitpart})`;
|
|
41
|
+
const exponent = `(?:[eE][-+]?${digitpart})`;
|
|
42
|
+
const pointfloat = `(?:${digitpart}?${fraction}|${digitpart}\\.)`;
|
|
43
|
+
const exponentfloat = `(?:(?:${digitpart}|${pointfloat})${exponent})`;
|
|
44
|
+
const floatnumber = `(?:${pointfloat}|${exponentfloat})`;
|
|
45
|
+
const numbers = new RegExp(`(?:${integer}|${floatnumber})`);
|
|
46
|
+
const templates = [
|
|
47
|
+
{
|
|
48
|
+
type: 'var',
|
|
49
|
+
startsWith: '$',
|
|
50
|
+
symbols: /[a-zA-Z_][a-zA-Z0-9_]*/,
|
|
51
|
+
operators: ['.'],
|
|
52
|
+
},
|
|
53
|
+
{ type: 'expr', startsWith: '${', endsWith: '}' },
|
|
54
|
+
];
|
|
55
|
+
export const lexer = {
|
|
56
|
+
joinLines: '\\',
|
|
57
|
+
comments: [
|
|
58
|
+
{ type: 'line-comment', startsWith: '#!' },
|
|
59
|
+
{ type: 'line-comment', startsWith: '//' },
|
|
60
|
+
{ type: 'multiline-comment', startsWith: '/*', endsWith: '*/' },
|
|
61
|
+
],
|
|
62
|
+
symbols: /[a-zA-Z$_][a-zA-Z0-9$_]*/,
|
|
63
|
+
numbers,
|
|
64
|
+
operators,
|
|
65
|
+
brackets: [
|
|
66
|
+
{ startsWith: '{', endsWith: '}' },
|
|
67
|
+
{ startsWith: '[', endsWith: ']' },
|
|
68
|
+
{ startsWith: '(', endsWith: ')' },
|
|
69
|
+
],
|
|
70
|
+
strings: [
|
|
71
|
+
{ startsWith: "'", escapeChar: '\\' },
|
|
72
|
+
{ startsWith: "'''", escapeChar: '\\' },
|
|
73
|
+
{ startsWith: '"', templates, escapeChar: '\\' },
|
|
74
|
+
{ startsWith: '"""', templates, escapeChar: '\\' },
|
|
75
|
+
],
|
|
76
|
+
};
|
|
77
|
+
export const parser = {
|
|
78
|
+
useIndentBlocks: false,
|
|
79
|
+
};
|
|
80
|
+
export const lang = { lexer, parser };
|
|
81
81
|
//# sourceMappingURL=groovy.js.map
|
package/dist/esm/lang/index.d.ts
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
import type { Cursor, Node } from '../parser/types';
|
|
2
|
-
import type { QueryBuilder } from '../query/types';
|
|
3
|
-
import type { LanguageConfig } from './types';
|
|
4
|
-
export * from './types';
|
|
5
|
-
export declare class Language {
|
|
6
|
-
readonly config: LanguageConfig;
|
|
7
|
-
private lexer;
|
|
8
|
-
constructor(config: LanguageConfig);
|
|
9
|
-
parse(input: string): Cursor;
|
|
10
|
-
query<Ctx, T extends Node>(input: string | Cursor, q: QueryBuilder<Ctx, T>, context: Ctx): Ctx | null;
|
|
11
|
-
}
|
|
12
|
-
declare const languagePresets: {
|
|
13
|
-
groovy: LanguageConfig;
|
|
14
|
-
python: LanguageConfig;
|
|
15
|
-
scala: LanguageConfig;
|
|
16
|
-
starlark: LanguageConfig;
|
|
17
|
-
};
|
|
18
|
-
type LanguagePreset = keyof typeof languagePresets;
|
|
19
|
-
export declare function createLang(key: LanguagePreset): Language;
|
|
20
|
-
export declare function createLang(config: LanguageConfig): Language;
|
|
1
|
+
import type { Cursor, Node } from '../parser/types';
|
|
2
|
+
import type { QueryBuilder } from '../query/types';
|
|
3
|
+
import type { LanguageConfig } from './types';
|
|
4
|
+
export * from './types';
|
|
5
|
+
export declare class Language {
|
|
6
|
+
readonly config: LanguageConfig;
|
|
7
|
+
private lexer;
|
|
8
|
+
constructor(config: LanguageConfig);
|
|
9
|
+
parse(input: string): Cursor;
|
|
10
|
+
query<Ctx, T extends Node>(input: string | Cursor, q: QueryBuilder<Ctx, T>, context: Ctx): Ctx | null;
|
|
11
|
+
}
|
|
12
|
+
declare const languagePresets: {
|
|
13
|
+
groovy: LanguageConfig;
|
|
14
|
+
python: LanguageConfig;
|
|
15
|
+
scala: LanguageConfig;
|
|
16
|
+
starlark: LanguageConfig;
|
|
17
|
+
};
|
|
18
|
+
type LanguagePreset = keyof typeof languagePresets;
|
|
19
|
+
export declare function createLang(key: LanguagePreset): Language;
|
|
20
|
+
export declare function createLang(config: LanguageConfig): Language;
|
|
21
21
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/esm/lang/index.js
CHANGED
|
@@ -1,38 +1,38 @@
|
|
|
1
|
-
import { createLexer } from '../lexer';
|
|
2
|
-
import { createCursor, createTree } from '../parser';
|
|
3
|
-
import { buildRoot } from '../query';
|
|
4
|
-
import { clone } from '../util/clone';
|
|
5
|
-
import { lang as groovy } from './groovy';
|
|
6
|
-
import { lang as python } from './python';
|
|
7
|
-
import { lang as scala } from './scala';
|
|
8
|
-
import { lang as starlark } from './starlark';
|
|
9
|
-
export * from './types';
|
|
10
|
-
export class Language {
|
|
11
|
-
constructor(config) {
|
|
12
|
-
this.config = config;
|
|
13
|
-
this.lexer = createLexer(config.lexer);
|
|
14
|
-
}
|
|
15
|
-
parse(input) {
|
|
16
|
-
this.lexer.reset(input);
|
|
17
|
-
const root = createTree(this.lexer, this.config.parser);
|
|
18
|
-
return createCursor(root);
|
|
19
|
-
}
|
|
20
|
-
query(input, q, context) {
|
|
21
|
-
const matcher = buildRoot(q);
|
|
22
|
-
const cursor = typeof input === 'string' ? this.parse(input) : input;
|
|
23
|
-
const checkpoint = matcher.match({ cursor, context });
|
|
24
|
-
const result = checkpoint === null || checkpoint === void 0 ? void 0 : checkpoint.context;
|
|
25
|
-
return result ? clone(result) : null;
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
const languagePresets = {
|
|
29
|
-
groovy,
|
|
30
|
-
python,
|
|
31
|
-
scala,
|
|
32
|
-
starlark,
|
|
33
|
-
};
|
|
34
|
-
export function createLang(arg1) {
|
|
35
|
-
const config = typeof arg1 === 'string' ? languagePresets[arg1] : arg1;
|
|
36
|
-
return new Language(config);
|
|
37
|
-
}
|
|
1
|
+
import { createLexer } from '../lexer';
|
|
2
|
+
import { createCursor, createTree } from '../parser';
|
|
3
|
+
import { buildRoot } from '../query';
|
|
4
|
+
import { clone } from '../util/clone';
|
|
5
|
+
import { lang as groovy } from './groovy';
|
|
6
|
+
import { lang as python } from './python';
|
|
7
|
+
import { lang as scala } from './scala';
|
|
8
|
+
import { lang as starlark } from './starlark';
|
|
9
|
+
export * from './types';
|
|
10
|
+
export class Language {
|
|
11
|
+
constructor(config) {
|
|
12
|
+
this.config = config;
|
|
13
|
+
this.lexer = createLexer(config.lexer);
|
|
14
|
+
}
|
|
15
|
+
parse(input) {
|
|
16
|
+
this.lexer.reset(input);
|
|
17
|
+
const root = createTree(this.lexer, this.config.parser);
|
|
18
|
+
return createCursor(root);
|
|
19
|
+
}
|
|
20
|
+
query(input, q, context) {
|
|
21
|
+
const matcher = buildRoot(q);
|
|
22
|
+
const cursor = typeof input === 'string' ? this.parse(input) : input;
|
|
23
|
+
const checkpoint = matcher.match({ cursor, context });
|
|
24
|
+
const result = checkpoint === null || checkpoint === void 0 ? void 0 : checkpoint.context;
|
|
25
|
+
return result ? clone(result) : null;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
const languagePresets = {
|
|
29
|
+
groovy,
|
|
30
|
+
python,
|
|
31
|
+
scala,
|
|
32
|
+
starlark,
|
|
33
|
+
};
|
|
34
|
+
export function createLang(arg1) {
|
|
35
|
+
const config = typeof arg1 === 'string' ? languagePresets[arg1] : arg1;
|
|
36
|
+
return new Language(config);
|
|
37
|
+
}
|
|
38
38
|
//# sourceMappingURL=index.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type { LexerConfig } from '../lexer/types';
|
|
2
|
-
import type { ParserConfig } from '../parser/types';
|
|
3
|
-
import type { LanguageConfig } from './types';
|
|
4
|
-
export declare const lexer: LexerConfig;
|
|
5
|
-
export declare const parser: ParserConfig;
|
|
6
|
-
export declare const lang: LanguageConfig;
|
|
1
|
+
import type { LexerConfig } from '../lexer/types';
|
|
2
|
+
import type { ParserConfig } from '../parser/types';
|
|
3
|
+
import type { LanguageConfig } from './types';
|
|
4
|
+
export declare const lexer: LexerConfig;
|
|
5
|
+
export declare const parser: ParserConfig;
|
|
6
|
+
export declare const lang: LanguageConfig;
|
|
7
7
|
//# sourceMappingURL=python.d.ts.map
|
package/dist/esm/lang/python.js
CHANGED
|
@@ -1,71 +1,71 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @see https://docs.python.org/3/reference/lexical_analysis.html#operators
|
|
3
|
-
*/
|
|
4
|
-
const operators =
|
|
5
|
-
/* prettier-ignore */ [
|
|
6
|
-
// Operators
|
|
7
|
-
'+', '-', '*', '**', '/', '//', '%', '@',
|
|
8
|
-
'<<', '>>', '&', '|', '^', '~', ':=',
|
|
9
|
-
'<', '>', '<=', '>=', '==', '!=',
|
|
10
|
-
// Delimiters
|
|
11
|
-
',', ':', '.', ';', '@', '=', '->',
|
|
12
|
-
'+=', '-=', '*=', '/=', '//=', '%=', '@=',
|
|
13
|
-
'&=', '|=', '^=', '>>=', '<<=', '**=',
|
|
14
|
-
];
|
|
15
|
-
/**
|
|
16
|
-
* @see https://docs.python.org/3/reference/lexical_analysis.html#numeric-literals
|
|
17
|
-
*/
|
|
18
|
-
const bindigit = '[01]';
|
|
19
|
-
const octdigit = '[0-7]';
|
|
20
|
-
const digit = '[0-9]';
|
|
21
|
-
const nonzerodigit = '[1-9]';
|
|
22
|
-
const hexdigit = `(?:${digit}|[a-fA-F])`;
|
|
23
|
-
const bininteger = `(?:0[bB](?:_?${bindigit})+)`;
|
|
24
|
-
const octinteger = `(?:0[oO](?:_?${octdigit})+)`;
|
|
25
|
-
const hexinteger = `(?:0[xX](?:_?${hexdigit})+)`;
|
|
26
|
-
const decinteger = `(?:${nonzerodigit}(?:_?${digit})*|0+(?:_?0)*)`;
|
|
27
|
-
const integer = `(?:${decinteger}|${bininteger}|${octinteger}|${hexinteger})`;
|
|
28
|
-
const digitpart = `(?:${digit}(?:_?${digit})*)`;
|
|
29
|
-
const fraction = `(?:\\.${digitpart})`;
|
|
30
|
-
const exponent = `(?:[eE][-+]?${digitpart})`;
|
|
31
|
-
const pointfloat = `(?:${digitpart}?${fraction}|${digitpart}\\.)`;
|
|
32
|
-
const exponentfloat = `(?:(?:${digitpart}|${pointfloat})${exponent})`;
|
|
33
|
-
const floatnumber = `(?:${pointfloat}|${exponentfloat})`;
|
|
34
|
-
const numbers = new RegExp(`(?:${integer}|${floatnumber})`);
|
|
35
|
-
export const lexer = {
|
|
36
|
-
joinLines: '\\',
|
|
37
|
-
comments: [{ type: 'line-comment', startsWith: '#' }],
|
|
38
|
-
symbols: /[_a-zA-Z][_a-zA-Z0-9]*/,
|
|
39
|
-
numbers,
|
|
40
|
-
operators,
|
|
41
|
-
brackets: [
|
|
42
|
-
{ startsWith: '{', endsWith: '}' },
|
|
43
|
-
{ startsWith: '[', endsWith: ']' },
|
|
44
|
-
{ startsWith: '(', endsWith: ')' },
|
|
45
|
-
],
|
|
46
|
-
strings: [
|
|
47
|
-
{ startsWith: "'", escapeChar: '\\' },
|
|
48
|
-
{ startsWith: '"', escapeChar: '\\' },
|
|
49
|
-
{ startsWith: "'''", escapeChar: '\\' },
|
|
50
|
-
{ startsWith: '"""', escapeChar: '\\' },
|
|
51
|
-
{
|
|
52
|
-
startsWith: "f'",
|
|
53
|
-
endsWith: "'",
|
|
54
|
-
escapeChar: '\\',
|
|
55
|
-
templates: [{ type: 'expr', startsWith: '{', endsWith: '}' }],
|
|
56
|
-
},
|
|
57
|
-
{
|
|
58
|
-
startsWith: 'f"',
|
|
59
|
-
endsWith: '"',
|
|
60
|
-
escapeChar: '\\',
|
|
61
|
-
templates: [{ type: 'expr', startsWith: '{', endsWith: '}' }],
|
|
62
|
-
},
|
|
63
|
-
{ startsWith: "r'", endsWith: "'" },
|
|
64
|
-
{ startsWith: 'r"', endsWith: '"' },
|
|
65
|
-
],
|
|
66
|
-
};
|
|
67
|
-
export const parser = {
|
|
68
|
-
useIndentBlocks: true,
|
|
69
|
-
};
|
|
70
|
-
export const lang = { lexer, parser };
|
|
1
|
+
/**
|
|
2
|
+
* @see https://docs.python.org/3/reference/lexical_analysis.html#operators
|
|
3
|
+
*/
|
|
4
|
+
const operators =
|
|
5
|
+
/* prettier-ignore */ [
|
|
6
|
+
// Operators
|
|
7
|
+
'+', '-', '*', '**', '/', '//', '%', '@',
|
|
8
|
+
'<<', '>>', '&', '|', '^', '~', ':=',
|
|
9
|
+
'<', '>', '<=', '>=', '==', '!=',
|
|
10
|
+
// Delimiters
|
|
11
|
+
',', ':', '.', ';', '@', '=', '->',
|
|
12
|
+
'+=', '-=', '*=', '/=', '//=', '%=', '@=',
|
|
13
|
+
'&=', '|=', '^=', '>>=', '<<=', '**=',
|
|
14
|
+
];
|
|
15
|
+
/**
|
|
16
|
+
* @see https://docs.python.org/3/reference/lexical_analysis.html#numeric-literals
|
|
17
|
+
*/
|
|
18
|
+
const bindigit = '[01]';
|
|
19
|
+
const octdigit = '[0-7]';
|
|
20
|
+
const digit = '[0-9]';
|
|
21
|
+
const nonzerodigit = '[1-9]';
|
|
22
|
+
const hexdigit = `(?:${digit}|[a-fA-F])`;
|
|
23
|
+
const bininteger = `(?:0[bB](?:_?${bindigit})+)`;
|
|
24
|
+
const octinteger = `(?:0[oO](?:_?${octdigit})+)`;
|
|
25
|
+
const hexinteger = `(?:0[xX](?:_?${hexdigit})+)`;
|
|
26
|
+
const decinteger = `(?:${nonzerodigit}(?:_?${digit})*|0+(?:_?0)*)`;
|
|
27
|
+
const integer = `(?:${decinteger}|${bininteger}|${octinteger}|${hexinteger})`;
|
|
28
|
+
const digitpart = `(?:${digit}(?:_?${digit})*)`;
|
|
29
|
+
const fraction = `(?:\\.${digitpart})`;
|
|
30
|
+
const exponent = `(?:[eE][-+]?${digitpart})`;
|
|
31
|
+
const pointfloat = `(?:${digitpart}?${fraction}|${digitpart}\\.)`;
|
|
32
|
+
const exponentfloat = `(?:(?:${digitpart}|${pointfloat})${exponent})`;
|
|
33
|
+
const floatnumber = `(?:${pointfloat}|${exponentfloat})`;
|
|
34
|
+
const numbers = new RegExp(`(?:${integer}|${floatnumber})`);
|
|
35
|
+
export const lexer = {
|
|
36
|
+
joinLines: '\\',
|
|
37
|
+
comments: [{ type: 'line-comment', startsWith: '#' }],
|
|
38
|
+
symbols: /[_a-zA-Z][_a-zA-Z0-9]*/,
|
|
39
|
+
numbers,
|
|
40
|
+
operators,
|
|
41
|
+
brackets: [
|
|
42
|
+
{ startsWith: '{', endsWith: '}' },
|
|
43
|
+
{ startsWith: '[', endsWith: ']' },
|
|
44
|
+
{ startsWith: '(', endsWith: ')' },
|
|
45
|
+
],
|
|
46
|
+
strings: [
|
|
47
|
+
{ startsWith: "'", escapeChar: '\\' },
|
|
48
|
+
{ startsWith: '"', escapeChar: '\\' },
|
|
49
|
+
{ startsWith: "'''", escapeChar: '\\' },
|
|
50
|
+
{ startsWith: '"""', escapeChar: '\\' },
|
|
51
|
+
{
|
|
52
|
+
startsWith: "f'",
|
|
53
|
+
endsWith: "'",
|
|
54
|
+
escapeChar: '\\',
|
|
55
|
+
templates: [{ type: 'expr', startsWith: '{', endsWith: '}' }],
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
startsWith: 'f"',
|
|
59
|
+
endsWith: '"',
|
|
60
|
+
escapeChar: '\\',
|
|
61
|
+
templates: [{ type: 'expr', startsWith: '{', endsWith: '}' }],
|
|
62
|
+
},
|
|
63
|
+
{ startsWith: "r'", endsWith: "'" },
|
|
64
|
+
{ startsWith: 'r"', endsWith: '"' },
|
|
65
|
+
],
|
|
66
|
+
};
|
|
67
|
+
export const parser = {
|
|
68
|
+
useIndentBlocks: true,
|
|
69
|
+
};
|
|
70
|
+
export const lang = { lexer, parser };
|
|
71
71
|
//# sourceMappingURL=python.js.map
|
package/dist/esm/lang/scala.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type { LexerConfig } from '../lexer/types';
|
|
2
|
-
import type { ParserConfig } from '../parser/types';
|
|
3
|
-
import type { LanguageConfig } from './types';
|
|
4
|
-
export declare const lexer: LexerConfig;
|
|
5
|
-
export declare const parser: ParserConfig;
|
|
6
|
-
export declare const lang: LanguageConfig;
|
|
1
|
+
import type { LexerConfig } from '../lexer/types';
|
|
2
|
+
import type { ParserConfig } from '../parser/types';
|
|
3
|
+
import type { LanguageConfig } from './types';
|
|
4
|
+
export declare const lexer: LexerConfig;
|
|
5
|
+
export declare const parser: ParserConfig;
|
|
6
|
+
export declare const lang: LanguageConfig;
|
|
7
7
|
//# sourceMappingURL=scala.d.ts.map
|
package/dist/esm/lang/scala.js
CHANGED
|
@@ -1,69 +1,69 @@
|
|
|
1
|
-
const operators =
|
|
2
|
-
/* prettier-ignore */ [
|
|
3
|
-
'+', '-', '*', '/', '%', '%%', '%%%', '**',
|
|
4
|
-
'++', '--',
|
|
5
|
-
'+=', '++=', '-=', '*=', '/=', '%=', '**=',
|
|
6
|
-
'==', '!=', '<', '<=', '>', '>=', '===', '!==', '<=>',
|
|
7
|
-
'&&', '||', '!',
|
|
8
|
-
'&', '|', '^', '~',
|
|
9
|
-
'<<', '>>', '>>>',
|
|
10
|
-
'?', '?:',
|
|
11
|
-
':=', '=', '?=',
|
|
12
|
-
'.', '?.', '.@', '.&', '::', ':::',
|
|
13
|
-
'=~', '==~',
|
|
14
|
-
'*.', ':',
|
|
15
|
-
'..', '..<',
|
|
16
|
-
'<>',
|
|
17
|
-
'<<=', '>>=', '>>>=', '&=', '^=', '|=', '?=',
|
|
18
|
-
'->',
|
|
19
|
-
',', ';',
|
|
20
|
-
];
|
|
21
|
-
const octdigit = '[0-7]';
|
|
22
|
-
const digit = '[0-9]';
|
|
23
|
-
const nonzerodigit = '[1-9]';
|
|
24
|
-
const hexdigit = `(?:${digit}|[a-fA-F])`;
|
|
25
|
-
const octinteger = `(?:0[oO](?:_?${octdigit})+)`;
|
|
26
|
-
const hexinteger = `(?:0[xX](?:_?${hexdigit})+)`;
|
|
27
|
-
const decinteger = `(?:${nonzerodigit}(?:_?${digit})*|0+(?:_?0)*)`;
|
|
28
|
-
const integer = `(?:${decinteger}|${octinteger}|${hexinteger})`;
|
|
29
|
-
const digitpart = `(?:${digit}(?:_?${digit})*)`;
|
|
30
|
-
const fraction = `(?:\\.${digitpart})`;
|
|
31
|
-
const exponent = `(?:[eE][-+]?${digitpart})`;
|
|
32
|
-
const pointfloat = `(?:${digitpart}?${fraction}|${digitpart}\\.)`;
|
|
33
|
-
const exponentfloat = `(?:(?:${digitpart}|${pointfloat})${exponent})`;
|
|
34
|
-
const floatnumber = `(?:${pointfloat}|${exponentfloat})`;
|
|
35
|
-
const numbers = new RegExp(`(?:${integer}|${floatnumber})`);
|
|
36
|
-
const templates = [
|
|
37
|
-
{
|
|
38
|
-
type: 'var',
|
|
39
|
-
startsWith: '$',
|
|
40
|
-
symbols: /[a-zA-Z_][a-zA-Z0-9_]+/,
|
|
41
|
-
},
|
|
42
|
-
{ type: 'expr', startsWith: '${', endsWith: '}' },
|
|
43
|
-
];
|
|
44
|
-
export const lexer = {
|
|
45
|
-
joinLines: '\\',
|
|
46
|
-
comments: [
|
|
47
|
-
{ type: 'line-comment', startsWith: '//' },
|
|
48
|
-
{ type: 'multiline-comment', startsWith: '/*', endsWith: '*/' },
|
|
49
|
-
],
|
|
50
|
-
symbols: /[_a-zA-Z][_a-zA-Z0-9]*/,
|
|
51
|
-
numbers,
|
|
52
|
-
operators,
|
|
53
|
-
brackets: [
|
|
54
|
-
{ startsWith: '{', endsWith: '}' },
|
|
55
|
-
{ startsWith: '[', endsWith: ']' },
|
|
56
|
-
{ startsWith: '(', endsWith: ')' },
|
|
57
|
-
],
|
|
58
|
-
strings: [
|
|
59
|
-
{ startsWith: '"', escapeChar: '\\' },
|
|
60
|
-
{ startsWith: 'raw"', endsWith: '"' },
|
|
61
|
-
{ startsWith: 's"', templates, endsWith: '"', escapeChar: '\\' },
|
|
62
|
-
{ startsWith: 'f"', templates, endsWith: '"', escapeChar: '\\' },
|
|
63
|
-
],
|
|
64
|
-
};
|
|
65
|
-
export const parser = {
|
|
66
|
-
useIndentBlocks: false,
|
|
67
|
-
};
|
|
68
|
-
export const lang = { lexer, parser };
|
|
1
|
+
const operators =
|
|
2
|
+
/* prettier-ignore */ [
|
|
3
|
+
'+', '-', '*', '/', '%', '%%', '%%%', '**',
|
|
4
|
+
'++', '--',
|
|
5
|
+
'+=', '++=', '-=', '*=', '/=', '%=', '**=',
|
|
6
|
+
'==', '!=', '<', '<=', '>', '>=', '===', '!==', '<=>',
|
|
7
|
+
'&&', '||', '!',
|
|
8
|
+
'&', '|', '^', '~',
|
|
9
|
+
'<<', '>>', '>>>',
|
|
10
|
+
'?', '?:',
|
|
11
|
+
':=', '=', '?=',
|
|
12
|
+
'.', '?.', '.@', '.&', '::', ':::',
|
|
13
|
+
'=~', '==~',
|
|
14
|
+
'*.', ':',
|
|
15
|
+
'..', '..<',
|
|
16
|
+
'<>',
|
|
17
|
+
'<<=', '>>=', '>>>=', '&=', '^=', '|=', '?=',
|
|
18
|
+
'->',
|
|
19
|
+
',', ';',
|
|
20
|
+
];
|
|
21
|
+
const octdigit = '[0-7]';
|
|
22
|
+
const digit = '[0-9]';
|
|
23
|
+
const nonzerodigit = '[1-9]';
|
|
24
|
+
const hexdigit = `(?:${digit}|[a-fA-F])`;
|
|
25
|
+
const octinteger = `(?:0[oO](?:_?${octdigit})+)`;
|
|
26
|
+
const hexinteger = `(?:0[xX](?:_?${hexdigit})+)`;
|
|
27
|
+
const decinteger = `(?:${nonzerodigit}(?:_?${digit})*|0+(?:_?0)*)`;
|
|
28
|
+
const integer = `(?:${decinteger}|${octinteger}|${hexinteger})`;
|
|
29
|
+
const digitpart = `(?:${digit}(?:_?${digit})*)`;
|
|
30
|
+
const fraction = `(?:\\.${digitpart})`;
|
|
31
|
+
const exponent = `(?:[eE][-+]?${digitpart})`;
|
|
32
|
+
const pointfloat = `(?:${digitpart}?${fraction}|${digitpart}\\.)`;
|
|
33
|
+
const exponentfloat = `(?:(?:${digitpart}|${pointfloat})${exponent})`;
|
|
34
|
+
const floatnumber = `(?:${pointfloat}|${exponentfloat})`;
|
|
35
|
+
const numbers = new RegExp(`(?:${integer}|${floatnumber})`);
|
|
36
|
+
const templates = [
|
|
37
|
+
{
|
|
38
|
+
type: 'var',
|
|
39
|
+
startsWith: '$',
|
|
40
|
+
symbols: /[a-zA-Z_][a-zA-Z0-9_]+/,
|
|
41
|
+
},
|
|
42
|
+
{ type: 'expr', startsWith: '${', endsWith: '}' },
|
|
43
|
+
];
|
|
44
|
+
export const lexer = {
|
|
45
|
+
joinLines: '\\',
|
|
46
|
+
comments: [
|
|
47
|
+
{ type: 'line-comment', startsWith: '//' },
|
|
48
|
+
{ type: 'multiline-comment', startsWith: '/*', endsWith: '*/' },
|
|
49
|
+
],
|
|
50
|
+
symbols: /[_a-zA-Z][_a-zA-Z0-9]*/,
|
|
51
|
+
numbers,
|
|
52
|
+
operators,
|
|
53
|
+
brackets: [
|
|
54
|
+
{ startsWith: '{', endsWith: '}' },
|
|
55
|
+
{ startsWith: '[', endsWith: ']' },
|
|
56
|
+
{ startsWith: '(', endsWith: ')' },
|
|
57
|
+
],
|
|
58
|
+
strings: [
|
|
59
|
+
{ startsWith: '"', escapeChar: '\\' },
|
|
60
|
+
{ startsWith: 'raw"', endsWith: '"' },
|
|
61
|
+
{ startsWith: 's"', templates, endsWith: '"', escapeChar: '\\' },
|
|
62
|
+
{ startsWith: 'f"', templates, endsWith: '"', escapeChar: '\\' },
|
|
63
|
+
],
|
|
64
|
+
};
|
|
65
|
+
export const parser = {
|
|
66
|
+
useIndentBlocks: false,
|
|
67
|
+
};
|
|
68
|
+
export const lang = { lexer, parser };
|
|
69
69
|
//# sourceMappingURL=scala.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type { LexerConfig } from '../lexer/types';
|
|
2
|
-
import type { ParserConfig } from '../parser/types';
|
|
3
|
-
import type { LanguageConfig } from './types';
|
|
4
|
-
export declare const lexer: LexerConfig;
|
|
5
|
-
export declare const parser: ParserConfig;
|
|
6
|
-
export declare const lang: LanguageConfig;
|
|
1
|
+
import type { LexerConfig } from '../lexer/types';
|
|
2
|
+
import type { ParserConfig } from '../parser/types';
|
|
3
|
+
import type { LanguageConfig } from './types';
|
|
4
|
+
export declare const lexer: LexerConfig;
|
|
5
|
+
export declare const parser: ParserConfig;
|
|
6
|
+
export declare const lang: LanguageConfig;
|
|
7
7
|
//# sourceMappingURL=starlark.d.ts.map
|