fractalpop 0.1.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/LICENSE +21 -0
- package/README.md +232 -0
- package/dist/core.d.ts +110 -0
- package/dist/core.js +313 -0
- package/dist/full.d.ts +1 -0
- package/dist/full.js +356 -0
- package/dist/gpu.d.ts +59 -0
- package/dist/gpu.js +215 -0
- package/dist/index.d.ts +108 -0
- package/dist/index.js +523 -0
- package/dist/lang/c.d.ts +5 -0
- package/dist/lang/c.js +90 -0
- package/dist/lang/cpp.d.ts +5 -0
- package/dist/lang/cpp.js +138 -0
- package/dist/lang/csharp.d.ts +5 -0
- package/dist/lang/csharp.js +148 -0
- package/dist/lang/css.d.ts +21 -0
- package/dist/lang/css.js +164 -0
- package/dist/lang/diff.d.ts +30 -0
- package/dist/lang/diff.js +18 -0
- package/dist/lang/dockerfile.d.ts +5 -0
- package/dist/lang/dockerfile.js +60 -0
- package/dist/lang/go.d.ts +5 -0
- package/dist/lang/go.js +91 -0
- package/dist/lang/graphql.d.ts +5 -0
- package/dist/lang/graphql.js +66 -0
- package/dist/lang/hcl.d.ts +5 -0
- package/dist/lang/hcl.js +51 -0
- package/dist/lang/html.d.ts +12 -0
- package/dist/lang/html.js +168 -0
- package/dist/lang/java.d.ts +5 -0
- package/dist/lang/java.js +96 -0
- package/dist/lang/javascript.d.ts +5 -0
- package/dist/lang/javascript.js +0 -0
- package/dist/lang/json.d.ts +5 -0
- package/dist/lang/json.js +47 -0
- package/dist/lang/kotlin.d.ts +5 -0
- package/dist/lang/kotlin.js +113 -0
- package/dist/lang/lua.d.ts +5 -0
- package/dist/lang/lua.js +65 -0
- package/dist/lang/markdown.d.ts +12 -0
- package/dist/lang/markdown.js +172 -0
- package/dist/lang/php.d.ts +5 -0
- package/dist/lang/php.js +129 -0
- package/dist/lang/plaintext.d.ts +7 -0
- package/dist/lang/plaintext.js +3 -0
- package/dist/lang/powershell.d.ts +5 -0
- package/dist/lang/powershell.js +74 -0
- package/dist/lang/python.d.ts +5 -0
- package/dist/lang/python.js +75 -0
- package/dist/lang/ruby.d.ts +5 -0
- package/dist/lang/ruby.js +84 -0
- package/dist/lang/rust.d.ts +5 -0
- package/dist/lang/rust.js +95 -0
- package/dist/lang/sass.d.ts +15 -0
- package/dist/lang/sass.js +201 -0
- package/dist/lang/scss.d.ts +14 -0
- package/dist/lang/scss.js +105 -0
- package/dist/lang/shell.d.ts +5 -0
- package/dist/lang/shell.js +64 -0
- package/dist/lang/sql.d.ts +5 -0
- package/dist/lang/sql.js +129 -0
- package/dist/lang/svelte.d.ts +15 -0
- package/dist/lang/svelte.js +0 -0
- package/dist/lang/swift.d.ts +5 -0
- package/dist/lang/swift.js +125 -0
- package/dist/lang/toml.d.ts +5 -0
- package/dist/lang/toml.js +45 -0
- package/dist/lang/typescript.d.ts +5 -0
- package/dist/lang/typescript.js +0 -0
- package/dist/lang/yaml.d.ts +5 -0
- package/dist/lang/yaml.js +64 -0
- package/dist/lang/zig.d.ts +5 -0
- package/dist/lang/zig.js +133 -0
- package/dist/lang.d.ts +30 -0
- package/dist/lang.js +345 -0
- package/package.json +68 -0
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
/** Reusable comment-scanner bases shared by keyword-based language presets. */ /** Build onCommentStart/onCommentEnd for a mix of line + block comment styles.
|
|
2
|
+
* Line comments open as type 1 and close at `\n`; block comments open as type 2
|
|
3
|
+
* and close at the terminator — so a single onCommentEnd serves both. */ function commentRules(style) {
|
|
4
|
+
const line = style.line ?? [];
|
|
5
|
+
const hasSlash = line.includes('//');
|
|
6
|
+
const hasHash = line.includes('#');
|
|
7
|
+
const hasDash = line.includes('--');
|
|
8
|
+
const block = style.block ?? false;
|
|
9
|
+
return {
|
|
10
|
+
onCommentStart (curr, next) {
|
|
11
|
+
if (block && curr === '/' && next === '*') return 2;
|
|
12
|
+
if (hasSlash && curr === '/' && next === '/') return 1;
|
|
13
|
+
if (hasHash && curr === '#') return 1;
|
|
14
|
+
if (hasDash && curr === '-' && next === '-') return 1;
|
|
15
|
+
return 0;
|
|
16
|
+
},
|
|
17
|
+
onCommentEnd (prev, curr) {
|
|
18
|
+
if (curr === '\n') return 1;
|
|
19
|
+
if (block && prev === '*' && curr === '/') return 2;
|
|
20
|
+
return 0;
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
/** Assemble a keyword-based language config over the shared general lexer. */ function keywordLang(spec) {
|
|
25
|
+
const config = {};
|
|
26
|
+
if (spec.keywords) config.keywords = new Set(spec.keywords);
|
|
27
|
+
if (spec.typeKeywords) config.typeKeywords = new Set(spec.typeKeywords);
|
|
28
|
+
if (spec.caseInsensitive) config.caseInsensitive = true;
|
|
29
|
+
if (spec.comments) Object.assign(config, commentRules(spec.comments));
|
|
30
|
+
return config;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const config = keywordLang({
|
|
34
|
+
keywords: [
|
|
35
|
+
"as",
|
|
36
|
+
"break",
|
|
37
|
+
"by",
|
|
38
|
+
"catch",
|
|
39
|
+
"class",
|
|
40
|
+
"companion",
|
|
41
|
+
"const",
|
|
42
|
+
"constructor",
|
|
43
|
+
"continue",
|
|
44
|
+
"data",
|
|
45
|
+
"do",
|
|
46
|
+
"else",
|
|
47
|
+
"enum",
|
|
48
|
+
"false",
|
|
49
|
+
"finally",
|
|
50
|
+
"for",
|
|
51
|
+
"fun",
|
|
52
|
+
"get",
|
|
53
|
+
"if",
|
|
54
|
+
"import",
|
|
55
|
+
"in",
|
|
56
|
+
"infix",
|
|
57
|
+
"init",
|
|
58
|
+
"interface",
|
|
59
|
+
"internal",
|
|
60
|
+
"is",
|
|
61
|
+
"lateinit",
|
|
62
|
+
"noinline",
|
|
63
|
+
"null",
|
|
64
|
+
"object",
|
|
65
|
+
"open",
|
|
66
|
+
"operator",
|
|
67
|
+
"out",
|
|
68
|
+
"override",
|
|
69
|
+
"package",
|
|
70
|
+
"private",
|
|
71
|
+
"protected",
|
|
72
|
+
"public",
|
|
73
|
+
"reified",
|
|
74
|
+
"return",
|
|
75
|
+
"sealed",
|
|
76
|
+
"set",
|
|
77
|
+
"suspend",
|
|
78
|
+
"tailrec",
|
|
79
|
+
"this",
|
|
80
|
+
"throw",
|
|
81
|
+
"true",
|
|
82
|
+
"try",
|
|
83
|
+
"typealias",
|
|
84
|
+
"val",
|
|
85
|
+
"var",
|
|
86
|
+
"vararg",
|
|
87
|
+
"when",
|
|
88
|
+
"where",
|
|
89
|
+
"while"
|
|
90
|
+
],
|
|
91
|
+
typeKeywords: [
|
|
92
|
+
"Any",
|
|
93
|
+
"Boolean",
|
|
94
|
+
"Byte",
|
|
95
|
+
"Char",
|
|
96
|
+
"Double",
|
|
97
|
+
"Float",
|
|
98
|
+
"Int",
|
|
99
|
+
"Long",
|
|
100
|
+
"Nothing",
|
|
101
|
+
"Short",
|
|
102
|
+
"String",
|
|
103
|
+
"Unit"
|
|
104
|
+
],
|
|
105
|
+
comments: {
|
|
106
|
+
"line": [
|
|
107
|
+
"//"
|
|
108
|
+
],
|
|
109
|
+
"block": true
|
|
110
|
+
}
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
export { config };
|
package/dist/lang/lua.js
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/** Reusable comment-scanner bases shared by keyword-based language presets. */ /** Build onCommentStart/onCommentEnd for a mix of line + block comment styles.
|
|
2
|
+
* Line comments open as type 1 and close at `\n`; block comments open as type 2
|
|
3
|
+
* and close at the terminator — so a single onCommentEnd serves both. */ function commentRules(style) {
|
|
4
|
+
const line = style.line ?? [];
|
|
5
|
+
const hasSlash = line.includes('//');
|
|
6
|
+
const hasHash = line.includes('#');
|
|
7
|
+
const hasDash = line.includes('--');
|
|
8
|
+
const block = style.block ?? false;
|
|
9
|
+
return {
|
|
10
|
+
onCommentStart (curr, next) {
|
|
11
|
+
if (block && curr === '/' && next === '*') return 2;
|
|
12
|
+
if (hasSlash && curr === '/' && next === '/') return 1;
|
|
13
|
+
if (hasHash && curr === '#') return 1;
|
|
14
|
+
if (hasDash && curr === '-' && next === '-') return 1;
|
|
15
|
+
return 0;
|
|
16
|
+
},
|
|
17
|
+
onCommentEnd (prev, curr) {
|
|
18
|
+
if (curr === '\n') return 1;
|
|
19
|
+
if (block && prev === '*' && curr === '/') return 2;
|
|
20
|
+
return 0;
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
/** Assemble a keyword-based language config over the shared general lexer. */ function keywordLang(spec) {
|
|
25
|
+
const config = {};
|
|
26
|
+
if (spec.keywords) config.keywords = new Set(spec.keywords);
|
|
27
|
+
if (spec.typeKeywords) config.typeKeywords = new Set(spec.typeKeywords);
|
|
28
|
+
if (spec.caseInsensitive) config.caseInsensitive = true;
|
|
29
|
+
if (spec.comments) Object.assign(config, commentRules(spec.comments));
|
|
30
|
+
return config;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const config = keywordLang({
|
|
34
|
+
keywords: [
|
|
35
|
+
"and",
|
|
36
|
+
"break",
|
|
37
|
+
"do",
|
|
38
|
+
"else",
|
|
39
|
+
"elseif",
|
|
40
|
+
"end",
|
|
41
|
+
"false",
|
|
42
|
+
"for",
|
|
43
|
+
"function",
|
|
44
|
+
"goto",
|
|
45
|
+
"if",
|
|
46
|
+
"in",
|
|
47
|
+
"local",
|
|
48
|
+
"nil",
|
|
49
|
+
"not",
|
|
50
|
+
"or",
|
|
51
|
+
"repeat",
|
|
52
|
+
"return",
|
|
53
|
+
"then",
|
|
54
|
+
"true",
|
|
55
|
+
"until",
|
|
56
|
+
"while"
|
|
57
|
+
],
|
|
58
|
+
comments: {
|
|
59
|
+
"line": [
|
|
60
|
+
"--"
|
|
61
|
+
]
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
export { config };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { ParseOptions } from '../core.js';
|
|
2
|
+
|
|
3
|
+
/** A lexer emits these: `[numericType, value]`. */
|
|
4
|
+
type Token = [number, string];
|
|
5
|
+
|
|
6
|
+
/** Markdown / MDX tokenizer — headings, fences, inline code, emphasis, links, lists.
|
|
7
|
+
* Line-oriented; a fenced ``` block colors its body as string until it closes. */
|
|
8
|
+
|
|
9
|
+
declare const tokenize: (code: string) => Token[];
|
|
10
|
+
declare const config: ParseOptions;
|
|
11
|
+
|
|
12
|
+
export { config, tokenize };
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* fractalpop core — token model, line assembly, and rendering.
|
|
3
|
+
*
|
|
4
|
+
* Design: tokens are numeric `[type, value]` pairs during lexing (fast Set/array
|
|
5
|
+
* work); the string type names are resolved only at render. Output is an HTML
|
|
6
|
+
* string with no DOM required — so SSR and client produce identical markup.
|
|
7
|
+
*/ /** The stable, ordered token-type list. This list is the theming contract:
|
|
8
|
+
* each type maps to one CSS variable `--fp-<type>` and one class `fp__token--<type>`. */ const TokenTypes = [
|
|
9
|
+
'identifier',
|
|
10
|
+
'keyword',
|
|
11
|
+
'string',
|
|
12
|
+
'class',
|
|
13
|
+
'property',
|
|
14
|
+
'entity',
|
|
15
|
+
'jsxliterals',
|
|
16
|
+
'sign',
|
|
17
|
+
'comment',
|
|
18
|
+
'break',
|
|
19
|
+
'space'
|
|
20
|
+
];
|
|
21
|
+
// Numeric indices, used everywhere in the hot path.
|
|
22
|
+
const T_IDENTIFIER = 0;
|
|
23
|
+
const T_KEYWORD = 1;
|
|
24
|
+
const T_STRING = 2;
|
|
25
|
+
const T_CLASS = 3;
|
|
26
|
+
const T_PROPERTY = 4;
|
|
27
|
+
const T_SIGN = 7;
|
|
28
|
+
const T_COMMENT = 8;
|
|
29
|
+
const T_BREAK = 9;
|
|
30
|
+
({
|
|
31
|
+
TokenMap: new Map(TokenTypes.map((type, index)=>[
|
|
32
|
+
type,
|
|
33
|
+
index
|
|
34
|
+
]))
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
/** Tokenize the inline content of a normal text line. */ function inline(tokens, text) {
|
|
38
|
+
let i = 0;
|
|
39
|
+
const n = text.length;
|
|
40
|
+
let buf = '';
|
|
41
|
+
const flush = ()=>{
|
|
42
|
+
if (buf) {
|
|
43
|
+
tokens.push([
|
|
44
|
+
T_IDENTIFIER,
|
|
45
|
+
buf
|
|
46
|
+
]);
|
|
47
|
+
buf = '';
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
while(i < n){
|
|
51
|
+
const c = text[i];
|
|
52
|
+
// inline code
|
|
53
|
+
if (c === '`') {
|
|
54
|
+
flush();
|
|
55
|
+
const end = text.indexOf('`', i + 1);
|
|
56
|
+
const stop = end === -1 ? n : end + 1;
|
|
57
|
+
tokens.push([
|
|
58
|
+
T_STRING,
|
|
59
|
+
text.slice(i, stop)
|
|
60
|
+
]);
|
|
61
|
+
i = stop;
|
|
62
|
+
continue;
|
|
63
|
+
}
|
|
64
|
+
// emphasis markers
|
|
65
|
+
if (c === '*' || c === '_') {
|
|
66
|
+
flush();
|
|
67
|
+
const s = i;
|
|
68
|
+
while(i < n && (text[i] === '*' || text[i] === '_'))i++;
|
|
69
|
+
tokens.push([
|
|
70
|
+
T_SIGN,
|
|
71
|
+
text.slice(s, i)
|
|
72
|
+
]);
|
|
73
|
+
continue;
|
|
74
|
+
}
|
|
75
|
+
// link / image [text](url)
|
|
76
|
+
if (c === '[') {
|
|
77
|
+
const close = text.indexOf(']', i);
|
|
78
|
+
if (close !== -1 && text[close + 1] === '(') {
|
|
79
|
+
const paren = text.indexOf(')', close);
|
|
80
|
+
if (paren !== -1) {
|
|
81
|
+
flush();
|
|
82
|
+
tokens.push([
|
|
83
|
+
T_SIGN,
|
|
84
|
+
'['
|
|
85
|
+
]);
|
|
86
|
+
tokens.push([
|
|
87
|
+
T_PROPERTY,
|
|
88
|
+
text.slice(i + 1, close)
|
|
89
|
+
]);
|
|
90
|
+
tokens.push([
|
|
91
|
+
T_SIGN,
|
|
92
|
+
']('
|
|
93
|
+
]);
|
|
94
|
+
tokens.push([
|
|
95
|
+
T_STRING,
|
|
96
|
+
text.slice(close + 2, paren)
|
|
97
|
+
]);
|
|
98
|
+
tokens.push([
|
|
99
|
+
T_SIGN,
|
|
100
|
+
')'
|
|
101
|
+
]);
|
|
102
|
+
i = paren + 1;
|
|
103
|
+
continue;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
buf += c;
|
|
108
|
+
i++;
|
|
109
|
+
}
|
|
110
|
+
flush();
|
|
111
|
+
}
|
|
112
|
+
const tokenize = (code)=>{
|
|
113
|
+
const tokens = [];
|
|
114
|
+
const lines = code.split('\n');
|
|
115
|
+
let fence = '';
|
|
116
|
+
for(let l = 0; l < lines.length; l++){
|
|
117
|
+
const line = lines[l];
|
|
118
|
+
const trimmed = line.trimStart();
|
|
119
|
+
const fenceMarker = trimmed.match(/^(`{3,}|~{3,})/)?.[1];
|
|
120
|
+
if (fence) {
|
|
121
|
+
if (fenceMarker && fenceMarker[0] === fence[0] && fenceMarker.length >= fence.length) {
|
|
122
|
+
fence = '';
|
|
123
|
+
}
|
|
124
|
+
tokens.push([
|
|
125
|
+
T_STRING,
|
|
126
|
+
line
|
|
127
|
+
]);
|
|
128
|
+
} else if (fenceMarker) {
|
|
129
|
+
fence = fenceMarker;
|
|
130
|
+
tokens.push([
|
|
131
|
+
T_COMMENT,
|
|
132
|
+
line
|
|
133
|
+
]); // fence line (with optional lang label)
|
|
134
|
+
} else if (/^#{1,6}\s/.test(trimmed)) {
|
|
135
|
+
tokens.push([
|
|
136
|
+
T_CLASS,
|
|
137
|
+
line
|
|
138
|
+
]); // heading
|
|
139
|
+
} else if (/^>/.test(trimmed)) {
|
|
140
|
+
tokens.push([
|
|
141
|
+
T_COMMENT,
|
|
142
|
+
line
|
|
143
|
+
]); // blockquote
|
|
144
|
+
} else {
|
|
145
|
+
const indent = line.slice(0, line.length - trimmed.length);
|
|
146
|
+
if (indent) tokens.push([
|
|
147
|
+
T_IDENTIFIER,
|
|
148
|
+
indent
|
|
149
|
+
]);
|
|
150
|
+
const listMarker = trimmed.match(/^([-*+]|\d+\.)\s/)?.[1];
|
|
151
|
+
if (listMarker) {
|
|
152
|
+
tokens.push([
|
|
153
|
+
T_KEYWORD,
|
|
154
|
+
listMarker
|
|
155
|
+
]);
|
|
156
|
+
inline(tokens, trimmed.slice(listMarker.length));
|
|
157
|
+
} else {
|
|
158
|
+
inline(tokens, trimmed);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
if (l < lines.length - 1) tokens.push([
|
|
162
|
+
T_BREAK,
|
|
163
|
+
'\n'
|
|
164
|
+
]);
|
|
165
|
+
}
|
|
166
|
+
return tokens;
|
|
167
|
+
};
|
|
168
|
+
const config = {
|
|
169
|
+
tokenize
|
|
170
|
+
};
|
|
171
|
+
|
|
172
|
+
export { config, tokenize };
|
package/dist/lang/php.js
ADDED
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
/** Reusable comment-scanner bases shared by keyword-based language presets. */ /** Build onCommentStart/onCommentEnd for a mix of line + block comment styles.
|
|
2
|
+
* Line comments open as type 1 and close at `\n`; block comments open as type 2
|
|
3
|
+
* and close at the terminator — so a single onCommentEnd serves both. */ function commentRules(style) {
|
|
4
|
+
const line = style.line ?? [];
|
|
5
|
+
const hasSlash = line.includes('//');
|
|
6
|
+
const hasHash = line.includes('#');
|
|
7
|
+
const hasDash = line.includes('--');
|
|
8
|
+
const block = style.block ?? false;
|
|
9
|
+
return {
|
|
10
|
+
onCommentStart (curr, next) {
|
|
11
|
+
if (block && curr === '/' && next === '*') return 2;
|
|
12
|
+
if (hasSlash && curr === '/' && next === '/') return 1;
|
|
13
|
+
if (hasHash && curr === '#') return 1;
|
|
14
|
+
if (hasDash && curr === '-' && next === '-') return 1;
|
|
15
|
+
return 0;
|
|
16
|
+
},
|
|
17
|
+
onCommentEnd (prev, curr) {
|
|
18
|
+
if (curr === '\n') return 1;
|
|
19
|
+
if (block && prev === '*' && curr === '/') return 2;
|
|
20
|
+
return 0;
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
/** Assemble a keyword-based language config over the shared general lexer. */ function keywordLang(spec) {
|
|
25
|
+
const config = {};
|
|
26
|
+
if (spec.keywords) config.keywords = new Set(spec.keywords);
|
|
27
|
+
if (spec.typeKeywords) config.typeKeywords = new Set(spec.typeKeywords);
|
|
28
|
+
if (spec.caseInsensitive) config.caseInsensitive = true;
|
|
29
|
+
if (spec.comments) Object.assign(config, commentRules(spec.comments));
|
|
30
|
+
return config;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const config = keywordLang({
|
|
34
|
+
keywords: [
|
|
35
|
+
"abstract",
|
|
36
|
+
"and",
|
|
37
|
+
"array",
|
|
38
|
+
"as",
|
|
39
|
+
"break",
|
|
40
|
+
"callable",
|
|
41
|
+
"case",
|
|
42
|
+
"catch",
|
|
43
|
+
"class",
|
|
44
|
+
"clone",
|
|
45
|
+
"const",
|
|
46
|
+
"continue",
|
|
47
|
+
"declare",
|
|
48
|
+
"default",
|
|
49
|
+
"do",
|
|
50
|
+
"echo",
|
|
51
|
+
"else",
|
|
52
|
+
"elseif",
|
|
53
|
+
"empty",
|
|
54
|
+
"enddeclare",
|
|
55
|
+
"endfor",
|
|
56
|
+
"endforeach",
|
|
57
|
+
"endif",
|
|
58
|
+
"endswitch",
|
|
59
|
+
"endwhile",
|
|
60
|
+
"enum",
|
|
61
|
+
"eval",
|
|
62
|
+
"exit",
|
|
63
|
+
"extends",
|
|
64
|
+
"false",
|
|
65
|
+
"final",
|
|
66
|
+
"finally",
|
|
67
|
+
"fn",
|
|
68
|
+
"for",
|
|
69
|
+
"foreach",
|
|
70
|
+
"from",
|
|
71
|
+
"function",
|
|
72
|
+
"global",
|
|
73
|
+
"goto",
|
|
74
|
+
"if",
|
|
75
|
+
"implements",
|
|
76
|
+
"include",
|
|
77
|
+
"include_once",
|
|
78
|
+
"instanceof",
|
|
79
|
+
"insteadof",
|
|
80
|
+
"interface",
|
|
81
|
+
"isset",
|
|
82
|
+
"list",
|
|
83
|
+
"match",
|
|
84
|
+
"namespace",
|
|
85
|
+
"new",
|
|
86
|
+
"null",
|
|
87
|
+
"or",
|
|
88
|
+
"print",
|
|
89
|
+
"private",
|
|
90
|
+
"protected",
|
|
91
|
+
"public",
|
|
92
|
+
"readonly",
|
|
93
|
+
"require",
|
|
94
|
+
"require_once",
|
|
95
|
+
"return",
|
|
96
|
+
"static",
|
|
97
|
+
"switch",
|
|
98
|
+
"throw",
|
|
99
|
+
"trait",
|
|
100
|
+
"true",
|
|
101
|
+
"try",
|
|
102
|
+
"unset",
|
|
103
|
+
"use",
|
|
104
|
+
"var",
|
|
105
|
+
"while",
|
|
106
|
+
"xor",
|
|
107
|
+
"yield"
|
|
108
|
+
],
|
|
109
|
+
typeKeywords: [
|
|
110
|
+
"bool",
|
|
111
|
+
"float",
|
|
112
|
+
"int",
|
|
113
|
+
"iterable",
|
|
114
|
+
"mixed",
|
|
115
|
+
"never",
|
|
116
|
+
"object",
|
|
117
|
+
"string",
|
|
118
|
+
"void"
|
|
119
|
+
],
|
|
120
|
+
comments: {
|
|
121
|
+
"line": [
|
|
122
|
+
"//",
|
|
123
|
+
"#"
|
|
124
|
+
],
|
|
125
|
+
"block": true
|
|
126
|
+
}
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
export { config };
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/** Reusable comment-scanner bases shared by keyword-based language presets. */ /** Build onCommentStart/onCommentEnd for a mix of line + block comment styles.
|
|
2
|
+
* Line comments open as type 1 and close at `\n`; block comments open as type 2
|
|
3
|
+
* and close at the terminator — so a single onCommentEnd serves both. */ function commentRules(style) {
|
|
4
|
+
const line = style.line ?? [];
|
|
5
|
+
const hasSlash = line.includes('//');
|
|
6
|
+
const hasHash = line.includes('#');
|
|
7
|
+
const hasDash = line.includes('--');
|
|
8
|
+
const block = style.block ?? false;
|
|
9
|
+
return {
|
|
10
|
+
onCommentStart (curr, next) {
|
|
11
|
+
if (block && curr === '/' && next === '*') return 2;
|
|
12
|
+
if (hasSlash && curr === '/' && next === '/') return 1;
|
|
13
|
+
if (hasHash && curr === '#') return 1;
|
|
14
|
+
if (hasDash && curr === '-' && next === '-') return 1;
|
|
15
|
+
return 0;
|
|
16
|
+
},
|
|
17
|
+
onCommentEnd (prev, curr) {
|
|
18
|
+
if (curr === '\n') return 1;
|
|
19
|
+
if (block && prev === '*' && curr === '/') return 2;
|
|
20
|
+
return 0;
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
/** Assemble a keyword-based language config over the shared general lexer. */ function keywordLang(spec) {
|
|
25
|
+
const config = {};
|
|
26
|
+
if (spec.keywords) config.keywords = new Set(spec.keywords);
|
|
27
|
+
if (spec.typeKeywords) config.typeKeywords = new Set(spec.typeKeywords);
|
|
28
|
+
config.caseInsensitive = true;
|
|
29
|
+
if (spec.comments) Object.assign(config, commentRules(spec.comments));
|
|
30
|
+
return config;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const config = keywordLang({
|
|
34
|
+
keywords: [
|
|
35
|
+
"begin",
|
|
36
|
+
"break",
|
|
37
|
+
"catch",
|
|
38
|
+
"class",
|
|
39
|
+
"continue",
|
|
40
|
+
"data",
|
|
41
|
+
"define",
|
|
42
|
+
"do",
|
|
43
|
+
"dynamicparam",
|
|
44
|
+
"else",
|
|
45
|
+
"elseif",
|
|
46
|
+
"end",
|
|
47
|
+
"enum",
|
|
48
|
+
"exit",
|
|
49
|
+
"filter",
|
|
50
|
+
"finally",
|
|
51
|
+
"for",
|
|
52
|
+
"foreach",
|
|
53
|
+
"from",
|
|
54
|
+
"function",
|
|
55
|
+
"if",
|
|
56
|
+
"in",
|
|
57
|
+
"param",
|
|
58
|
+
"process",
|
|
59
|
+
"return",
|
|
60
|
+
"switch",
|
|
61
|
+
"throw",
|
|
62
|
+
"trap",
|
|
63
|
+
"try",
|
|
64
|
+
"until",
|
|
65
|
+
"using",
|
|
66
|
+
"while"
|
|
67
|
+
],
|
|
68
|
+
comments: {
|
|
69
|
+
"line": [
|
|
70
|
+
"#"
|
|
71
|
+
]
|
|
72
|
+
}});
|
|
73
|
+
|
|
74
|
+
export { config };
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/** Reusable comment-scanner bases shared by keyword-based language presets. */ /** Build onCommentStart/onCommentEnd for a mix of line + block comment styles.
|
|
2
|
+
* Line comments open as type 1 and close at `\n`; block comments open as type 2
|
|
3
|
+
* and close at the terminator — so a single onCommentEnd serves both. */ function commentRules(style) {
|
|
4
|
+
const line = style.line ?? [];
|
|
5
|
+
const hasSlash = line.includes('//');
|
|
6
|
+
const hasHash = line.includes('#');
|
|
7
|
+
const hasDash = line.includes('--');
|
|
8
|
+
const block = style.block ?? false;
|
|
9
|
+
return {
|
|
10
|
+
onCommentStart (curr, next) {
|
|
11
|
+
if (block && curr === '/' && next === '*') return 2;
|
|
12
|
+
if (hasSlash && curr === '/' && next === '/') return 1;
|
|
13
|
+
if (hasHash && curr === '#') return 1;
|
|
14
|
+
if (hasDash && curr === '-' && next === '-') return 1;
|
|
15
|
+
return 0;
|
|
16
|
+
},
|
|
17
|
+
onCommentEnd (prev, curr) {
|
|
18
|
+
if (curr === '\n') return 1;
|
|
19
|
+
if (block && prev === '*' && curr === '/') return 2;
|
|
20
|
+
return 0;
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
/** Assemble a keyword-based language config over the shared general lexer. */ function keywordLang(spec) {
|
|
25
|
+
const config = {};
|
|
26
|
+
if (spec.keywords) config.keywords = new Set(spec.keywords);
|
|
27
|
+
if (spec.typeKeywords) config.typeKeywords = new Set(spec.typeKeywords);
|
|
28
|
+
if (spec.caseInsensitive) config.caseInsensitive = true;
|
|
29
|
+
if (spec.comments) Object.assign(config, commentRules(spec.comments));
|
|
30
|
+
return config;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const config = keywordLang({
|
|
34
|
+
keywords: [
|
|
35
|
+
"and",
|
|
36
|
+
"as",
|
|
37
|
+
"assert",
|
|
38
|
+
"async",
|
|
39
|
+
"await",
|
|
40
|
+
"break",
|
|
41
|
+
"class",
|
|
42
|
+
"continue",
|
|
43
|
+
"def",
|
|
44
|
+
"del",
|
|
45
|
+
"elif",
|
|
46
|
+
"else",
|
|
47
|
+
"except",
|
|
48
|
+
"finally",
|
|
49
|
+
"for",
|
|
50
|
+
"from",
|
|
51
|
+
"global",
|
|
52
|
+
"if",
|
|
53
|
+
"import",
|
|
54
|
+
"in",
|
|
55
|
+
"is",
|
|
56
|
+
"lambda",
|
|
57
|
+
"nonlocal",
|
|
58
|
+
"not",
|
|
59
|
+
"or",
|
|
60
|
+
"pass",
|
|
61
|
+
"raise",
|
|
62
|
+
"return",
|
|
63
|
+
"try",
|
|
64
|
+
"while",
|
|
65
|
+
"with",
|
|
66
|
+
"yield"
|
|
67
|
+
],
|
|
68
|
+
comments: {
|
|
69
|
+
"line": [
|
|
70
|
+
"#"
|
|
71
|
+
]
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
export { config };
|