@boundaryml/baml-highlightjs 0.1.0 → 0.1.1
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 +1 -1
- package/dist/baml.js +34 -12
- package/package.json +1 -1
- package/src/baml.js +34 -12
package/README.md
CHANGED
|
@@ -45,7 +45,7 @@ The package ships a plain ES module, so it works directly from an ESM CDN — no
|
|
|
45
45
|
For the classic (non-module) highlight.js build, `dist/baml.js` self-registers the language on the global `hljs` — load it after highlight.js:
|
|
46
46
|
|
|
47
47
|
```html
|
|
48
|
-
<script src="https://cdn.jsdelivr.net/npm/
|
|
48
|
+
<script src="https://cdn.jsdelivr.net/npm/@highlightjs/cdn-assets@11/highlight.min.js"></script>
|
|
49
49
|
<script src="https://cdn.jsdelivr.net/npm/@boundaryml/baml-highlightjs/dist/baml.js"></script>
|
|
50
50
|
```
|
|
51
51
|
|
package/dist/baml.js
CHANGED
|
@@ -36,16 +36,20 @@
|
|
|
36
36
|
|
|
37
37
|
/** @type {import('highlight.js').LanguageFn} */
|
|
38
38
|
function baml(hljs) {
|
|
39
|
-
// Identifier as the BAML lexer defines its `Word` token
|
|
40
|
-
//
|
|
41
|
-
// digits and hyphens (`gpt-4o` is one identifier).
|
|
42
|
-
|
|
39
|
+
// Identifier as the BAML lexer defines its `Word` token
|
|
40
|
+
// (baml_compiler_lexer/src/tokens.rs): first char is a letter or underscore,
|
|
41
|
+
// continuation chars add digits and hyphens (`gpt-4o` is one identifier).
|
|
42
|
+
// Names may be joined by `$` into segments (`ExtractResume$render_prompt`),
|
|
43
|
+
// and a leading `$` marks the special $-prefixed form (`$stream`).
|
|
44
|
+
const IDENT = /\$?[A-Za-z_][A-Za-z0-9_-]*(?:\$[A-Za-z_][A-Za-z0-9_-]*)*/;
|
|
43
45
|
|
|
44
46
|
const KEYWORDS = {
|
|
45
|
-
// Keywords are plain words, but identifiers may contain hyphens
|
|
46
|
-
//
|
|
47
|
-
//
|
|
48
|
-
|
|
47
|
+
// Keywords are plain words, but identifiers may contain hyphens and
|
|
48
|
+
// $-joined segments; matching the full lexer Word shape here keeps
|
|
49
|
+
// `catch-all-handler`, `gpt-4o`, `for$each`, or `$stream` from being read
|
|
50
|
+
// as a keyword plus trailing junk (keywords themselves contain no `-`/`$`,
|
|
51
|
+
// so real keywords still match exactly).
|
|
52
|
+
$pattern: /\$?[A-Za-z_][A-Za-z0-9_-]*(?:\$[A-Za-z_][A-Za-z0-9_-]*)*/,
|
|
49
53
|
keyword: [
|
|
50
54
|
// top-level declaration keywords (lexer TokenKind)
|
|
51
55
|
'class',
|
|
@@ -217,8 +221,18 @@
|
|
|
217
221
|
relevance: 0
|
|
218
222
|
};
|
|
219
223
|
|
|
220
|
-
// ${ ... } interpolation inside backtick strings.
|
|
221
|
-
//
|
|
224
|
+
// ${ ... } interpolation inside backtick strings. The interpolated
|
|
225
|
+
// expression may itself contain braces (`${if ok { "x" } else { "y" }}`), so
|
|
226
|
+
// a self-recursive brace-tracking mode keeps the interpolation open until
|
|
227
|
+
// its own balancing `}`. `contains` for both is filled in below (after the
|
|
228
|
+
// modes they reference exist).
|
|
229
|
+
const NESTED_BRACES = {
|
|
230
|
+
begin: /\{/,
|
|
231
|
+
end: /\}/,
|
|
232
|
+
keywords: KEYWORDS,
|
|
233
|
+
contains: []
|
|
234
|
+
};
|
|
235
|
+
|
|
222
236
|
const SUBST = {
|
|
223
237
|
scope: 'subst',
|
|
224
238
|
begin: /\$\{/,
|
|
@@ -326,14 +340,22 @@
|
|
|
326
340
|
relevance: 0
|
|
327
341
|
};
|
|
328
342
|
|
|
329
|
-
|
|
343
|
+
// Shared contents of an interpolated expression. The list includes
|
|
344
|
+
// NESTED_BRACES, and NESTED_BRACES reuses the list, so arbitrarily deep
|
|
345
|
+
// `{ ... }` nesting inside `${ ... }` is tracked and only the balancing `}`
|
|
346
|
+
// closes the interpolation.
|
|
347
|
+
const INTERPOLATION_CONTAINS = [
|
|
330
348
|
hljs.C_LINE_COMMENT_MODE,
|
|
331
349
|
hljs.C_BLOCK_COMMENT_MODE,
|
|
332
350
|
QUOTED_STRING,
|
|
333
351
|
NUMBER,
|
|
334
|
-
ENV_VAR
|
|
352
|
+
ENV_VAR,
|
|
353
|
+
NESTED_BRACES
|
|
335
354
|
];
|
|
336
355
|
|
|
356
|
+
NESTED_BRACES.contains = INTERPOLATION_CONTAINS;
|
|
357
|
+
SUBST.contains = INTERPOLATION_CONTAINS;
|
|
358
|
+
|
|
337
359
|
return {
|
|
338
360
|
name: 'BAML',
|
|
339
361
|
aliases: ['baml'],
|
package/package.json
CHANGED
package/src/baml.js
CHANGED
|
@@ -32,16 +32,20 @@ false for this language.
|
|
|
32
32
|
|
|
33
33
|
/** @type {import('highlight.js').LanguageFn} */
|
|
34
34
|
export default function baml(hljs) {
|
|
35
|
-
// Identifier as the BAML lexer defines its `Word` token
|
|
36
|
-
//
|
|
37
|
-
// digits and hyphens (`gpt-4o` is one identifier).
|
|
38
|
-
|
|
35
|
+
// Identifier as the BAML lexer defines its `Word` token
|
|
36
|
+
// (baml_compiler_lexer/src/tokens.rs): first char is a letter or underscore,
|
|
37
|
+
// continuation chars add digits and hyphens (`gpt-4o` is one identifier).
|
|
38
|
+
// Names may be joined by `$` into segments (`ExtractResume$render_prompt`),
|
|
39
|
+
// and a leading `$` marks the special $-prefixed form (`$stream`).
|
|
40
|
+
const IDENT = /\$?[A-Za-z_][A-Za-z0-9_-]*(?:\$[A-Za-z_][A-Za-z0-9_-]*)*/;
|
|
39
41
|
|
|
40
42
|
const KEYWORDS = {
|
|
41
|
-
// Keywords are plain words, but identifiers may contain hyphens
|
|
42
|
-
//
|
|
43
|
-
//
|
|
44
|
-
|
|
43
|
+
// Keywords are plain words, but identifiers may contain hyphens and
|
|
44
|
+
// $-joined segments; matching the full lexer Word shape here keeps
|
|
45
|
+
// `catch-all-handler`, `gpt-4o`, `for$each`, or `$stream` from being read
|
|
46
|
+
// as a keyword plus trailing junk (keywords themselves contain no `-`/`$`,
|
|
47
|
+
// so real keywords still match exactly).
|
|
48
|
+
$pattern: /\$?[A-Za-z_][A-Za-z0-9_-]*(?:\$[A-Za-z_][A-Za-z0-9_-]*)*/,
|
|
45
49
|
keyword: [
|
|
46
50
|
// top-level declaration keywords (lexer TokenKind)
|
|
47
51
|
'class',
|
|
@@ -213,8 +217,18 @@ export default function baml(hljs) {
|
|
|
213
217
|
relevance: 0
|
|
214
218
|
};
|
|
215
219
|
|
|
216
|
-
// ${ ... } interpolation inside backtick strings.
|
|
217
|
-
//
|
|
220
|
+
// ${ ... } interpolation inside backtick strings. The interpolated
|
|
221
|
+
// expression may itself contain braces (`${if ok { "x" } else { "y" }}`), so
|
|
222
|
+
// a self-recursive brace-tracking mode keeps the interpolation open until
|
|
223
|
+
// its own balancing `}`. `contains` for both is filled in below (after the
|
|
224
|
+
// modes they reference exist).
|
|
225
|
+
const NESTED_BRACES = {
|
|
226
|
+
begin: /\{/,
|
|
227
|
+
end: /\}/,
|
|
228
|
+
keywords: KEYWORDS,
|
|
229
|
+
contains: []
|
|
230
|
+
};
|
|
231
|
+
|
|
218
232
|
const SUBST = {
|
|
219
233
|
scope: 'subst',
|
|
220
234
|
begin: /\$\{/,
|
|
@@ -322,14 +336,22 @@ export default function baml(hljs) {
|
|
|
322
336
|
relevance: 0
|
|
323
337
|
};
|
|
324
338
|
|
|
325
|
-
|
|
339
|
+
// Shared contents of an interpolated expression. The list includes
|
|
340
|
+
// NESTED_BRACES, and NESTED_BRACES reuses the list, so arbitrarily deep
|
|
341
|
+
// `{ ... }` nesting inside `${ ... }` is tracked and only the balancing `}`
|
|
342
|
+
// closes the interpolation.
|
|
343
|
+
const INTERPOLATION_CONTAINS = [
|
|
326
344
|
hljs.C_LINE_COMMENT_MODE,
|
|
327
345
|
hljs.C_BLOCK_COMMENT_MODE,
|
|
328
346
|
QUOTED_STRING,
|
|
329
347
|
NUMBER,
|
|
330
|
-
ENV_VAR
|
|
348
|
+
ENV_VAR,
|
|
349
|
+
NESTED_BRACES
|
|
331
350
|
];
|
|
332
351
|
|
|
352
|
+
NESTED_BRACES.contains = INTERPOLATION_CONTAINS;
|
|
353
|
+
SUBST.contains = INTERPOLATION_CONTAINS;
|
|
354
|
+
|
|
333
355
|
return {
|
|
334
356
|
name: 'BAML',
|
|
335
357
|
aliases: ['baml'],
|