diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index bb5f041fbb..9b85c2a8fd 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -100,3 +100,11 @@ repos: files: ^baml_language/ priority: 4 stages: [manual] + + - id: textmate-grammar + name: textmate grammar (yaml → json) + entry: bash -c 'cd typescript2 && pnpm exec tsx textmate-grammar/build-grammar.ts && git diff --exit-code app-vscode-ext/syntaxes/baml.tmLanguage.json app-vscode-ext/syntaxes/jinja.tmLanguage.json app-promptfiddle/syntaxes/baml.tmLanguage.json app-promptfiddle/syntaxes/jinja.tmLanguage.json' + language: system + pass_filenames: false + files: ^typescript2/textmate-grammar/(baml\.tmLanguage\.yaml|jinja\.tmLanguage\.json)$ + priority: 1 diff --git a/typescript2/app-promptfiddle/src/playground/MonacoEditor.tsx b/typescript2/app-promptfiddle/src/playground/MonacoEditor.tsx index c1f4cd95f1..ad5ad5e1fe 100644 --- a/typescript2/app-promptfiddle/src/playground/MonacoEditor.tsx +++ b/typescript2/app-promptfiddle/src/playground/MonacoEditor.tsx @@ -225,7 +225,7 @@ export const MonacoEditor: FC = ({ files, onFilesChange, heig import('@codingame/monaco-vscode-secret-storage-service-override'), import('@codingame/monaco-vscode-storage-service-override'), import('vscode'), - import('./baml.tmLanguage.json'), + import('../../syntaxes/baml.tmLanguage.json'), ]); if (disposed || !containerRef.current) return; @@ -491,7 +491,7 @@ export const MonacoEditor: FC = ({ files, onFilesChange, heig async renderInput(input: any): Promise<{ dispose: () => void }> { const el = this._el; - if (!el) return { dispose() {} }; + if (!el) return { dispose() { } }; el.innerHTML = ''; this._img = null; @@ -500,7 +500,7 @@ export const MonacoEditor: FC = ({ files, onFilesChange, heig if (!uri?.path) { el.textContent = 'No image to display'; Object.assign(el.style, { color: '#ccc', padding: '2em' }); - return { dispose() {} }; + return { dispose() { } }; } const filename = String(uri.path).startsWith(WORKSPACE_PREFIX) @@ -520,7 +520,7 @@ export const MonacoEditor: FC = ({ files, onFilesChange, heig console.error('[ImagePreview] readFile failed:', err); el.textContent = `Failed to load image: ${err}`; Object.assign(el.style, { color: '#ccc', padding: '2em' }); - return { dispose() {} }; + return { dispose() { } }; } } @@ -628,7 +628,7 @@ export const MonacoEditor: FC = ({ files, onFilesChange, heig if (disposed) return; // Focus Explorer so file tree shows - vscode.commands.executeCommand('workbench.view.explorer').then(() => {}, () => {}); + vscode.commands.executeCommand('workbench.view.explorer').then(() => { }, () => { }); // Workbench ready — editor is visible, hide skeleton setReady(true); @@ -776,17 +776,17 @@ export const MonacoEditor: FC = ({ files, onFilesChange, heig ); workerRef.current = worker; - // Listen for the 'ready' message IMMEDIATELY — before any awaits — - // so we don't miss it if WASM loads fast (e.g. from cache). - const workerReadyPromise = new Promise((resolve) => { - const onMsg = (event: MessageEvent) => { - if (event.data?.type === 'ready') { - worker!.removeEventListener('message', onMsg); - resolve(); - } - }; - worker!.addEventListener('message', onMsg); - }); + // Listen for the 'ready' message IMMEDIATELY — before any awaits — + // so we don't miss it if WASM loads fast (e.g. from cache). + const workerReadyPromise = new Promise((resolve) => { + const onMsg = (event: MessageEvent) => { + if (event.data?.type === 'ready') { + worker!.removeEventListener('message', onMsg); + resolve(); + } + }; + worker!.addEventListener('message', onMsg); + }); // Listen for VFS mutations from the WASM runtime (worker → main). const onVfsChange = (event: MessageEvent) => { @@ -812,7 +812,7 @@ export const MonacoEditor: FC = ({ files, onFilesChange, heig const { path: relPath } = data as { path: string }; delete lf[relPath]; const absPath = `/workspace/${relPath}`; - fsp.delete(vs.Uri.file(absPath), { recursive: false, useTrash: false, atomic: false }).catch(() => {}); + fsp.delete(vs.Uri.file(absPath), { recursive: false, useTrash: false, atomic: false }).catch(() => { }); if (isMediaPath(relPath)) remBlob(relPath); onFilesChangeRef.current({ ...lf }); } else if (data?.type === 'buildTime') { @@ -928,7 +928,7 @@ export const MonacoEditor: FC = ({ files, onFilesChange, heig worker = null; } }; - // eslint-disable-next-line react-hooks/exhaustive-deps + // eslint-disable-next-line react-hooks/exhaustive-deps }, []); const isDev = process.env.NODE_ENV === "development"; @@ -963,8 +963,8 @@ export const MonacoEditor: FC = ({ files, onFilesChange, heig const delta = Math.floor(Date.now() / 1000) - wasmBuildTime; const rel = delta < 60 ? `${delta}s ago` : delta < 3600 ? `${Math.floor(delta / 60)}m ago` - : delta < 86400 ? `${Math.floor(delta / 3600)}h ago` - : `${Math.floor(delta / 86400)}d ago`; + : delta < 86400 ? `${Math.floor(delta / 3600)}h ago` + : `${Math.floor(delta / 86400)}d ago`; return ( Built: {abs} ({rel}) diff --git a/typescript2/app-promptfiddle/src/playground/baml-monarch.ts b/typescript2/app-promptfiddle/src/playground/baml-monarch.ts deleted file mode 100644 index d75b1abf4e..0000000000 --- a/typescript2/app-promptfiddle/src/playground/baml-monarch.ts +++ /dev/null @@ -1,171 +0,0 @@ -/** - * Monaco Monarch grammar for the BAML language. - * - * Provides syntax highlighting for BAML files in the Monaco editor. - * This grammar covers keywords, strings, comments, type annotations, - * template interpolations, and attributes. - */ - -import type * as monaco from 'monaco-editor'; - -export const BAML_LANGUAGE_ID = 'baml'; - -export const bamlLanguageConfiguration: monaco.languages.LanguageConfiguration = { - comments: { - lineComment: '//', - blockComment: ['/*', '*/'], - }, - brackets: [ - ['{', '}'], - ['[', ']'], - ['(', ')'], - ], - autoClosingPairs: [ - { open: '{', close: '}' }, - { open: '[', close: ']' }, - { open: '(', close: ')' }, - { open: '"', close: '"', notIn: ['string'] }, - { open: "'", close: "'", notIn: ['string'] }, - ], - surroundingPairs: [ - { open: '{', close: '}' }, - { open: '[', close: ']' }, - { open: '(', close: ')' }, - { open: '"', close: '"' }, - { open: "'", close: "'" }, - ], - folding: { - markers: { - start: /^\s*\{/, - end: /^\s*\}/, - }, - }, -}; - -export const bamlMonarchLanguage: monaco.languages.IMonarchLanguage = { - defaultToken: '', - tokenPostfix: '.baml', - - // BAML keywords - keywords: [ - 'function', 'class', 'enum', 'client', 'generator', 'test', - 'retry_policy', 'template_string', 'type_builder', - 'if', 'else', 'for', 'while', 'let', 'in', - 'break', 'continue', 'return', 'match', 'assert', - 'watch', 'instanceof', 'env', 'dynamic', - 'true', 'false', 'null', - ], - - // Primitive types - typeKeywords: [ - 'int', 'float', 'string', 'bool', 'null', 'image', 'audio', - ], - - operators: [ - '=', '==', '!=', '<', '>', '<=', '>=', - '+', '-', '*', '/', - '&&', '||', '!', - '->', '=>', '|', '?', '.', - '@@', '@', - ], - - symbols: /[=>/, 'operator'], - [/=>/, 'operator'], - [/@symbols/, { - cases: { - '@operators': 'operator', - '@default': '', - }, - }], - - // Comma, semicolons - [/[;,]/, 'delimiter'], - ], - - blockComment: [ - [/[^/*]+/, 'comment'], - [/\*\//, 'comment', '@pop'], - [/[/*]/, 'comment'], - ], - - string: [ - [/[^\\"]+/, 'string'], - [/@escapes/, 'string.escape'], - [/\\./, 'string.escape.invalid'], - [/"/, 'string', '@pop'], - ], - - // After seeing '#', check for '"' to start a raw string - rawStringPrefix: [ - [/"/, { token: 'string.delim', next: '@rawStringBody' }], - // If not followed by ", pop back and treat the # as punctuation - [/./, { token: 'delimiter', next: '@pop', goBack: 1 }], - ], - - rawStringBody: [ - // Template interpolation inside raw strings - [/\{\{/, { token: 'delimiter.bracket', next: '@interpolation' }], - // End of raw string: "# (simplified — doesn't count hashes) - [/"#+/, { token: 'string.delim', next: '@popall' }], - [/[^"{}]+/, 'string'], - [/./, 'string'], - ], - - interpolation: [ - [/\}\}/, { token: 'delimiter.bracket', next: '@pop' }], - [/[a-zA-Z_]\w*/, { - cases: { - '@keywords': 'keyword', - '@default': 'identifier', - }, - }], - [/\./, 'delimiter'], - [/[ \t\r\n]+/, 'white'], - [/./, ''], - ], - }, -}; diff --git a/typescript2/app-promptfiddle/src/playground/baml.tmLanguage.json b/typescript2/app-promptfiddle/src/playground/baml.tmLanguage.json deleted file mode 100644 index 839950298e..0000000000 --- a/typescript2/app-promptfiddle/src/playground/baml.tmLanguage.json +++ /dev/null @@ -1,1674 +0,0 @@ -{ - "fileTypes": ["baml"], - "name": "baml", - "patterns": [ - { - "include": "#comment" - }, - { - "include": "#schema" - } - ], - "repository": { - "schema": { - "patterns": [ - { - "include": "#enum_declaration" - }, - { - "include": "#interface_declaration" - }, - { - "include": "#template_string_declaration" - }, - { - "include": "#function_declaration" - }, - { - "include": "#function_application" - }, - { - "include": "#let_declaration" - }, - { - "include": "#config_block" - }, - { - "include": "#type_alias" - }, - { - "include": "#function" - }, - { - "include": "#language_block_python" - }, - { - "include": "#language_block_ts" - }, - { - "include": "#language_block_jinja" - }, - { - "include": "#type_builder" - } - ] - }, - "comment": { - "patterns": [ - { - "name": "comment.line", - "match": "//.*" - }, - { - "name": "comment.block.documentation", - "begin": "///", - "end": "$", - "patterns": [ - { - "name": "comment.block.documentation", - "match": ".*" - } - ] - }, - { - "include": "#curly_comment" - } - ] - }, - "enum_declaration": { - "begin": "(enum)\\s+(\\w+)", - "beginCaptures": { - "1": { - "name": "storage.type.enum" - }, - "2": { - "name": "entity.name.type" - } - }, - "end": "\\}", - "patterns": [ - { - "include": "#comment" - }, - { - "include": "#block_attribute" - }, - { - "name": "variable.other.field", - "match": "\\b[A-Za-z_][A-Za-z0-9_]*\\b" - } - ] - }, - "interface_declaration": { - "begin": "(class|override)\\s+(\\w+)\\s*\\{", - "beginCaptures": { - "1": { - "name": "storage.type.declaration.interface" - }, - "2": { - "name": "entity.name.type" - } - }, - "end": "\\}", - "patterns": [ - { - "include": "#comment" - }, - { - "comment": "Property + Type", - "begin": "(\\w+)", - "beginCaptures": { - "1": { - "name": "variable.other.readwrite" - } - }, - "end": "(?=$|\\n|@|\\}|/)", - "patterns": [ - { - "include": "#type_definition" - } - ] - }, - { - "include": "#block_attribute" - } - ] - }, - "dynamic_declaration": { - "begin": "(dynamic)\\s+(\\w+)\\s*\\{", - "beginCaptures": { - "1": { - "name": "storage.type.dynamic" - }, - "2": { - "name": "entity.name.type.dynamic" - } - }, - "end": "\\}", - "patterns": [ - { - "include": "#comment" - }, - { - "comment": "Property + Type", - "begin": "(\\w+)", - "beginCaptures": { - "1": { - "name": "variable.other.readwrite" - } - }, - "end": "(?=$|\\n|@|\\}|/)", - "patterns": [ - { - "include": "#type_definition" - } - ] - }, - { - "name": "variable.other.field", - "match": "\\b[A-Za-z_][A-Za-z0-9_]*\\b" - }, - { - "include": "#block_attribute" - } - ] - }, - "template_string_declaration": { - "begin": "(template_string)\\s+(\\w+)", - "beginCaptures": { - "1": { - "name": "storage.type.declaration.function" - }, - "2": { - "name": "entity.name.function" - } - }, - "end": "^(\"#{1,3})", - "endCaptures": { - "1": { - "name": "string.quoted.block.baml.end" - } - }, - "patterns": [ - { - "include": "#comment" - }, - { - "include": "#function_parameters" - }, - { - "include": "#template_string_body" - } - ] - }, - "template_string_body": { - "begin": "\\s+(#{1,3})(\")", - "beginCaptures": { - "1": { - "name": "string.quoted.block.baml.body.start" - }, - "2": { - "name": "string.quoted.block.baml.body.start" - } - }, - "end": "(?=\"\\1)", - "contentName": "string.quoted.block.baml.body", - "patterns": [ - { - "include": "source.baml-jinja" - } - ] - }, - "function_declaration": { - "comment": "Function declaration", - "begin": "(function)\\s+(\\w+)", - "beginCaptures": { - "1": { - "name": "storage.type.declaration.function" - }, - "2": { - "name": "entity.name.function" - } - }, - "end": "\\}", - "patterns": [ - { - "include": "#comment" - }, - { - "include": "#function_parameters" - }, - { - "include": "#arrow_return_type" - }, - { - "include": "#function_body" - } - ] - }, - "function_application": { - "begin": "(\\w+)\\s*\\(", - "beginCaptures": { - "1": { - "name": "entity.name.function" - } - }, - "end": "\\)", - "patterns": [ - { - "include": "#comment" - }, - { - "include": "#string_literal" - }, - { - "include": "#constant_numeric" - }, - { - "match": "(\\w+)\\s*(?:,|$|\\))", - "captures": { - "1": { - "name": "variable.parameter" - } - } - }, - { - "include": "#function_application" - } - ] - }, - "let_declaration": { - "comment": "Let declaration", - "begin": "(let)\\s+(\\w+)\\s*(=)", - "beginCaptures": { - "1": { - "name": "storage.type.declaration.let" - }, - "2": { - "name": "variable.other.readwrite" - }, - "3": { - "name": "keyword.operator.assignment" - } - }, - "end": ";", - "patterns": [ - { - "include": "#comment" - }, - { - "include": "#string_literal" - }, - { - "include": "#constant_numeric" - }, - { - "include": "#function_parameters" - }, - { - "include": "#arrow_return_type" - }, - { - "include": "#function_application" - }, - { - "include": "#object_construction" - }, - { - "include": "#function_body" - } - ] - }, - "function_parameters": { - "begin": "\\(", - "end": "\\)", - "patterns": [ - { - "include": "#comment" - }, - { - "include": "#function_name_type" - } - ], - "contentName": "function.params" - }, - "function_name_type": { - "patterns": [ - { - "match": "(\\w+)\\s*:", - "captures": { - "1": { - "name": "variable.other.readwrite" - } - } - }, - { - "include": "#type_definition" - } - ] - }, - "type_definition": { - "patterns": [ - { - "match": "\\b(bool|int|float|string|null|image|audio|pdf)\\b", - "name": "storage.type.baml" - }, - { - "begin": "(map)\\s*<", - "beginCaptures": { - "1": { - "name": "storage.type.baml" - } - }, - "patterns": [ - { - "include": "#type_definition" - }, - { - "include": "#type_definition" - } - ], - "end": ">" - }, - { - "match": "\\b(true|false)\\b", - "name": "constant.language.boolean" - }, - { - "match": "\\w+", - "name": "support.type" - }, - { - "include": "#string_literal" - }, - { - "match": "\\[\\]", - "name": "keyword.control.baml" - }, - { - "match": "\\?", - "name": "keyword.control.baml" - }, - { - "comment": "union a | b | c", - "match": "\\|", - "name": "keyword.control.baml" - }, - { - "comment": "Groups", - "begin": "\\(", - "beginCaptures": { - "0": { - "name": "keyword.control" - } - }, - "end": "(\\))(\\[\\])*(\\?)?", - "endCaptures": { - "1": { - "name": "keyword.control" - }, - "2": { - "name": "keyword.control" - }, - "3": { - "name": "keyword.control" - } - }, - "patterns": [ - { - "include": "#type_definition" - } - ] - } - ] - }, - "arrow_return_type": { - "begin": "(?<=\\))\\s*(->)\\s*", - "beginCaptures": { - "1": { - "name": "keyword.control.baml.arrow" - } - }, - "end": "(?=\\{)", - "patterns": [ - { - "include": "#comment" - }, - { - "include": "#type_definition" - } - ] - }, - "function_body": { - "begin": "(?<=\\{)\\s*", - "end": "(?=\\})", - "patterns": [ - { - "include": "#comment" - }, - { - "include": "#markdown_header" - }, - { - "include": "#block_attribute" - }, - { - "include": "#let_declaration" - }, - { - "include": "#for_in_loop" - }, - { - "include": "#for_c_loop" - }, - { - "include": "#if_statement" - }, - { - "include": "#else_clause" - }, - { - "include": "#while_statement" - }, - { - "include": "#assignment_statement" - }, - { - "include": "#object_construction" - }, - { - "comment": "Function client properties", - "patterns": [ - { - "match": "(client)\\s+(\\w+|\"[^\"]*\")", - "captures": { - "1": { - "name": "variable.other.readwrite.client" - }, - "2": { - "patterns": [ - { - "match": "\\w+", - "name": "entity.name.other.client" - }, - { - "include": "#string_literal" - } - ] - } - }, - "name": "meta.client.declaration" - }, - { - "begin": "\\s+(prompt)\\s+(#{1,5})(\")", - "beginCaptures": { - "1": { - "name": "variable.other.readwrite.prompt" - }, - "2": { - "name": "string.quoted.block.baml.prompt" - }, - "3": { - "name": "string.quoted.block.baml.prompt" - } - }, - "end": "\\s*(\"\\2)", - "contentName": "string.quoted.block.baml.prompt", - "endCaptures": { - "0": { - "name": "string.quoted.block.baml.prompt" - } - }, - "patterns": [ - { - "include": "source.baml-jinja" - } - ] - } - ] - } - ] - }, - "key_value_pair": { - "begin": "(\\w+)\\s*", - "beginCaptures": { - "1": { - "name": "variable.other.readwrite.key_value_pair" - } - }, - "end": "(?=\\n)", - "patterns": [ - { - "include": "#string_literal" - } - ] - }, - "keyword": { - "patterns": [ - { - "match": "\\b(input|output)\\b", - "name": "keyword.special.input-output" - } - ] - }, - "single_variable_no_assignment": { - "match": "^\\s*\\w+\\b", - "name": "variable.other.readwrite.single_var" - }, - "config_block": { - "begin": "(client|generator|retry_policy|printer|test)\\s*(<([^>]+)>)?\\s+(\\w+)\\s*\\{", - "beginCaptures": { - "1": { - "name": "storage.type.declaration" - }, - "3": { - "name": "storage.type.declaration" - }, - "4": { - "name": "entity.name.type" - } - }, - "end": "\\}", - "patterns": [ - { - "include": "#comment" - }, - { - "include": "#block_attribute" - }, - { - "include": "#type_builder" - }, - { - "include": "#property_assignment_expression" - } - ] - }, - "block_attribute": { - "patterns": [ - { - "begin": "(@{1,2}(?:check|assert))\\s*\\(\\s*(?=\\{\\{)", - "beginCaptures": { - "1": { - "name": "entity.name.function.attribute" - } - }, - "end": "\\)\\s*", - "contentName": "string.quoted.block.thing", - "patterns": [ - { - "include": "source.baml-jinja" - } - ] - }, - { - "begin": "(@{1,2}(?:check|assert))\\s*\\(([^,]+)?\\s*,\\s*(?=\\{\\{)", - "beginCaptures": { - "1": { - "name": "entity.name.function.attribute" - }, - "2": { - "name": "variable.parameter.checkName" - } - }, - "end": "\\)\\s*", - "contentName": "string.quoted.block.thing", - "patterns": [ - { - "include": "source.baml-jinja" - } - ] - }, - { - "begin": "(@{1,2}(?:check|assert))\\(([^,]+)?\\s*,\\s*()", - "beginCaptures": { - "1": { - "name": "entity.name.function.attribute" - }, - "2": { - "name": "variable.parameter.checkName" - } - }, - "end": "\\)", - "contentName": "string.quoted.block.thing", - "patterns": [ - { - "include": "source.baml-jinja" - } - ] - }, - { - "begin": "(@{1,2}\\w+)\\(#\"", - "beginCaptures": { - "1": { - "name": "entity.name.function.attribute" - } - }, - "end": "\"#\\)", - "name": "string.quoted.block.baml", - "patterns": [ - { - "include": "#comment" - }, - { - "include": "#language_block_python" - }, - { - "include": "#language_block_ts" - }, - { - "include": "#key_value" - }, - { - "include": "#block_string_pair" - }, - { - "include": "#string_literal" - }, - { - "match": "\\(", - "name": "punctuation.section.parens.open" - }, - { - "match": "\\)", - "name": "punctuation.section.parens.close" - } - ] - }, - { - "begin": "(@{1,2}\\w+)\\(#{1,3}\"", - "beginCaptures": { - "1": { - "name": "entity.name.function.attribute" - } - }, - "end": "\"#{1,3}\\)", - "name": "string.quoted.block.baml", - "patterns": [ - { - "include": "#comment" - }, - { - "include": "#language_block_python" - }, - { - "include": "#language_block_ts" - }, - { - "include": "#key_value" - }, - { - "include": "#block_string_pair" - }, - { - "include": "#string_literal" - }, - { - "match": "\\(", - "name": "punctuation.section.parens.open" - }, - { - "match": "\\)", - "name": "punctuation.section.parens.close" - } - ] - }, - { - "begin": "(@{1,2}\\w+)\\(", - "beginCaptures": { - "1": { - "name": "entity.name.function.attribute" - } - }, - "end": "\\)", - "patterns": [ - { - "include": "#string_unquoted" - }, - { - "include": "#comment" - }, - { - "include": "#language_block_python" - }, - { - "include": "#language_block_ts" - }, - { - "include": "#key_value" - }, - { - "include": "#block_string_pair" - }, - { - "include": "#string_literal", - "name": "string.quoted.double" - }, - { - "match": "\\(", - "name": "punctuation.section.parens.open" - }, - { - "match": "\\)", - "name": "punctuation.section.parens.close" - } - ] - }, - { - "begin": "(@{1,2}\\w+)\\(\"", - "beginCaptures": { - "1": { - "name": "entity.name.function.attribute" - } - }, - "end": "\"\\)", - "patterns": [ - { - "include": "#string_literal", - "name": "string.quoted.double" - } - ] - }, - { - "begin": "(@{1,2}\\w+)\\(", - "beginCaptures": { - "1": { - "name": "entity.name.function.attribute" - } - }, - "end": "\\)", - "patterns": [ - { - "match": "\\w+", - "name": "string.unquoted" - } - ] - }, - { - "begin": "(@{1,2}\\w+)\\(#{1,3}", - "beginCaptures": { - "1": { - "name": "entity.name.function.attribute" - } - }, - "end": "#{1,3}\\)", - "name": "string.quoted.block.baml", - "patterns": [ - { - "name": "constant.character.escape", - "match": "\\\\." - }, - { - "name": "meta.embedded.block_attribute", - "begin": "\\(", - "end": "\\)" - }, - { - "include": "#comment" - }, - { - "include": "#language_block_python" - }, - { - "include": "#language_block_ts" - }, - { - "include": "#key_value" - }, - { - "include": "#block_string_pair" - }, - { - "include": "#string_literal" - }, - { - "match": ".", - "name": "text.plain" - } - ] - } - ] - }, - "key_value": { - "begin": "\\s*\\{", - "end": "\\s*\\}", - "patterns": [ - { - "include": "#comment" - }, - { - "include": "#property_assignment_expression" - } - ] - }, - "property_assignment_expression": { - "patterns": [ - { - "include": "#key_null_pair" - }, - { - "include": "#language_block_python" - }, - { - "include": "#language_block_ts" - }, - { - "include": "#block_string_pair" - }, - { - "include": "#key_value" - }, - { - "include": "#comment" - }, - { - "include": "#key_string_pair" - }, - { - "include": "#key_quoted_string_pair" - }, - { - "include": "#key_number_pair" - }, - { - "include": "#key_boolean_pair" - }, - { - "include": "#key_array_pair" - }, - { - "include": "#key_custom_string_pair" - }, - { - "include": "#nested_key_value" - } - ] - }, - "nested_key_value": { - "begin": "(\"\\w+\"|\\b\\w+\\b)\\s+\\{", - "end": "\\}", - "captures": { - "1": { - "name": "variable.other.readwrite.nested_key" - } - }, - "contentName": "variable.other.readwrite.nested", - "patterns": [ - { - "include": "#comment" - }, - { - "include": "#key_value" - }, - { - "include": "#key_null_pair" - }, - { - "include": "#key_string_pair" - }, - { - "include": "#language_block_python" - }, - { - "include": "#language_block_ts" - }, - { - "include": "#block_string_pair" - }, - { - "include": "#key_quoted_string_pair" - }, - { - "include": "#key_number_pair" - }, - { - "include": "#key_boolean_pair" - }, - { - "include": "#key_array_pair" - }, - { - "include": "#key_custom_string_pair" - } - ] - }, - "language_block_jinja": { - "begin": "(jinja)(#{1,3}\")", - "beginCaptures": { - "1": { - "name": "comment.line" - }, - "2": { - "name": "string.quoted" - } - }, - "end": "\\s*(\"{1,3}#)", - "endCaptures": { - "1": { - "name": "string.quoted" - } - }, - "contentName": "source.baml-jinja.embedded", - "patterns": [ - { - "include": "source.baml-jinja" - } - ] - }, - "language_block_python": { - "begin": "(python)(#{1,3}\")", - "beginCaptures": { - "1": { - "name": "comment.line" - }, - "2": { - "name": "string.quoted" - } - }, - "end": "\\s*(\"{1,3}#)", - "endCaptures": { - "1": { - "name": "string.quoted" - } - }, - "contentName": "source.python.embedded", - "patterns": [ - { - "include": "source.python" - } - ] - }, - "language_block_ts": { - "begin": "(typescript)(#{1,3}\")", - "beginCaptures": { - "1": { - "name": "comment.line" - }, - "2": { - "name": "string.quoted" - } - }, - "end": "\\s*(\"{1,3}#)", - "endCaptures": { - "1": { - "name": "string.quoted" - } - }, - "contentName": "source.ts.embedded", - "patterns": [ - { - "include": "source.ts" - } - ] - }, - "block_string_pair": { - "begin": "(\\w+)?\\s+(#{1,3}(\"){1,3})", - "beginCaptures": { - "1": { - "name": "variable.other.readwrite.block_string_pair" - }, - "2": { - "name": "string.quoted.block.baml.startquote" - } - }, - "end": "((\"){1,3}#{1,3})", - "endCaptures": { - "1": { - "name": "string.quoted.block.baml.endquote" - } - }, - "contentName": "string.quoted.block.baml.stringpair", - "patterns": [ - { - "include": "#curly_comment" - }, - { - "name": "entity.name.type.chat", - "match": "\\{#chat\\([^}]*\\)}" - }, - { - "name": "keyword.special.string.code", - "match": "\\{#[a-zA-Z_][a-zA-Z0-9_.()><]*}" - } - ] - }, - "curly_comment": { - "begin": "\\{//", - "beginCaptures": {}, - "end": "//}", - "endCaptures": {}, - "name": "comment.line.double-slash.baml", - "patterns": [ - { - "include": "#language_block_python" - }, - { - "include": "#language_block_ts" - } - ] - }, - "key_quoted_string_pair": { - "match": "(\"[^\"]+\")\\s+(\"[^\"]+\")", - "captures": { - "1": { - "name": "string.quoted.double" - }, - "2": { - "name": "string.quoted.double" - } - } - }, - "key_string_pair": { - "begin": "(\"\\w+\"|\\b\\w+\\b)\\s+(\")", - "beginCaptures": { - "1": { - "name": "variable.other.readwrite.key_string_pair" - }, - "2": { - "name": "string.quoted.double" - } - }, - "end": "\"", - "endCaptures": { - "0": { - "name": "string.quoted.double" - } - }, - "patterns": [ - { - "name": "constant.character.escape", - "match": "\\\\." - }, - { - "name": "string.quoted.double", - "match": "[^\"\\\\]+" - } - ] - }, - "key_custom_string_pair": { - "match": "(\"\\w+\"|\\b\\w+\\b)\\s+((?!null)[^\\s\\[\\{]+)", - "captures": { - "1": { - "name": "variable.other.readwrite.custom_string" - }, - "2": { - "name": "string.unquoted" - } - } - }, - "key_number_pair": { - "match": "(\"\\w+\"|\\b\\w+\\b)\\s+(\\b\\d+\\b)", - "captures": { - "1": { - "name": "variable.other.readwrite.number_pair" - }, - "2": { - "name": "constant.numeric" - } - } - }, - "key_boolean_pair": { - "match": "(\"\\w+\"|\\b\\w+\\b)\\s+(\\btrue\\b|\\bfalse\\b)", - "captures": { - "1": { - "name": "variable.other.readwrite" - }, - "2": { - "name": "constant.language.boolean" - } - } - }, - "key_null_pair": { - "match": "(\"\\w+\"|\\b\\w+\\b)\\s+(\\bnull\\b)", - "captures": { - "1": { - "name": "variable.other.readwrite.null" - }, - "2": { - "name": "constant.language.nil.null" - } - } - }, - "key_array_pair": { - "begin": "(\"\\w+\"|\\b\\w+\\b)\\s+\\[", - "end": "\\]", - "captures": { - "1": { - "name": "variable.other.readwrite" - } - }, - "contentName": "variable.other.readwrite.array", - "patterns": [ - { - "include": "#key_array_pair" - }, - { - "include": "#string_quoted2" - }, - { - "include": "#constant_numeric" - } - ] - }, - "string_quoted2": { - "name": "string.quoted.double", - "begin": "\"", - "end": "\"", - "patterns": [ - { - "name": "constant.character.escape", - "match": "\\\\." - } - ] - }, - "string_unquoted": { - "match": "\\b[\\w-]+\\b", - "name": "string.unquoted" - }, - "constant_numeric": { - "match": "\\b\\d+\\b", - "name": "constant.numeric" - }, - "type_alias": { - "begin": "(type)\\s+(\\w+)\\s*(=)", - "beginCaptures": { - "1": { - "name": "storage.type.declaration" - }, - "2": { - "name": "entity.name.type" - }, - "3": { - "name": "keyword.operator.assignment" - } - }, - "end": "(?=$|\\n)", - "patterns": [ - { - "include": "#comment" - }, - { - "begin": "(?<=\\=)\\s*", - "end": "(?=//|$|\\n)", - "patterns": [ - { - "include": "#type_definition" - }, - { - "include": "#block_attribute" - } - ] - } - ] - }, - "invalid_assignment": { - "name": "invalid.illegal", - "match": "\\b[a-zA-Z_][a-zA-Z0-9_]*\\s+[a-zA-Z_][a-zA-Z0-9_]*\\s+[a-zA-Z_][a-zA-Z0-9_]*" - }, - "string_literal": { - "match": "\"[^\"]*\"", - "name": "string.quoted.double" - }, - "type_builder": { - "begin": "(type_builder)\\s*\\{", - "beginCaptures": { - "1": { - "name": "keyword.control.type_builder" - } - }, - "end": "\\}", - "patterns": [ - { - "include": "#interface_declaration" - }, - { - "include": "#enum_declaration" - }, - { - "include": "#dynamic_declaration" - }, - { - "include": "#type_alias" - }, - { - "include": "#comment" - } - ] - }, - "for_in_loop": { - "comment": "For-in loop", - "begin": "(for)\\s*\\(\\s*(\\w+)\\s+(in)\\s+", - "beginCaptures": { - "1": { - "name": "keyword.control.for" - }, - "2": { - "name": "variable.other.readwrite" - }, - "3": { - "name": "keyword.control.in" - } - }, - "end": "\\}", - "patterns": [ - { - "include": "#comment" - }, - { - "include": "#array_literal" - }, - { - "include": "#function_application" - }, - { - "include": "#expression_body" - } - ] - }, - "for_c_loop": { - "comment": "C-style for loop", - "begin": "(for)\\s*\\(\\s*", - "beginCaptures": { - "1": { - "name": "keyword.control.for" - } - }, - "end": "\\}", - "patterns": [ - { - "include": "#comment" - }, - { - "include": "#for_c_init_statement" - }, - { - "include": "#for_c_condition" - }, - { - "include": "#for_c_update" - }, - { - "include": "#let_declaration" - }, - { - "include": "#assignment_statement" - }, - { - "include": "#binary_operators" - }, - { - "include": "#increment_operators" - }, - { - "include": "#expression_body" - } - ] - }, - "if_statement": { - "comment": "If-else statement", - "begin": "(if)\\s*\\(", - "beginCaptures": { - "1": { - "name": "keyword.control.if" - } - }, - "end": "(?<=\\})", - "patterns": [ - { - "include": "#comment" - }, - { - "include": "#binary_operators" - }, - { - "include": "#expression" - }, - { - "include": "#expression_body" - }, - { - "include": "#else_clause" - } - ] - }, - "else_clause": { - "comment": "Else clause", - "match": "(else)\\s*(if)?", - "captures": { - "1": { - "name": "keyword.control.else" - }, - "2": { - "name": "keyword.control.if" - } - } - }, - "while_statement": { - "comment": "While loop", - "begin": "(while)\\s*\\(", - "beginCaptures": { - "1": { - "name": "keyword.control.while" - } - }, - "end": "\\}", - "patterns": [ - { - "include": "#comment" - }, - { - "include": "#binary_operators" - }, - { - "include": "#expression" - }, - { - "include": "#expression_body" - } - ] - }, - "assignment_statement": { - "comment": "Assignment with operators", - "begin": "(\\w+)\\s*([+\\-*/]?=)", - "beginCaptures": { - "1": { - "name": "variable.other.readwrite" - }, - "2": { - "name": "keyword.operator.assignment" - } - }, - "end": ";?", - "patterns": [ - { - "include": "#comment" - }, - { - "include": "#expression" - } - ] - }, - "array_literal": { - "begin": "\\[", - "end": "\\]", - "patterns": [ - { - "include": "#comment" - }, - { - "include": "#constant_numeric" - }, - { - "include": "#string_literal" - }, - { - "include": "#expression" - } - ] - }, - "binary_operators": { - "match": "(<|>|<=|>=|==|!=|&&|\\|\\||[+\\-*/])", - "name": "keyword.operator.binary" - }, - "increment_operators": { - "match": "(\\+\\+|--)", - "name": "keyword.operator.increment" - }, - "expression": { - "patterns": [ - { - "include": "#constant_numeric" - }, - { - "include": "#string_literal" - }, - { - "include": "#array_literal" - }, - { - "include": "#function_application" - }, - { - "include": "#object_construction" - }, - { - "include": "#method_call" - }, - { - "include": "#binary_operators" - } - ] - }, - "expression_body": { - "begin": "\\{", - "end": "(?=\\})", - "patterns": [ - { - "include": "#comment" - }, - { - "include": "#markdown_header" - }, - { - "include": "#let_declaration" - }, - { - "include": "#assignment_statement" - }, - { - "include": "#for_in_loop" - }, - { - "include": "#for_c_loop" - }, - { - "include": "#if_statement" - }, - { - "include": "#else_clause" - }, - { - "include": "#while_statement" - }, - { - "include": "#object_construction" - }, - { - "include": "#expression" - } - ] - }, - "object_construction": { - "comment": "Object construction ClassName { ... }", - "begin": "(\\w+)\\s*\\{", - "beginCaptures": { - "1": { - "name": "entity.name.type" - } - }, - "end": "\\}", - "patterns": [ - { - "include": "#comment" - }, - { - "include": "#object_field" - } - ] - }, - "object_field": { - "comment": "field_name: value", - "begin": "(\\w+)\\s*:", - "beginCaptures": { - "1": { - "name": "variable.other.readwrite.interface" - } - }, - "end": "(?=,|\\})", - "patterns": [ - { - "include": "#comment" - }, - { - "include": "#expression" - } - ] - }, - "method_call": { - "comment": "obj.method()", - "match": "(\\w+)\\.(\\w+)\\s*\\(", - "captures": { - "1": { - "name": "variable.other.readwrite" - }, - "2": { - "name": "entity.name.function.method" - } - } - }, - "markdown_header": { - "comment": "Markdown headers # ## ###", - "patterns": [ - { - "match": "^\\s*(#{6})\\s+(.*)$", - "captures": { - "1": { - "name": "punctuation.definition.heading.markdown" - }, - "2": { - "name": "entity.name.section.markdown.h6" - } - } - }, - { - "match": "^\\s*(#{5})\\s+(.*)$", - "captures": { - "1": { - "name": "punctuation.definition.heading.markdown" - }, - "2": { - "name": "entity.name.section.markdown.h5" - } - } - }, - { - "match": "^\\s*(#{4})\\s+(.*)$", - "captures": { - "1": { - "name": "punctuation.definition.heading.markdown" - }, - "2": { - "name": "entity.name.section.markdown.h4" - } - } - }, - { - "match": "^\\s*(#{3})\\s+(.*)$", - "captures": { - "1": { - "name": "punctuation.definition.heading.markdown" - }, - "2": { - "name": "entity.name.section.markdown.h3" - } - } - }, - { - "match": "^\\s*(#{2})\\s+(.*)$", - "captures": { - "1": { - "name": "punctuation.definition.heading.markdown" - }, - "2": { - "name": "entity.name.section.markdown.h2" - } - } - }, - { - "match": "^\\s*(#{1})\\s+(.*)$", - "captures": { - "1": { - "name": "punctuation.definition.heading.markdown" - }, - "2": { - "name": "entity.name.section.markdown.h1" - } - } - } - ] - }, - "for_c_init_statement": { - "comment": "C-style for loop initialization statement", - "patterns": [ - { - "comment": "Let declaration in for loop (preferred)", - "match": "(let)\\s+(\\w+)\\s*(=)", - "captures": { - "1": { - "name": "storage.type.declaration.let" - }, - "2": { - "name": "variable.other.readwrite" - }, - "3": { - "name": "keyword.operator.assignment" - } - } - }, - { - "comment": "Variable assignment in for loop (requires existing variable)", - "match": "(\\w+)\\s*(=|\\+=|-=|\\*=|/=|%=)", - "captures": { - "1": { - "name": "variable.other.readwrite" - }, - "2": { - "name": "keyword.operator.assignment" - } - } - } - ] - }, - "for_c_condition": { - "comment": "C-style for loop condition", - "patterns": [ - { - "include": "#expression" - }, - { - "include": "#binary_operators" - } - ] - }, - "for_c_update": { - "comment": "C-style for loop update statement", - "patterns": [ - { - "comment": "Increment/decrement operators", - "match": "(\\w+)(\\+\\+|--)", - "captures": { - "1": { - "name": "variable.other.readwrite" - }, - "2": { - "name": "keyword.operator.increment" - } - } - }, - { - "comment": "Assignment operators in update", - "match": "(\\w+)\\s*(\\+=|-=|\\*=|/=|%=)", - "captures": { - "1": { - "name": "variable.other.readwrite" - }, - "2": { - "name": "keyword.operator.assignment" - } - } - } - ] - } - }, - "scopeName": "source.baml" -} diff --git a/typescript2/app-promptfiddle/syntaxes/baml.tmLanguage.json b/typescript2/app-promptfiddle/syntaxes/baml.tmLanguage.json new file mode 100644 index 0000000000..e73917793e --- /dev/null +++ b/typescript2/app-promptfiddle/syntaxes/baml.tmLanguage.json @@ -0,0 +1,1229 @@ +{ + "fileTypes": [ + "baml" + ], + "name": "baml", + "scopeName": "source.baml", + "patterns": [ + { + "include": "#comment" + }, + { + "include": "#item" + } + ], + "repository": { + "comment": { + "patterns": [ + { + "name": "comment.line.baml", + "match": "//.*$" + }, + { + "name": "comment.block.baml", + "begin": "/\\*", + "end": "\\*/" + } + ] + }, + "item": { + "patterns": [ + { + "include": "#enum" + }, + { + "include": "#class" + }, + { + "include": "#function" + }, + { + "include": "#template-string" + }, + { + "include": "#type-alias" + }, + { + "include": "#client" + }, + { + "include": "#test" + }, + { + "include": "#generator" + }, + { + "include": "#retry-policy" + } + ] + }, + "client": { + "begin": "\\b(client)\\b(<([a-zA-Z_][a-zA-Z0-9_]*)>)?", + "beginCaptures": { + "1": { + "name": "keyword.declaration.baml" + }, + "3": { + "name": "entity.name.type.baml" + } + }, + "end": "(?<=\\})", + "patterns": [ + { + "include": "#comment" + }, + { + "match": "([a-zA-Z_][a-zA-Z0-9_]*)", + "captures": { + "1": { + "name": "entity.name.type.baml" + } + } + }, + { + "include": "#config-block" + } + ] + }, + "test": { + "begin": "\\b(test)\\b", + "beginCaptures": { + "1": { + "name": "keyword.declaration.baml" + } + }, + "end": "(?<=\\})", + "patterns": [ + { + "include": "#comment" + }, + { + "match": "([a-zA-Z_][a-zA-Z0-9_]*)", + "captures": { + "1": { + "name": "entity.name.type.baml" + } + } + }, + { + "include": "#config-block" + } + ] + }, + "generator": { + "begin": "\\b(generator)\\b", + "beginCaptures": { + "1": { + "name": "keyword.declaration.baml" + } + }, + "end": "(?<=\\})", + "patterns": [ + { + "include": "#comment" + }, + { + "match": "([a-zA-Z_][a-zA-Z0-9_]*)", + "captures": { + "1": { + "name": "entity.name.type.baml" + } + } + }, + { + "include": "#config-block" + } + ] + }, + "retry-policy": { + "begin": "\\b(retry_policy)\\b", + "beginCaptures": { + "1": { + "name": "keyword.declaration.baml" + } + }, + "end": "(?<=\\})", + "patterns": [ + { + "include": "#comment" + }, + { + "match": "([a-zA-Z_][a-zA-Z0-9_]*)", + "captures": { + "1": { + "name": "entity.name.type.baml" + } + } + }, + { + "include": "#config-block" + } + ] + }, + "config-block": { + "begin": "\\{", + "end": "\\}", + "patterns": [ + { + "include": "#comment" + }, + { + "include": "#type-builder" + }, + { + "include": "#config-block-entry" + } + ] + }, + "type-builder": { + "begin": "\\b(type_builder)\\b", + "beginCaptures": { + "1": { + "name": "keyword.declaration.baml" + } + }, + "end": "(?<=\\})", + "patterns": [ + { + "include": "#comment" + }, + { + "include": "#type-builder-block" + } + ] + }, + "type-builder-block": { + "begin": "\\{", + "end": "\\}", + "patterns": [ + { + "include": "#comment" + }, + { + "match": "\\b(dynamic)\\b", + "captures": { + "1": { + "name": "keyword.declaration.baml" + } + } + }, + { + "include": "#item" + } + ] + }, + "config-block-entry": { + "begin": "([a-zA-Z_][a-zA-Z0-9_]*)", + "beginCaptures": { + "1": { + "name": "variable.other.property.baml" + } + }, + "end": "(?=\\})|$", + "patterns": [ + { + "include": "#comment" + }, + { + "include": "#config-block" + }, + { + "include": "#expression" + } + ] + }, + "type-alias": { + "begin": "\\b(type)\\b", + "beginCaptures": { + "1": { + "name": "keyword.declaration.baml" + } + }, + "end": "(?=;)|$", + "patterns": [ + { + "include": "#comment" + }, + { + "match": "([a-zA-Z_][a-zA-Z0-9_]*)", + "captures": { + "1": { + "name": "entity.name.type.baml" + } + } + }, + { + "include": "#type-expression" + } + ] + }, + "enum": { + "begin": "\\b(enum)\\b", + "beginCaptures": { + "1": { + "name": "keyword.declaration.baml" + } + }, + "end": "(?<=\\})", + "patterns": [ + { + "include": "#comment" + }, + { + "match": "([a-zA-Z_][a-zA-Z0-9_]*)", + "captures": { + "1": { + "name": "entity.name.type.baml" + } + } + }, + { + "include": "#enum-block" + } + ] + }, + "enum-block": { + "begin": "\\{", + "end": "\\}", + "patterns": [ + { + "include": "#comment" + }, + { + "include": "#attribute" + }, + { + "include": "#enum-variant" + } + ] + }, + "enum-variant": { + "begin": "([a-zA-Z_][a-zA-Z0-9_]*)", + "beginCaptures": { + "1": { + "name": "variable.other.baml" + } + }, + "end": "(?=@)|$", + "patterns": [ + { + "include": "#comment" + }, + { + "include": "#attribute" + } + ] + }, + "class": { + "begin": "\\b(class)\\b", + "beginCaptures": { + "1": { + "name": "keyword.declaration.baml" + } + }, + "end": "(?<=\\})", + "patterns": [ + { + "include": "#comment" + }, + { + "match": "([a-zA-Z_][a-zA-Z0-9_]*)", + "captures": { + "1": { + "name": "entity.name.type.baml" + } + } + }, + { + "include": "#class-block" + } + ] + }, + "class-block": { + "begin": "\\{", + "end": "\\}", + "patterns": [ + { + "include": "#comment" + }, + { + "include": "#attribute" + }, + { + "include": "#class-member" + } + ] + }, + "class-member": { + "patterns": [ + { + "include": "#function" + }, + { + "include": "#class-field" + } + ] + }, + "class-field": { + "begin": "([a-zA-Z_][a-zA-Z0-9_]*)", + "beginCaptures": { + "1": { + "name": "variable.other.property.baml" + } + }, + "end": "(?=@)|$", + "patterns": [ + { + "include": "#comment" + }, + { + "include": "#type-expression" + }, + { + "include": "#attribute" + } + ] + }, + "attribute": { + "begin": "(@@?[a-zA-Z_][a-zA-Z0-9_]*)", + "beginCaptures": { + "1": { + "name": "entity.other.attribute-name.baml" + } + }, + "end": "(?<=\\))|(?![(\\s])", + "patterns": [ + { + "include": "#attribute-arguments" + } + ] + }, + "attribute-arguments": { + "begin": "\\(", + "end": "\\)", + "patterns": [ + { + "include": "#expression" + }, + { + "match": "," + } + ] + }, + "function": { + "begin": "\\b(function)\\b", + "beginCaptures": { + "1": { + "name": "keyword.declaration.baml" + } + }, + "end": "(?<=\\})", + "patterns": [ + { + "include": "#comment" + }, + { + "match": "([a-zA-Z_][a-zA-Z0-9_]*)", + "captures": { + "1": { + "name": "entity.name.function.baml" + } + } + }, + { + "include": "#parameter-list" + }, + { + "include": "#return-type" + }, + { + "include": "#function-block" + } + ] + }, + "function-block": { + "begin": "\\{", + "end": "\\}", + "patterns": [ + { + "include": "#comment" + }, + { + "include": "#llm-function-client" + }, + { + "include": "#llm-function-prompt" + }, + { + "include": "#statement" + } + ] + }, + "llm-function-client": { + "begin": "\\b(client)\\b", + "beginCaptures": { + "1": { + "name": "keyword.declaration.baml" + } + }, + "end": "$", + "patterns": [ + { + "include": "#comment" + }, + { + "include": "#expression" + } + ] + }, + "llm-function-prompt": { + "begin": "\\b(prompt)\\b", + "beginCaptures": { + "1": { + "name": "keyword.declaration.baml" + } + }, + "end": "(?<=#)", + "patterns": [ + { + "include": "#comment" + }, + { + "include": "#template-string-body" + } + ] + }, + "template-string": { + "begin": "\\b(template_string)\\b", + "beginCaptures": { + "1": { + "name": "keyword.declaration.baml" + } + }, + "patterns": [ + { + "include": "#comment" + }, + { + "match": "([a-zA-Z_][a-zA-Z0-9_]*)", + "captures": { + "1": { + "name": "entity.name.function.baml" + } + } + }, + { + "include": "#parameter-list" + }, + { + "include": "#template-string-body" + } + ], + "end": "(?<=#)" + }, + "template-string-body": { + "begin": "(#+)\"", + "beginCaptures": { + "0": { + "name": "string.quoted.raw.baml" + } + }, + "end": "\\1", + "endCaptures": { + "0": { + "name": "string.quoted.raw.baml" + } + }, + "contentName": "string.quoted.raw.baml", + "patterns": [ + { + "include": "#jinja-escapes" + } + ] + }, + "jinja-escapes": { + "patterns": [ + { + "include": "source.baml-jinja#comments" + }, + { + "begin": "{{-?", + "captures": { + "0": { + "name": "storage.type.jinja.delimiter" + } + }, + "end": "-?}}", + "name": "variable.meta.scope.jinja", + "patterns": [ + { + "include": "source.baml-jinja#expression" + } + ] + }, + { + "begin": "{%-?", + "captures": { + "0": { + "name": "storage.type.jinja.delimiter" + } + }, + "end": "-?%}", + "name": "meta.scope.jinja.tag", + "patterns": [ + { + "include": "source.baml-jinja#expression" + } + ] + } + ] + }, + "return-type": { + "begin": "->\\s*", + "end": "(?=\\{)", + "patterns": [ + { + "include": "#comment" + }, + { + "include": "#type-expression" + } + ] + }, + "parameter": { + "begin": "(self)|([a-zA-Z_][a-zA-Z0-9_]*)", + "beginCaptures": { + "1": { + "name": "variable.language.self.baml" + }, + "2": { + "name": "variable.parameter.baml" + } + }, + "end": "(?=[,)])", + "patterns": [ + { + "include": "#comment" + }, + { + "include": "#type-expression" + } + ] + }, + "parameter-list": { + "begin": "\\(", + "end": "\\)", + "patterns": [ + { + "include": "#comment" + }, + { + "include": "#parameter" + }, + { + "match": "," + } + ] + }, + "type-expression": { + "patterns": [ + { + "include": "#type-generic" + }, + { + "include": "#type-parenthesized" + }, + { + "include": "#literal" + }, + { + "include": "#type-namespaced" + } + ] + }, + "type-parenthesized": { + "begin": "\\(", + "end": "\\)", + "patterns": [ + { + "include": "#type-expression" + } + ] + }, + "type-generic": { + "begin": "(?:[a-zA-Z_][a-zA-Z0-9_]*\\.)*([a-zA-Z_][a-zA-Z0-9_]*)\\s*<", + "beginCaptures": { + "1": { + "name": "entity.name.type.baml" + } + }, + "end": ">", + "patterns": [ + { + "include": "#type-expression" + }, + { + "match": "," + } + ] + }, + "type-namespaced": { + "match": "(?:[a-zA-Z_][a-zA-Z0-9_]*\\.)*([a-zA-Z_][a-zA-Z0-9_]*)", + "captures": { + "1": { + "name": "entity.name.type.baml" + } + } + }, + "imperative-block": { + "begin": "\\{", + "end": "\\}", + "patterns": [ + { + "include": "#comment" + }, + { + "include": "#statement" + } + ] + }, + "return-statement": { + "begin": "\\b(return)\\b", + "beginCaptures": { + "1": { + "name": "keyword.control.baml" + } + }, + "end": ";|(?=\\})", + "patterns": [ + { + "include": "#expression" + } + ] + }, + "throw-expression": { + "begin": "\\b(throw)\\b", + "beginCaptures": { + "1": { + "name": "keyword.control.baml" + } + }, + "end": ";|(?=\\})", + "patterns": [ + { + "include": "#expression" + } + ] + }, + "statement": { + "patterns": [ + { + "include": "#let-statement" + }, + { + "include": "#return-statement" + }, + { + "include": "#continue-statement" + }, + { + "include": "#break-statement" + }, + { + "include": "#for-loop" + }, + { + "include": "#while-loop" + }, + { + "include": "#expression" + } + ] + }, + "continue-statement": { + "begin": "\\b(continue)\\b", + "beginCaptures": { + "1": { + "name": "keyword.control.baml" + } + }, + "end": ";|(?=\\})" + }, + "break-statement": { + "begin": "\\b(break)\\b", + "beginCaptures": { + "1": { + "name": "keyword.control.baml" + } + }, + "end": ";|(?=\\})" + }, + "while-loop": { + "begin": "\\b(while)\\b", + "beginCaptures": { + "1": { + "name": "keyword.control.baml" + } + }, + "end": "(?<=\\})", + "patterns": [ + { + "include": "#imperative-block" + }, + { + "include": "#expression" + } + ] + }, + "for-loop": { + "begin": "\\b(for)\\b", + "beginCaptures": { + "1": { + "name": "keyword.control.baml" + } + }, + "end": "(?<=\\})", + "patterns": [ + { + "include": "#for-in-clause" + }, + { + "include": "#imperative-block" + }, + { + "include": "#statement" + } + ] + }, + "for-in-clause": { + "begin": "(let\\s+)?([a-zA-Z_][a-zA-Z0-9_]*)\\s+(in)\\s+", + "beginCaptures": { + "1": { + "name": "keyword.declaration.baml" + }, + "2": { + "name": "variable.other.baml" + }, + "3": { + "name": "keyword.control.baml" + } + }, + "end": "\\)", + "patterns": [ + { + "include": "#expression" + } + ] + }, + "let-statement": { + "begin": "\\b(let)\\b", + "beginCaptures": { + "1": { + "name": "keyword.declaration.baml" + } + }, + "end": ";", + "patterns": [ + { + "match": "([a-zA-Z_][a-zA-Z0-9_]*)\\s*(?=[:=])", + "captures": { + "1": { + "name": "variable.other.baml" + } + } + }, + { + "include": "#let-type-annotation" + }, + { + "include": "#expression" + } + ] + }, + "let-type-annotation": { + "begin": ":", + "end": "(?==)", + "patterns": [ + { + "include": "#type-expression" + } + ] + }, + "expression": { + "patterns": [ + { + "include": "#literal" + }, + { + "include": "#throw-expression" + }, + { + "include": "#if-expression" + }, + { + "include": "#match-expression" + }, + { + "include": "#catch-expression" + }, + { + "include": "#catch-all-expression" + }, + { + "include": "#object-constructor-expression" + }, + { + "include": "#map-expression" + }, + { + "include": "#array-expression" + }, + { + "include": "#function-call-expression" + }, + { + "include": "#variable-expression" + }, + { + "include": "#property-access-expression" + } + ] + }, + "map-expression": { + "begin": "\\{", + "end": "\\}", + "patterns": [ + { + "include": "#comment" + }, + { + "include": "#map-entry" + }, + { + "match": "," + } + ] + }, + "map-entry": { + "end": "(?=[,}])", + "patterns": [ + { + "include": "#map-entry-key" + }, + { + "include": "#map-entry-value" + } + ] + }, + "map-entry-key": { + "end": "(?=:)", + "patterns": [ + { + "include": "#string-literal" + }, + { + "include": "#raw-string-literal" + }, + { + "match": "([a-zA-Z_][a-zA-Z0-9_]*)", + "captures": { + "1": { + "name": "variable.other.property.baml" + } + } + } + ] + }, + "map-entry-value": { + "begin": ":", + "end": "(?=[,}])", + "patterns": [ + { + "include": "#expression" + } + ] + }, + "match-expression": { + "begin": "\\b(match)\\b", + "beginCaptures": { + "1": { + "name": "keyword.control.baml" + } + }, + "end": "(?<=\\})", + "patterns": [ + { + "include": "#match-scrutinee" + }, + { + "include": "#match-block" + } + ] + }, + "catch-expression": { + "begin": "\\b(catch)\\b", + "beginCaptures": { + "1": { + "name": "keyword.control.baml" + } + }, + "end": "(?<=\\})", + "patterns": [ + { + "include": "#match-scrutinee" + }, + { + "include": "#match-block" + } + ] + }, + "catch-all-expression": { + "begin": "\\b(catch_all)\\b", + "beginCaptures": { + "1": { + "name": "keyword.control.baml" + } + }, + "end": "(?<=\\})", + "patterns": [ + { + "include": "#match-scrutinee" + }, + { + "include": "#match-block" + } + ] + }, + "match-scrutinee": { + "begin": "\\(", + "end": "\\)", + "patterns": [ + { + "include": "#expression" + } + ] + }, + "match-block": { + "begin": "\\{", + "end": "\\}", + "patterns": [ + { + "include": "#comment" + }, + { + "include": "#match-case-typed" + }, + { + "include": "#literal" + }, + { + "include": "#variable-expression" + }, + { + "include": "#match-case-arrow" + } + ] + }, + "match-case-typed": { + "begin": "([a-zA-Z_][a-zA-Z0-9_]*)\\s*:", + "beginCaptures": { + "1": { + "name": "variable.other.baml" + } + }, + "end": "(?==>)", + "patterns": [ + { + "include": "#type-expression" + } + ] + }, + "match-case-arrow": { + "begin": "=>", + "end": "(?<=\\}),?|,|(?=\\})", + "patterns": [ + { + "include": "#imperative-block" + }, + { + "include": "#expression" + } + ] + }, + "property-access-expression": { + "match": "(?:[a-zA-Z_][a-zA-Z0-9_]*\\.?)*\\.([a-zA-Z_][a-zA-Z0-9_]*)", + "captures": { + "1": { + "name": "variable.other.property.baml" + } + } + }, + "variable-expression": { + "match": "(self)|([a-zA-Z_][a-zA-Z0-9_]*)", + "captures": { + "1": { + "name": "variable.language.baml" + }, + "2": { + "name": "variable.other.baml" + } + } + }, + "function-call-expression": { + "begin": "\\.?([a-zA-Z_][a-zA-Z0-9_]*)\\s*(?:<(?:[a-zA-Z_][a-zA-Z0-9_]*\\.)*([a-zA-Z_][a-zA-Z0-9_]*)>)?\\s*\\(", + "beginCaptures": { + "1": { + "name": "entity.name.function.baml" + }, + "2": { + "name": "entity.name.type.baml" + } + }, + "end": "\\)", + "patterns": [ + { + "include": "#comment" + }, + { + "include": "#expression" + }, + { + "match": "," + } + ] + }, + "array-expression": { + "begin": "\\[", + "end": "\\]", + "patterns": [ + { + "include": "#comment" + }, + { + "include": "#expression" + }, + { + "match": "," + } + ] + }, + "object-constructor-expression": { + "begin": "(?:[a-zA-Z_][a-zA-Z0-9_]*\\.)*([a-zA-Z_][a-zA-Z0-9_]*)\\s*\\{", + "beginCaptures": { + "1": { + "name": "entity.name.type.baml" + } + }, + "end": "\\}", + "patterns": [ + { + "include": "#comment" + }, + { + "include": "#object-constructor-property" + } + ] + }, + "object-constructor-property": { + "begin": "([a-zA-Z_][a-zA-Z0-9_]*)\\s*:", + "beginCaptures": { + "1": { + "name": "variable.other.property.baml" + } + }, + "end": "(?=[,}])", + "patterns": [ + { + "include": "#expression" + } + ] + }, + "number-literal": { + "match": "\\b\\d+(\\.\\d+)?\\b", + "name": "constant.numeric.baml" + }, + "string-literal": { + "begin": "\"", + "end": "\"", + "name": "string.quoted.double.baml" + }, + "bool-literal": { + "match": "\\b(true|false)\\b", + "name": "constant.language.boolean.baml" + }, + "null-literal": { + "match": "\\bnull\\b", + "name": "constant.language.null.baml" + }, + "literal": { + "patterns": [ + { + "include": "#number-literal" + }, + { + "include": "#string-literal" + }, + { + "include": "#raw-string-literal" + }, + { + "include": "#bool-literal" + }, + { + "include": "#null-literal" + } + ] + }, + "if-expression": { + "begin": "\\b(if)\\b", + "beginCaptures": { + "1": { + "name": "keyword.control.baml" + } + }, + "end": "(?<=\\})(?!\\s*else\\b)", + "patterns": [ + { + "include": "#if-condition" + }, + { + "include": "#else-clause" + }, + { + "include": "#imperative-block" + } + ] + }, + "if-condition": { + "begin": "\\(", + "end": "\\)", + "patterns": [ + { + "include": "#expression" + } + ] + }, + "else-clause": { + "begin": "\\b(else)\\b", + "beginCaptures": { + "1": { + "name": "keyword.control.baml" + } + }, + "end": "(?<=\\})", + "patterns": [ + { + "include": "#if-expression" + }, + { + "include": "#imperative-block" + } + ] + }, + "raw-string-literal": { + "begin": "(#+)\"", + "end": "\"\\1", + "name": "string.quoted.raw.baml" + } + } +} diff --git a/typescript2/app-promptfiddle/syntaxes/jinja.tmLanguage.json b/typescript2/app-promptfiddle/syntaxes/jinja.tmLanguage.json new file mode 100644 index 0000000000..5e13694fd9 --- /dev/null +++ b/typescript2/app-promptfiddle/syntaxes/jinja.tmLanguage.json @@ -0,0 +1,345 @@ +{ + "name": "jinja", + "scopeName": "source.baml-jinja", + "comment": "Jinja Templates", + "foldingStartMarker": "({%\\s*(block|filter|for|if|macro|raw))", + "foldingStopMarker": "({%\\s*(endblock|endfilter|endfor|endif|endmacro|endraw)\\s*%})", + "patterns": [ + { + "begin": "({%)\\s*(raw)\\s*(%})", + "captures": { + "1": { + "name": "storage.type.jinja.delimiter.tag" + }, + "2": { + "name": "keyword.control.jinja" + }, + "3": { + "name": "storage.type.jinja.delimiter.tag" + } + }, + "end": "({%)\\s*(endraw)\\s*(%})", + "name": "comment.block.jinja.raw" + }, + { + "include": "#comments" + }, + { + "begin": "{{-?", + "captures": [ + { + "name": "storage.type.jinja.delimiter" + } + ], + "end": "-?}}", + "name": "variable.meta.scope.jinja", + "patterns": [ + { + "include": "#expression" + } + ] + }, + { + "begin": "{%-?", + "captures": [ + { + "name": "storage.type.jinja.delimiter" + } + ], + "end": "-?%}", + "name": "meta.scope.jinja.tag", + "patterns": [ + { + "include": "#expression" + } + ] + } + ], + "repository": { + "comments": { + "begin": "{#-?", + "captures": [ + { + "name": "storage.type.jinja.delimiter" + } + ], + "end": "-?#}", + "name": "comment.block.jinja", + "patterns": [ + { + "include": "#comments" + } + ] + }, + "escaped_char": { + "match": "\\\\x[0-9A-F]{2}", + "name": "constant.character.escape.hex.jinja" + }, + "escaped_unicode_char": { + "captures": { + "1": { + "name": "constant.character.escape.unicode.16-bit-hex.jinja" + }, + "2": { + "name": "constant.character.escape.unicode.32-bit-hex.jinja" + }, + "3": { + "name": "constant.character.escape.unicode.name.jinja" + } + }, + "match": "(\\\\U[0-9A-Fa-f]{8})|(\\\\u[0-9A-Fa-f]{4})|(\\\\N\\{[a-zA-Z ]+\\})" + }, + "expression": { + "patterns": [ + { + "captures": { + "1": { + "name": "keyword.control.jinja" + }, + "2": { + "name": "variable.other.jinja.block" + } + }, + "match": "\\s*\\b(block)\\s+([a-zA-Z_][a-zA-Z0-9_]*)\\b" + }, + { + "captures": { + "1": { + "name": "keyword.control.jinja" + }, + "2": { + "name": "variable.other.jinja.filter" + } + }, + "match": "\\s*\\b(filter)\\s+([a-zA-Z_][a-zA-Z0-9_]*)\\b" + }, + { + "captures": { + "1": { + "name": "keyword.control.jinja" + }, + "2": { + "name": "variable.other.jinja.test" + } + }, + "match": "\\s*\\b(is)\\s+([a-zA-Z_][a-zA-Z0-9_]*)\\b" + }, + { + "captures": { + "1": { + "name": "keyword.control.jinja" + } + }, + "match": "(?<=\\{\\%-|\\{\\%)\\s*\\b([a-zA-Z_][a-zA-Z0-9_]*)\\b(?!\\s*[,=])" + }, + { + "match": "\\b(and|else|if|in|import|not|or|recursive|with(out)?\\s+context)\\b", + "name": "keyword.control.jinja" + }, + { + "match": "\\b(true|false|none)\\b", + "name": "constant.language.jinja" + }, + { + "match": "\\b(loop|super|self|varargs|kwargs)\\b", + "name": "variable.language.jinja" + }, + { + "match": "[a-zA-Z_][a-zA-Z0-9_]*", + "name": "variable.other.jinja" + }, + { + "match": "(\\+|\\-|\\*\\*|\\*|//|/|%)", + "name": "keyword.operator.arithmetic.jinja" + }, + { + "captures": { + "1": { + "name": "punctuation.other.jinja" + }, + "2": { + "name": "variable.other.jinja.filter" + } + }, + "match": "(\\|)([a-zA-Z_][a-zA-Z0-9_]*)" + }, + { + "captures": { + "1": { + "name": "punctuation.other.jinja" + }, + "2": { + "name": "variable.other.jinja.attribute" + } + }, + "match": "(\\.)([a-zA-Z_][a-zA-Z0-9_]*)" + }, + { + "begin": "\\[", + "captures": [ + { + "name": "punctuation.other.jinja" + } + ], + "end": "\\]", + "patterns": [ + { + "include": "#expression" + } + ] + }, + { + "begin": "\\(", + "captures": [ + { + "name": "punctuation.other.jinja" + } + ], + "end": "\\)", + "patterns": [ + { + "include": "#expression" + } + ] + }, + { + "begin": "\\{", + "captures": [ + { + "name": "punctuation.other.jinja" + } + ], + "end": "\\}", + "patterns": [ + { + "include": "#expression" + } + ] + }, + { + "match": "(\\.|:|\\||,)", + "name": "punctuation.other.jinja" + }, + { + "match": "(==|<=|=>|<|>|!=)", + "name": "keyword.operator.comparison.jinja" + }, + { + "match": "=", + "name": "keyword.operator.assignment.jinja" + }, + { + "begin": "\"", + "beginCaptures": [ + { + "name": "punctuation.definition.string.begin.jinja" + } + ], + "end": "\"", + "endCaptures": [ + { + "name": "punctuation.definition.string.end.jinja" + } + ], + "name": "string.quoted.double.jinja", + "patterns": [ + { + "include": "#string" + } + ] + }, + { + "begin": "'", + "beginCaptures": [ + { + "name": "punctuation.definition.string.begin.jinja" + } + ], + "end": "'", + "endCaptures": [ + { + "name": "punctuation.definition.string.end.jinja" + } + ], + "name": "string.quoted.single.jinja", + "patterns": [ + { + "include": "#string" + } + ] + }, + { + "begin": "@/", + "beginCaptures": [ + { + "name": "punctuation.definition.regexp.begin.jinja" + } + ], + "end": "/", + "endCaptures": [ + { + "name": "punctuation.definition.regexp.end.jinja" + } + ], + "name": "string.regexp.jinja", + "patterns": [ + { + "include": "#simple_escapes" + } + ] + } + ] + }, + "simple_escapes": { + "captures": { + "1": { + "name": "constant.character.escape.newline.jinja" + }, + "2": { + "name": "constant.character.escape.backlash.jinja" + }, + "3": { + "name": "constant.character.escape.double-quote.jinja" + }, + "4": { + "name": "constant.character.escape.single-quote.jinja" + }, + "5": { + "name": "constant.character.escape.bell.jinja" + }, + "6": { + "name": "constant.character.escape.backspace.jinja" + }, + "7": { + "name": "constant.character.escape.formfeed.jinja" + }, + "8": { + "name": "constant.character.escape.linefeed.jinja" + }, + "9": { + "name": "constant.character.escape.return.jinja" + }, + "10": { + "name": "constant.character.escape.tab.jinja" + }, + "11": { + "name": "constant.character.escape.vertical-tab.jinja" + } + }, + "match": "(\\\\\\n)|(\\\\\\\\)|(\\\\\\\")|(\\\\')|(\\\\a)|(\\\\b)|(\\\\f)|(\\\\n)|(\\\\r)|(\\\\t)|(\\\\v)" + }, + "string": { + "patterns": [ + { + "include": "#simple_escapes" + }, + { + "include": "#escaped_char" + }, + { + "include": "#escaped_unicode_char" + } + ] + } + } +} diff --git a/typescript2/app-vscode-ext/syntaxes/baml.tmLanguage.json b/typescript2/app-vscode-ext/syntaxes/baml.tmLanguage.json index 7194bb4af0..e73917793e 100644 --- a/typescript2/app-vscode-ext/syntaxes/baml.tmLanguage.json +++ b/typescript2/app-vscode-ext/syntaxes/baml.tmLanguage.json @@ -1,1148 +1,1229 @@ { - "fileTypes": ["baml"], + "fileTypes": [ + "baml" + ], "name": "baml", "scopeName": "source.baml", "patterns": [ - { "include": "#comments" }, - { "include": "#class-block" }, - { "include": "#enum-block" }, - { "include": "#function-block" }, - { "include": "#client-block" }, - { "include": "#test-block" }, - { "include": "#generator-block" }, - { "include": "#retry-policy-block" }, - { "include": "#template-string" }, - { "include": "#type-alias" }, - { "include": "#top-level-let" }, - { "include": "#strings" }, - { "include": "#numbers" }, - { "include": "#operators" }, - { "include": "#punctuation" } + { + "include": "#comment" + }, + { + "include": "#item" + } ], "repository": { - "comments": { + "comment": { "patterns": [ + { + "name": "comment.line.baml", + "match": "//.*$" + }, { "name": "comment.block.baml", "begin": "/\\*", - "end": "\\*/", - "beginCaptures": { "0": { "name": "punctuation.definition.comment.begin.baml" } }, - "endCaptures": { "0": { "name": "punctuation.definition.comment.end.baml" } } + "end": "\\*/" + } + ] + }, + "item": { + "patterns": [ + { + "include": "#enum" }, { - "name": "comment.line.documentation.baml", - "match": "(///)(.*)$", - "captures": { - "1": { "name": "punctuation.definition.comment.baml" }, - "2": { "name": "comment.line.documentation.baml" } - } + "include": "#class" }, { - "name": "comment.line.double-slash.baml", - "match": "(//)(.*)$", - "captures": { - "1": { "name": "punctuation.definition.comment.baml" }, - "2": { "name": "comment.line.double-slash.baml" } - } + "include": "#function" + }, + { + "include": "#template-string" + }, + { + "include": "#type-alias" + }, + { + "include": "#client" + }, + { + "include": "#test" + }, + { + "include": "#generator" + }, + { + "include": "#retry-policy" } ] }, - - "class-block": { - "begin": "\\b(class)\\s+([A-Za-z_][A-Za-z0-9_-]*)\\s*(\\{)", + "client": { + "begin": "\\b(client)\\b(<([a-zA-Z_][a-zA-Z0-9_]*)>)?", "beginCaptures": { - "1": { "name": "keyword.declaration.class.baml" }, - "2": { "name": "entity.name.type.class.baml" }, - "3": { "name": "punctuation.definition.block.begin.baml" } - }, - "end": "\\}", - "endCaptures": { - "0": { "name": "punctuation.definition.block.end.baml" } + "1": { + "name": "keyword.declaration.baml" + }, + "3": { + "name": "entity.name.type.baml" + } }, - "name": "meta.class.baml", + "end": "(?<=\\})", "patterns": [ - { "include": "#comments" }, - { "include": "#block-attribute" }, - { "include": "#function-block" }, - { "include": "#type-alias" }, - { "include": "#field-definition" } + { + "include": "#comment" + }, + { + "match": "([a-zA-Z_][a-zA-Z0-9_]*)", + "captures": { + "1": { + "name": "entity.name.type.baml" + } + } + }, + { + "include": "#config-block" + } ] }, - - "enum-block": { - "begin": "\\b(enum)\\s+([A-Za-z_][A-Za-z0-9_-]*)\\s*(\\{)", + "test": { + "begin": "\\b(test)\\b", "beginCaptures": { - "1": { "name": "keyword.declaration.enum.baml" }, - "2": { "name": "entity.name.type.enum.baml" }, - "3": { "name": "punctuation.definition.block.begin.baml" } - }, - "end": "\\}", - "endCaptures": { - "0": { "name": "punctuation.definition.block.end.baml" } + "1": { + "name": "keyword.declaration.baml" + } }, - "name": "meta.enum.baml", + "end": "(?<=\\})", "patterns": [ - { "include": "#comments" }, - { "include": "#block-attribute" }, - { "include": "#enum-variant" } + { + "include": "#comment" + }, + { + "match": "([a-zA-Z_][a-zA-Z0-9_]*)", + "captures": { + "1": { + "name": "entity.name.type.baml" + } + } + }, + { + "include": "#config-block" + } ] }, - - "enum-variant": { - "begin": "^\\s*([A-Za-z_][A-Za-z0-9_-]*)(?=\\s|$|@|//)", + "generator": { + "begin": "\\b(generator)\\b", "beginCaptures": { - "1": { "name": "variable.other.enummember.baml" } + "1": { + "name": "keyword.declaration.baml" + } }, - "end": "$", + "end": "(?<=\\})", "patterns": [ - { "include": "#field-attribute" }, - { "include": "#comments" } + { + "include": "#comment" + }, + { + "match": "([a-zA-Z_][a-zA-Z0-9_]*)", + "captures": { + "1": { + "name": "entity.name.type.baml" + } + } + }, + { + "include": "#config-block" + } ] }, - - "function-block": { - "begin": "\\b(function)\\s+([A-Za-z_][A-Za-z0-9_-]*)\\s*(\\()", + "retry-policy": { + "begin": "\\b(retry_policy)\\b", "beginCaptures": { - "1": { "name": "keyword.declaration.function.baml" }, - "2": { "name": "entity.name.function.baml" }, - "3": { "name": "punctuation.definition.parameters.begin.baml" } + "1": { + "name": "keyword.declaration.baml" + } }, "end": "(?<=\\})", - "name": "meta.function.baml", "patterns": [ - { "include": "#comments" }, - { "include": "#function-params" }, - { "include": "#arrow-return-type" }, - { "include": "#function-body" } + { + "include": "#comment" + }, + { + "match": "([a-zA-Z_][a-zA-Z0-9_]*)", + "captures": { + "1": { + "name": "entity.name.type.baml" + } + } + }, + { + "include": "#config-block" + } + ] + }, + "config-block": { + "begin": "\\{", + "end": "\\}", + "patterns": [ + { + "include": "#comment" + }, + { + "include": "#type-builder" + }, + { + "include": "#config-block-entry" + } ] }, - - "function-params": { - "begin": "(?<=\\()", - "end": "\\)", - "endCaptures": { - "0": { "name": "punctuation.definition.parameters.end.baml" } + "type-builder": { + "begin": "\\b(type_builder)\\b", + "beginCaptures": { + "1": { + "name": "keyword.declaration.baml" + } }, + "end": "(?<=\\})", "patterns": [ - { "include": "#comments" }, - { "include": "#parameter" }, - { "include": "#namespace-path" }, - { "include": "#type-expression" }, { - "match": ",", - "name": "punctuation.separator.comma.baml" + "include": "#comment" + }, + { + "include": "#type-builder-block" } ] }, - - "parameter": { + "type-builder-block": { + "begin": "\\{", + "end": "\\}", "patterns": [ { - "comment": "self parameter", - "match": "\\b(self)\\b", - "captures": { - "1": { "name": "variable.language.self.baml" } - } + "include": "#comment" }, { - "comment": "Typed parameter: name: Type", - "match": "([A-Za-z_][A-Za-z0-9_-]*)\\s*(:)", + "match": "\\b(dynamic)\\b", "captures": { - "1": { "name": "variable.other.baml" }, - "2": { "name": "punctuation.separator.colon.baml" } + "1": { + "name": "keyword.declaration.baml" + } } }, { - "comment": "Untyped parameter: name after ( or , and before , or )", - "match": "(?<=[(,]\\s*)([A-Za-z_][A-Za-z0-9_-]*)(?=\\s*[,)])", - "captures": { - "1": { "name": "variable.other.baml" } - } + "include": "#item" } ] }, - - "arrow-return-type": { - "begin": "(->)", + "config-block-entry": { + "begin": "([a-zA-Z_][a-zA-Z0-9_]*)", "beginCaptures": { - "1": { "name": "keyword.operator.arrow.baml" } + "1": { + "name": "variable.other.property.baml" + } }, - "end": "(?=\\{)", + "end": "(?=\\})|$", "patterns": [ - { "include": "#comments" }, { - "match": "\\b(throws)\\b", - "name": "keyword.other.throws.baml" + "include": "#comment" + }, + { + "include": "#config-block" }, - { "include": "#namespace-path" }, - { "include": "#type-expression" } + { + "include": "#expression" + } ] }, - - "function-body": { - "begin": "\\{", + "type-alias": { + "begin": "\\b(type)\\b", "beginCaptures": { - "0": { "name": "punctuation.definition.block.begin.baml" } - }, - "end": "\\}", - "endCaptures": { - "0": { "name": "punctuation.definition.block.end.baml" } + "1": { + "name": "keyword.declaration.baml" + } }, - "name": "meta.function.body.baml", + "end": "(?=;)|$", "patterns": [ - { "include": "#comments" }, - { "include": "#block-attribute" }, - { "include": "#llm-function-config-field" }, - { "include": "#expression-body" } + { + "include": "#comment" + }, + { + "match": "([a-zA-Z_][a-zA-Z0-9_]*)", + "captures": { + "1": { + "name": "entity.name.type.baml" + } + } + }, + { + "include": "#type-expression" + } ] }, - - "llm-function-config-field": { - "comment": "Known config fields in LLM function bodies: client, prompt, retry_policy", - "begin": "^\\s*(client|prompt|retry_policy)\\b", + "enum": { + "begin": "\\b(enum)\\b", "beginCaptures": { - "1": { "name": "variable.other.property.baml" } + "1": { + "name": "keyword.declaration.baml" + } }, - "end": "$", + "end": "(?<=\\})", "patterns": [ - { "include": "#comments" }, - { "include": "#field-attribute" }, - { "include": "#config-value" } + { + "include": "#comment" + }, + { + "match": "([a-zA-Z_][a-zA-Z0-9_]*)", + "captures": { + "1": { + "name": "entity.name.type.baml" + } + } + }, + { + "include": "#enum-block" + } ] }, - - "expression-body": { + "enum-block": { + "begin": "\\{", + "end": "\\}", "patterns": [ - { "include": "#comments" }, - { "include": "#strings" }, - { "include": "#numbers" }, - { "include": "#match-block" }, - { "include": "#catch-block" }, - { "include": "#let-declaration" }, - { "include": "#keywords" }, - { "include": "#field-attribute" }, - { "include": "#namespace-path" }, - { "include": "#field-access" }, - { "include": "#object-field" }, - { "include": "#namespaced-object-literal" }, - { "include": "#object-literal" }, - { "include": "#nested-block" }, - { "include": "#generic-function-call" }, - { "include": "#function-call" }, - { "include": "#operators" }, - { "include": "#punctuation" }, - { "include": "#identifier" } + { + "include": "#comment" + }, + { + "include": "#attribute" + }, + { + "include": "#enum-variant" + } ] }, - - "match-block": { - "begin": "\\b(match)\\s*\\(", + "enum-variant": { + "begin": "([a-zA-Z_][a-zA-Z0-9_]*)", "beginCaptures": { - "1": { "name": "keyword.control.match.baml" } + "1": { + "name": "variable.other.baml" + } }, - "end": "(?<=\\})", + "end": "(?=@)|$", "patterns": [ - { "include": "#comments" }, - { "include": "#match-body" }, - { "include": "#expression-body" } + { + "include": "#comment" + }, + { + "include": "#attribute" + } ] }, - - "catch-block": { - "begin": "\\b(catch_all|catch)\\s*\\(", + "class": { + "begin": "\\b(class)\\b", "beginCaptures": { - "1": { "name": "keyword.control.baml" } + "1": { + "name": "keyword.declaration.baml" + } }, "end": "(?<=\\})", "patterns": [ - { "include": "#comments" }, - { "include": "#match-body" }, - { "include": "#expression-body" } + { + "include": "#comment" + }, + { + "match": "([a-zA-Z_][a-zA-Z0-9_]*)", + "captures": { + "1": { + "name": "entity.name.type.baml" + } + } + }, + { + "include": "#class-block" + } ] }, - - "match-body": { + "class-block": { "begin": "\\{", - "beginCaptures": { - "0": { "name": "punctuation.definition.block.begin.baml" } - }, "end": "\\}", - "endCaptures": { - "0": { "name": "punctuation.definition.block.end.baml" } - }, "patterns": [ - { "include": "#comments" }, - { "include": "#match-arm-typed" }, - { "include": "#expression-body" } + { + "include": "#comment" + }, + { + "include": "#attribute" + }, + { + "include": "#class-member" + } + ] + }, + "class-member": { + "patterns": [ + { + "include": "#function" + }, + { + "include": "#class-field" + } ] }, - - "match-arm-typed": { - "comment": "Typed match arm: variable: Type =>", - "begin": "([A-Za-z_][A-Za-z0-9_-]*)\\s*(:)(?!:)(?=.*=>)", + "class-field": { + "begin": "([a-zA-Z_][a-zA-Z0-9_]*)", "beginCaptures": { - "1": { "name": "variable.other.baml" }, - "2": { "name": "punctuation.separator.colon.baml" } - }, - "end": "(=>)", - "endCaptures": { - "1": { "name": "keyword.operator.fat-arrow.baml" } + "1": { + "name": "variable.other.property.baml" + } }, + "end": "(?=@)|$", "patterns": [ - { "include": "#comments" }, - { "include": "#namespace-path" }, - { "include": "#type-expression" } + { + "include": "#comment" + }, + { + "include": "#type-expression" + }, + { + "include": "#attribute" + } ] }, - - "nested-block": { - "begin": "\\{", + "attribute": { + "begin": "(@@?[a-zA-Z_][a-zA-Z0-9_]*)", "beginCaptures": { - "0": { "name": "punctuation.definition.block.begin.baml" } - }, - "end": "\\}", - "endCaptures": { - "0": { "name": "punctuation.definition.block.end.baml" } + "1": { + "name": "entity.other.attribute-name.baml" + } }, + "end": "(?<=\\))|(?![(\\s])", "patterns": [ - { "include": "#expression-body" } + { + "include": "#attribute-arguments" + } ] }, - - "client-block": { - "begin": "\\b(client)(?:(<)(llm)(>))?\\s+([A-Za-z_][A-Za-z0-9_-]*)\\s*(\\{)", + "attribute-arguments": { + "begin": "\\(", + "end": "\\)", + "patterns": [ + { + "include": "#expression" + }, + { + "match": "," + } + ] + }, + "function": { + "begin": "\\b(function)\\b", "beginCaptures": { - "1": { "name": "keyword.declaration.client.baml" }, - "2": { "name": "keyword.operator.baml" }, - "3": { "name": "support.type.primitive.baml" }, - "4": { "name": "keyword.operator.baml" }, - "5": { "name": "entity.name.type.struct.baml" }, - "6": { "name": "punctuation.definition.block.begin.baml" } + "1": { + "name": "keyword.declaration.baml" + } }, + "end": "(?<=\\})", + "patterns": [ + { + "include": "#comment" + }, + { + "match": "([a-zA-Z_][a-zA-Z0-9_]*)", + "captures": { + "1": { + "name": "entity.name.function.baml" + } + } + }, + { + "include": "#parameter-list" + }, + { + "include": "#return-type" + }, + { + "include": "#function-block" + } + ] + }, + "function-block": { + "begin": "\\{", "end": "\\}", - "endCaptures": { - "0": { "name": "punctuation.definition.block.end.baml" } - }, - "name": "meta.client.baml", "patterns": [ - { "include": "#comments" }, - { "include": "#config-contents" } + { + "include": "#comment" + }, + { + "include": "#llm-function-client" + }, + { + "include": "#llm-function-prompt" + }, + { + "include": "#statement" + } ] }, - - "test-block": { - "begin": "\\b(test)\\s+([A-Za-z_][A-Za-z0-9_-]*)(?:\\s*\\(\\s*\\))?\\s*(\\{)", + "llm-function-client": { + "begin": "\\b(client)\\b", "beginCaptures": { - "1": { "name": "keyword.declaration.test.baml" }, - "2": { "name": "entity.name.type.struct.baml" }, - "3": { "name": "punctuation.definition.block.begin.baml" } - }, - "end": "\\}", - "endCaptures": { - "0": { "name": "punctuation.definition.block.end.baml" } + "1": { + "name": "keyword.declaration.baml" + } }, - "name": "meta.test.baml", + "end": "$", "patterns": [ - { "include": "#comments" }, - { "include": "#config-contents" } + { + "include": "#comment" + }, + { + "include": "#expression" + } ] }, - - "generator-block": { - "begin": "\\b(generator)\\s+([A-Za-z_][A-Za-z0-9_-]*)\\s*(\\{)", + "llm-function-prompt": { + "begin": "\\b(prompt)\\b", "beginCaptures": { - "1": { "name": "keyword.declaration.generator.baml" }, - "2": { "name": "entity.name.type.struct.baml" }, - "3": { "name": "punctuation.definition.block.begin.baml" } - }, - "end": "\\}", - "endCaptures": { - "0": { "name": "punctuation.definition.block.end.baml" } + "1": { + "name": "keyword.declaration.baml" + } }, - "name": "meta.generator.baml", + "end": "(?<=#)", "patterns": [ - { "include": "#comments" }, - { "include": "#config-contents" } + { + "include": "#comment" + }, + { + "include": "#template-string-body" + } ] }, - - "retry-policy-block": { - "begin": "\\b(retry_policy)\\s+([A-Za-z_][A-Za-z0-9_-]*)\\s*(\\{)", + "template-string": { + "begin": "\\b(template_string)\\b", "beginCaptures": { - "1": { "name": "keyword.declaration.retry-policy.baml" }, - "2": { "name": "entity.name.type.struct.baml" }, - "3": { "name": "punctuation.definition.block.begin.baml" } + "1": { + "name": "keyword.declaration.baml" + } }, - "end": "\\}", + "patterns": [ + { + "include": "#comment" + }, + { + "match": "([a-zA-Z_][a-zA-Z0-9_]*)", + "captures": { + "1": { + "name": "entity.name.function.baml" + } + } + }, + { + "include": "#parameter-list" + }, + { + "include": "#template-string-body" + } + ], + "end": "(?<=#)" + }, + "template-string-body": { + "begin": "(#+)\"", + "beginCaptures": { + "0": { + "name": "string.quoted.raw.baml" + } + }, + "end": "\\1", "endCaptures": { - "0": { "name": "punctuation.definition.block.end.baml" } + "0": { + "name": "string.quoted.raw.baml" + } }, - "name": "meta.retry-policy.baml", + "contentName": "string.quoted.raw.baml", "patterns": [ - { "include": "#comments" }, - { "include": "#config-contents" } + { + "include": "#jinja-escapes" + } ] }, - - "template-string": { - "begin": "\\b(template_string)\\s+([A-Za-z_][A-Za-z0-9_-]*)", + "jinja-escapes": { + "patterns": [ + { + "include": "source.baml-jinja#comments" + }, + { + "begin": "{{-?", + "captures": { + "0": { + "name": "storage.type.jinja.delimiter" + } + }, + "end": "-?}}", + "name": "variable.meta.scope.jinja", + "patterns": [ + { + "include": "source.baml-jinja#expression" + } + ] + }, + { + "begin": "{%-?", + "captures": { + "0": { + "name": "storage.type.jinja.delimiter" + } + }, + "end": "-?%}", + "name": "meta.scope.jinja.tag", + "patterns": [ + { + "include": "source.baml-jinja#expression" + } + ] + } + ] + }, + "return-type": { + "begin": "->\\s*", + "end": "(?=\\{)", + "patterns": [ + { + "include": "#comment" + }, + { + "include": "#type-expression" + } + ] + }, + "parameter": { + "begin": "(self)|([a-zA-Z_][a-zA-Z0-9_]*)", "beginCaptures": { - "1": { "name": "keyword.declaration.template.baml" }, - "2": { "name": "entity.name.function.baml" } + "1": { + "name": "variable.language.self.baml" + }, + "2": { + "name": "variable.parameter.baml" + } }, - "end": "(?<=\"#)|(?<=\"##)|(?<=\"###)|(?<=\"####)|(?<=\"#####)", + "end": "(?=[,)])", "patterns": [ - { "include": "#comments" }, { - "match": "=", - "name": "keyword.operator.assignment.baml" + "include": "#comment" }, - { "include": "#template-params" }, - { "include": "#raw-string-5" }, - { "include": "#raw-string-4" }, - { "include": "#raw-string-3" }, - { "include": "#raw-string-2" }, - { "include": "#raw-string-1" } + { + "include": "#type-expression" + } ] }, - - "template-params": { + "parameter-list": { "begin": "\\(", - "beginCaptures": { - "0": { "name": "punctuation.definition.parameters.begin.baml" } - }, "end": "\\)", - "endCaptures": { - "0": { "name": "punctuation.definition.parameters.end.baml" } - }, "patterns": [ - { "include": "#comments" }, - { "include": "#parameter" }, { - "match": ",", - "name": "punctuation.separator.comma.baml" + "include": "#comment" + }, + { + "include": "#parameter" }, - { "include": "#namespace-path" }, - { "include": "#type-expression" } + { + "match": "," + } ] }, - - "type-alias": { - "begin": "\\b(type)\\s+([A-Za-z_][A-Za-z0-9_-]*)\\s*(=)", + "type-expression": { + "patterns": [ + { + "include": "#type-generic" + }, + { + "include": "#type-parenthesized" + }, + { + "include": "#literal" + }, + { + "include": "#type-namespaced" + } + ] + }, + "type-parenthesized": { + "begin": "\\(", + "end": "\\)", + "patterns": [ + { + "include": "#type-expression" + } + ] + }, + "type-generic": { + "begin": "(?:[a-zA-Z_][a-zA-Z0-9_]*\\.)*([a-zA-Z_][a-zA-Z0-9_]*)\\s*<", "beginCaptures": { - "1": { "name": "keyword.declaration.type.baml" }, - "2": { "name": "entity.name.type.baml" }, - "3": { "name": "keyword.operator.assignment.baml" } + "1": { + "name": "entity.name.type.baml" + } }, - "end": "(?=;|$|\\{|\\})", + "end": ">", "patterns": [ - { "include": "#comments" }, - { "include": "#namespace-path" }, - { "include": "#type-expression" } + { + "include": "#type-expression" + }, + { + "match": "," + } ] }, - - "top-level-let": { - "match": "\\b(let)\\s+([A-Za-z_][A-Za-z0-9_-]*)\\b", + "type-namespaced": { + "match": "(?:[a-zA-Z_][a-zA-Z0-9_]*\\.)*([a-zA-Z_][a-zA-Z0-9_]*)", "captures": { - "1": { "name": "keyword.declaration.let.baml" }, - "2": { "name": "variable.other.baml" } + "1": { + "name": "entity.name.type.baml" + } } }, - - "let-declaration": { - "comment": "Let statement with optional type: let name: Type = ...", - "begin": "\\b(let)\\s+([A-Za-z_][A-Za-z0-9_-]*)(?:\\s*(:))?", + "imperative-block": { + "begin": "\\{", + "end": "\\}", + "patterns": [ + { + "include": "#comment" + }, + { + "include": "#statement" + } + ] + }, + "return-statement": { + "begin": "\\b(return)\\b", "beginCaptures": { - "1": { "name": "keyword.declaration.let.baml" }, - "2": { "name": "variable.other.baml" }, - "3": { "name": "punctuation.separator.colon.baml" } + "1": { + "name": "keyword.control.baml" + } }, - "end": "(?=\\s*=)|(?=\\s*\\bin\\b)|(?=;)|$", + "end": ";|(?=\\})", "patterns": [ - { "include": "#comments" }, - { "include": "#namespace-path" }, - { "include": "#type-expression" } + { + "include": "#expression" + } ] }, - - "field-definition": { - "begin": "^\\s*(?!(?:function|class|enum|let|if|else|for|while|match|catch|return|break|continue|throw|watch|assert|dynamic|@@)\\b)([A-Za-z_][A-Za-z0-9_-]*)\\s*(:?)\\s*(?=\\S)", + "throw-expression": { + "begin": "\\b(throw)\\b", "beginCaptures": { - "1": { "name": "variable.other.property.baml" }, - "2": { "name": "punctuation.separator.colon.baml" } + "1": { + "name": "keyword.control.baml" + } }, - "end": "$", + "end": ";|(?=\\})", "patterns": [ - { "include": "#comments" }, - { "include": "#field-attribute" }, - { "include": "#namespace-path" }, - { "include": "#type-expression" } + { + "include": "#expression" + } ] }, - - "config-contents": { + "statement": { "patterns": [ - { "include": "#comments" }, - { "include": "#strings" }, - { "include": "#block-attribute" }, - { "include": "#type-builder-block" }, - { "include": "#config-block-field" }, - { "include": "#config-field" }, - { "include": "#config-value" } + { + "include": "#let-statement" + }, + { + "include": "#return-statement" + }, + { + "include": "#continue-statement" + }, + { + "include": "#break-statement" + }, + { + "include": "#for-loop" + }, + { + "include": "#while-loop" + }, + { + "include": "#expression" + } ] }, - - "config-block-field": { - "comment": "Config field with nested block: options { ... }, options: { ... }", - "begin": "^\\s*([A-Za-z_][A-Za-z0-9_-]*)(:?)\\s*(\\{)", + "continue-statement": { + "begin": "\\b(continue)\\b", "beginCaptures": { - "1": { "name": "variable.other.property.baml" }, - "2": { "name": "punctuation.separator.colon.baml" }, - "3": { "name": "punctuation.definition.block.begin.baml" } - }, - "end": "\\}", - "endCaptures": { - "0": { "name": "punctuation.definition.block.end.baml" } + "1": { + "name": "keyword.control.baml" + } }, - "patterns": [ - { "include": "#comments" }, - { "include": "#config-contents" } - ] + "end": ";|(?=\\})" }, - - "type-builder-block": { - "begin": "\\b(type_builder)\\s*(\\{)", + "break-statement": { + "begin": "\\b(break)\\b", "beginCaptures": { - "1": { "name": "keyword.declaration.type-builder.baml" }, - "2": { "name": "punctuation.definition.block.begin.baml" } + "1": { + "name": "keyword.control.baml" + } }, - "end": "\\}", - "endCaptures": { - "0": { "name": "punctuation.definition.block.end.baml" } + "end": ";|(?=\\})" + }, + "while-loop": { + "begin": "\\b(while)\\b", + "beginCaptures": { + "1": { + "name": "keyword.control.baml" + } }, + "end": "(?<=\\})", "patterns": [ - { "include": "#comments" }, - { "include": "#class-block" }, - { "include": "#enum-block" }, - { "include": "#type-alias" } + { + "include": "#imperative-block" + }, + { + "include": "#expression" + } ] }, - - "config-field": { - "begin": "^\\s*(?!(?:let|if|else|for|while|match|catch|return|break|continue|throw|watch|assert|function|class|enum|dynamic)\\b)([A-Za-z_][A-Za-z0-9_-]*)(:?)(?!\\s*[({.])(?=\\s+\\S)", + "for-loop": { + "begin": "\\b(for)\\b", "beginCaptures": { - "1": { "name": "variable.other.property.baml" }, - "2": { "name": "punctuation.separator.colon.baml" } + "1": { + "name": "keyword.control.baml" + } }, - "end": "$", + "end": "(?<=\\})", "patterns": [ - { "include": "#comments" }, - { "include": "#field-attribute" }, - { "include": "#config-value" } + { + "include": "#for-in-clause" + }, + { + "include": "#imperative-block" + }, + { + "include": "#statement" + } ] }, - - "config-value": { + "for-in-clause": { + "begin": "(let\\s+)?([a-zA-Z_][a-zA-Z0-9_]*)\\s+(in)\\s+", + "beginCaptures": { + "1": { + "name": "keyword.declaration.baml" + }, + "2": { + "name": "variable.other.baml" + }, + "3": { + "name": "keyword.control.baml" + } + }, + "end": "\\)", "patterns": [ - { "include": "#strings" }, - { "include": "#numbers" }, - { "include": "#namespace-path" }, - { "include": "#config-nested-map" }, - { "include": "#config-array" }, { - "match": "[A-Za-z_][A-Za-z0-9_./-]*", - "name": "string.unquoted.baml" + "include": "#expression" } ] }, - - "config-nested-map": { - "begin": "\\{", + "let-statement": { + "begin": "\\b(let)\\b", "beginCaptures": { - "0": { "name": "punctuation.definition.block.begin.baml" } - }, - "end": "\\}", - "endCaptures": { - "0": { "name": "punctuation.definition.block.end.baml" } + "1": { + "name": "keyword.declaration.baml" + } }, + "end": ";", "patterns": [ - { "include": "#comments" }, - { "include": "#config-contents" } + { + "match": "([a-zA-Z_][a-zA-Z0-9_]*)\\s*(?=[:=])", + "captures": { + "1": { + "name": "variable.other.baml" + } + } + }, + { + "include": "#let-type-annotation" + }, + { + "include": "#expression" + } ] }, - - "config-array": { - "begin": "\\[", - "beginCaptures": { - "0": { "name": "punctuation.definition.array.begin.baml" } - }, - "end": "\\]", - "endCaptures": { - "0": { "name": "punctuation.definition.array.end.baml" } - }, + "let-type-annotation": { + "begin": ":", + "end": "(?==)", "patterns": [ - { "include": "#comments" }, - { "include": "#config-value" }, { - "match": ",", - "name": "punctuation.separator.comma.baml" + "include": "#type-expression" } ] }, - - "type-expression": { + "expression": { "patterns": [ - { "include": "#strings" }, - { "include": "#numbers" }, { - "comment": "Function type: (params) -> ReturnType", - "begin": "(\\()", - "beginCaptures": { - "1": { "name": "punctuation.definition.parameters.begin.baml" } - }, - "end": "(?<=\\))", - "patterns": [ - { "include": "#comments" }, - { "include": "#fn-type-params" } - ] + "include": "#literal" }, { - "comment": "Arrow in function type", - "begin": "(->)", - "beginCaptures": { - "1": { "name": "keyword.operator.arrow.baml" } - }, - "end": "(?=[,)\\]}>|?]|\\[\\]|$)", - "patterns": [ - { "include": "#comments" }, - { "include": "#type-expression" } - ] + "include": "#throw-expression" }, { - "comment": "Generic type: map or TypeName", - "begin": "\\b(int|float|string|bool|image|audio|map|unknown|never|null)\\s*(<)", - "beginCaptures": { - "1": { "name": "support.type.primitive.baml" }, - "2": { "name": "punctuation.definition.typeparameters.begin.baml" } - }, - "end": ">", - "endCaptures": { - "0": { "name": "punctuation.definition.typeparameters.end.baml" } - }, - "patterns": [ - { "include": "#comments" }, - { "include": "#type-expression" }, - { "match": ",", "name": "punctuation.separator.comma.baml" } - ] + "include": "#if-expression" }, - { "include": "#namespaced-type" }, { - "comment": "User-defined generic type: MyType", - "begin": "\\b([A-Za-z_][A-Za-z0-9_]*)\\s*(<)", - "beginCaptures": { - "1": { "name": "entity.name.type.baml" }, - "2": { "name": "punctuation.definition.typeparameters.begin.baml" } - }, - "end": ">", - "endCaptures": { - "0": { "name": "punctuation.definition.typeparameters.end.baml" } - }, - "patterns": [ - { "include": "#comments" }, - { "include": "#type-expression" }, - { "match": ",", "name": "punctuation.separator.comma.baml" } - ] + "include": "#match-expression" }, { - "match": "\\b(int|float|string|bool|image|audio|map|unknown|never|null)\\b", - "name": "support.type.primitive.baml" + "include": "#catch-expression" }, { - "match": "\\[\\]", - "name": "punctuation.definition.array-type.baml" + "include": "#catch-all-expression" }, { - "match": "\\?", - "name": "keyword.operator.optional.baml" + "include": "#object-constructor-expression" }, { - "match": "\\|", - "name": "keyword.operator.union.baml" + "include": "#map-expression" }, { - "comment": "User-defined type reference in type position", - "match": "\\b([A-Za-z_][A-Za-z0-9_]*)\\b", - "name": "entity.name.type.baml" + "include": "#array-expression" + }, + { + "include": "#function-call-expression" + }, + { + "include": "#variable-expression" + }, + { + "include": "#property-access-expression" } ] }, - - "fn-type-params": { - "comment": "Parameters inside a function type: (name: Type, ...) closing paren", - "begin": "(?<=\\()", - "end": "\\)", - "endCaptures": { - "0": { "name": "punctuation.definition.parameters.end.baml" } - }, + "map-expression": { + "begin": "\\{", + "end": "\\}", "patterns": [ - { "include": "#comments" }, - { "include": "#parameter" }, { - "match": ",", - "name": "punctuation.separator.comma.baml" + "include": "#comment" }, - { "include": "#namespace-path" }, - { "include": "#type-expression" } - ] - }, - - "field-attribute": { - "begin": "(@)([A-Za-z_][A-Za-z0-9_.]*)", - "beginCaptures": { - "1": { "name": "entity.name.function.decorator.baml" }, - "2": { "name": "entity.name.function.decorator.baml" } - }, - "end": "(?<=\\))|(?=\\s+@)|(?=$)|(?=\\})", - "patterns": [ - { "include": "#attribute-args" } + { + "include": "#map-entry" + }, + { + "match": "," + } ] }, - - "block-attribute": { - "begin": "(@@)([A-Za-z_][A-Za-z0-9_.]*)", - "beginCaptures": { - "1": { "name": "entity.name.function.decorator.baml" }, - "2": { "name": "entity.name.function.decorator.baml" } - }, - "end": "(?<=\\))|(?=$)", + "map-entry": { + "end": "(?=[,}])", "patterns": [ - { "include": "#attribute-args" } + { + "include": "#map-entry-key" + }, + { + "include": "#map-entry-value" + } ] }, - - "attribute-args": { - "begin": "\\(", - "beginCaptures": { - "0": { "name": "punctuation.definition.arguments.begin.baml" } - }, - "end": "\\)", - "endCaptures": { - "0": { "name": "punctuation.definition.arguments.end.baml" } - }, + "map-entry-key": { + "end": "(?=:)", "patterns": [ - { "include": "#comments" }, - { "include": "#strings" }, - { "include": "#numbers" }, - { "include": "#jinja-expression" }, { - "match": ",", - "name": "punctuation.separator.comma.baml" + "include": "#string-literal" }, { - "match": "[A-Za-z_][A-Za-z0-9_-]*", - "name": "variable.other.baml" + "include": "#raw-string-literal" + }, + { + "match": "([a-zA-Z_][a-zA-Z0-9_]*)", + "captures": { + "1": { + "name": "variable.other.property.baml" + } + } } ] }, - - "jinja-expression": { - "begin": "\\{\\{", - "beginCaptures": { - "0": { "name": "punctuation.section.embedded.begin.baml" } - }, - "end": "\\}\\}", - "endCaptures": { - "0": { "name": "punctuation.section.embedded.end.baml" } - }, - "name": "meta.embedded.jinja.baml", - "contentName": "source.baml-jinja" + "map-entry-value": { + "begin": ":", + "end": "(?=[,}])", + "patterns": [ + { + "include": "#expression" + } + ] }, - - "namespaced-object-literal": { - "comment": "Namespaced constructor: ns.Type { field: value }", - "begin": "\\b([A-Za-z_][A-Za-z0-9_]*)(\\.)(?=(?:[A-Za-z_][A-Za-z0-9_]*\\.)*[A-Za-z_][A-Za-z0-9_]*\\s*\\{)", + "match-expression": { + "begin": "\\b(match)\\b", "beginCaptures": { - "1": { "name": "entity.name.namespace.baml" }, - "2": { "name": "punctuation.accessor.namespace.baml" } - }, - "end": "\\}", - "endCaptures": { - "0": { "name": "punctuation.definition.block.end.baml" } + "1": { + "name": "keyword.control.baml" + } }, + "end": "(?<=\\})", "patterns": [ { - "match": "(\\.)(?=[A-Za-z_])", - "name": "punctuation.accessor.namespace.baml" - }, - { - "comment": "Intermediate namespace segment", - "match": "[A-Za-z_][A-Za-z0-9_]*(?=\\.)", - "name": "entity.name.namespace.baml" + "include": "#match-scrutinee" }, { - "comment": "Type name followed by opening brace", - "begin": "([A-Za-z_][A-Za-z0-9_]*)\\s*(\\{)", - "beginCaptures": { - "1": { "name": "entity.name.type.baml" }, - "2": { "name": "punctuation.definition.block.begin.baml" } - }, - "end": "(?=\\})", - "patterns": [ - { "include": "#comments" }, - { "include": "#object-field" }, - { "include": "#expression-body" } - ] + "include": "#match-block" } ] }, - - "object-literal": { - "comment": "Constructor: TypeName { field: value }", - "begin": "\\b([A-Za-z_][A-Za-z0-9_]*)\\s*(\\{)", + "catch-expression": { + "begin": "\\b(catch)\\b", "beginCaptures": { - "1": { "name": "entity.name.type.baml" }, - "2": { "name": "punctuation.definition.block.begin.baml" } - }, - "end": "\\}", - "endCaptures": { - "0": { "name": "punctuation.definition.block.end.baml" } + "1": { + "name": "keyword.control.baml" + } }, - "patterns": [ - { "include": "#comments" }, - { "include": "#object-field" }, - { "include": "#expression-body" } - ] - }, - - "object-field": { - "comment": "Object field: name: value (not ::)", - "match": "([A-Za-z_][A-Za-z0-9_-]*)\\s*(:)(?!:)", - "captures": { - "1": { "name": "variable.other.property.baml" }, - "2": { "name": "punctuation.separator.colon.baml" } - } - }, - - "field-access": { + "end": "(?<=\\})", "patterns": [ { - "comment": "Method call: .method()", - "match": "(\\.)([A-Za-z_][A-Za-z0-9_-]*)(?=\\s*\\()", - "captures": { - "1": { "name": "punctuation.accessor.dot.baml" }, - "2": { "name": "entity.name.function.baml" } - } + "include": "#match-scrutinee" }, { - "comment": "Field access: .field", - "match": "(\\.)([A-Za-z_][A-Za-z0-9_-]*)", - "captures": { - "1": { "name": "punctuation.accessor.dot.baml" }, - "2": { "name": "variable.other.property.baml" } - } + "include": "#match-block" } ] }, - - "namespaced-type": { - "comment": "Namespaced type reference: ns.Type, a.b.Type, ns.Type", - "begin": "\\b([A-Za-z_][A-Za-z0-9_]*)(\\.)(?=[A-Za-z_])", + "catch-all-expression": { + "begin": "\\b(catch_all)\\b", "beginCaptures": { - "1": { "name": "entity.name.namespace.baml" }, - "2": { "name": "punctuation.accessor.namespace.baml" } + "1": { + "name": "keyword.control.baml" + } }, - "end": "(?<=[A-Za-z0-9_>])(?!\\.|<)", + "end": "(?<=\\})", "patterns": [ { - "match": "\\.", - "name": "punctuation.accessor.namespace.baml" - }, - { - "comment": "Intermediate namespace segment (followed by dot)", - "match": "[A-Za-z_][A-Za-z0-9_]*(?=\\.)", - "name": "entity.name.namespace.baml" + "include": "#match-scrutinee" }, { - "comment": "Generic type: ns.Type", - "begin": "([A-Za-z_][A-Za-z0-9_]*)\\s*(<)", - "beginCaptures": { - "1": { "name": "entity.name.type.baml" }, - "2": { "name": "punctuation.definition.typeparameters.begin.baml" } - }, - "end": ">", - "endCaptures": { - "0": { "name": "punctuation.definition.typeparameters.end.baml" } - }, - "patterns": [ - { "include": "#comments" }, - { "include": "#type-expression" }, - { "match": ",", "name": "punctuation.separator.comma.baml" } - ] - }, + "include": "#match-block" + } + ] + }, + "match-scrutinee": { + "begin": "\\(", + "end": "\\)", + "patterns": [ { - "comment": "Final type name", - "match": "[A-Za-z_][A-Za-z0-9_]*", - "name": "entity.name.type.baml" + "include": "#expression" } ] }, - - "namespace-path": { - "comment": "Dotted paths starting with env., baml., or root. are namespace accesses", - "begin": "\\b(env|baml|root)(?=\\.)", - "beginCaptures": { - "1": { "name": "entity.name.namespace.baml" } - }, - "end": "(?=[^A-Za-z0-9_.\\-<>,\\s]|$)(?)", + "match-block": { + "begin": "\\{", + "end": "\\}", "patterns": [ { - "match": "\\.", - "name": "punctuation.accessor.namespace.baml" + "include": "#comment" }, { - "comment": "Intermediate namespace segment (followed by another dot)", - "match": "[A-Za-z_][A-Za-z0-9_-]*(?=\\.)", - "name": "entity.name.namespace.baml" + "include": "#match-case-typed" }, { - "comment": "Generic function call: name()", - "begin": "([A-Za-z_][A-Za-z0-9_-]*)\\s*(<)", - "beginCaptures": { - "1": { "name": "entity.name.function.baml" }, - "2": { "name": "punctuation.definition.typeparameters.begin.baml" } - }, - "end": ">", - "endCaptures": { - "0": { "name": "punctuation.definition.typeparameters.end.baml" } - }, - "patterns": [ - { "include": "#comments" }, - { "include": "#type-expression" }, - { "match": ",", "name": "punctuation.separator.comma.baml" } - ] + "include": "#literal" }, { - "comment": "Final segment: function (followed by open paren)", - "match": "[A-Za-z_][A-Za-z0-9_-]*(?=\\s*\\()", - "name": "entity.name.function.baml" + "include": "#variable-expression" }, { - "comment": "Final segment: type", - "match": "[A-Za-z_][A-Za-z0-9_]*", - "name": "entity.name.type.baml" + "include": "#match-case-arrow" } ] }, - - "generic-function-call": { - "comment": "Generic function call: name()", - "begin": "\\b([A-Za-z_][A-Za-z0-9_-]*)(<)(?![-=])", + "match-case-typed": { + "begin": "([a-zA-Z_][a-zA-Z0-9_]*)\\s*:", "beginCaptures": { - "1": { "name": "entity.name.function.baml" }, - "2": { "name": "punctuation.definition.typeparameters.begin.baml" } - }, - "end": ">", - "endCaptures": { - "0": { "name": "punctuation.definition.typeparameters.end.baml" } + "1": { + "name": "variable.other.baml" + } }, + "end": "(?==>)", "patterns": [ - { "include": "#comments" }, - { "include": "#type-expression" }, - { "match": ",", "name": "punctuation.separator.comma.baml" } + { + "include": "#type-expression" + } ] }, - - "function-call": { - "match": "\\b([A-Za-z_][A-Za-z0-9_-]*)\\s*(?=\\()", - "captures": { - "1": { "name": "entity.name.function.baml" } - } - }, - - "keywords": { + "match-case-arrow": { + "begin": "=>", + "end": "(?<=\\}),?|,|(?=\\})", "patterns": [ { - "match": "\\b(self)\\b", - "name": "variable.language.self.baml" + "include": "#imperative-block" }, { - "match": "\\b(if|else|for|while|match|catch_all|catch|in)\\b", - "name": "keyword.control.baml" + "include": "#expression" + } + ] + }, + "property-access-expression": { + "match": "(?:[a-zA-Z_][a-zA-Z0-9_]*\\.?)*\\.([a-zA-Z_][a-zA-Z0-9_]*)", + "captures": { + "1": { + "name": "variable.other.property.baml" + } + } + }, + "variable-expression": { + "match": "(self)|([a-zA-Z_][a-zA-Z0-9_]*)", + "captures": { + "1": { + "name": "variable.language.baml" }, - { - "match": "\\b(let|watch)\\b", - "name": "keyword.declaration.baml" + "2": { + "name": "variable.other.baml" + } + } + }, + "function-call-expression": { + "begin": "\\.?([a-zA-Z_][a-zA-Z0-9_]*)\\s*(?:<(?:[a-zA-Z_][a-zA-Z0-9_]*\\.)*([a-zA-Z_][a-zA-Z0-9_]*)>)?\\s*\\(", + "beginCaptures": { + "1": { + "name": "entity.name.function.baml" }, + "2": { + "name": "entity.name.type.baml" + } + }, + "end": "\\)", + "patterns": [ { - "match": "\\b(return|break|continue|throw)\\b", - "name": "keyword.control.flow.baml" + "include": "#comment" }, { - "match": "\\b(instanceof|assert)\\b", - "name": "keyword.operator.baml" + "include": "#expression" }, { - "match": "\\b(env)\\b", - "name": "keyword.other.env.baml" + "match": "," + } + ] + }, + "array-expression": { + "begin": "\\[", + "end": "\\]", + "patterns": [ + { + "include": "#comment" }, { - "match": "\\b(dynamic)\\b", - "name": "keyword.other.dynamic.baml" + "include": "#expression" }, { - "match": "\\b(true|false|null)\\b", - "name": "constant.language.baml" + "match": "," } ] }, - - "strings": { - "patterns": [ - { "include": "#raw-string-5" }, - { "include": "#raw-string-4" }, - { "include": "#raw-string-3" }, - { "include": "#raw-string-2" }, - { "include": "#raw-string-1" }, - { "include": "#quoted-string" } - ] - }, - - "raw-string-5": { - "begin": "#####\"", - "beginCaptures": { "0": { "name": "punctuation.definition.string.begin.baml" } }, - "end": "\"#####", - "endCaptures": { "0": { "name": "punctuation.definition.string.end.baml" } }, - "name": "string.quoted.raw.baml", - "contentName": "string.quoted.block.baml.prompt", - "patterns": [ - { "include": "source.baml-jinja" } - ] - }, - - "raw-string-4": { - "begin": "####\"", - "beginCaptures": { "0": { "name": "punctuation.definition.string.begin.baml" } }, - "end": "\"####", - "endCaptures": { "0": { "name": "punctuation.definition.string.end.baml" } }, - "name": "string.quoted.raw.baml", - "contentName": "string.quoted.block.baml.prompt", - "patterns": [ - { "include": "source.baml-jinja" } - ] - }, - - "raw-string-3": { - "begin": "###\"", - "beginCaptures": { "0": { "name": "punctuation.definition.string.begin.baml" } }, - "end": "\"###", - "endCaptures": { "0": { "name": "punctuation.definition.string.end.baml" } }, - "name": "string.quoted.raw.baml", - "contentName": "string.quoted.block.baml.prompt", + "object-constructor-expression": { + "begin": "(?:[a-zA-Z_][a-zA-Z0-9_]*\\.)*([a-zA-Z_][a-zA-Z0-9_]*)\\s*\\{", + "beginCaptures": { + "1": { + "name": "entity.name.type.baml" + } + }, + "end": "\\}", "patterns": [ - { "include": "source.baml-jinja" } + { + "include": "#comment" + }, + { + "include": "#object-constructor-property" + } ] }, - - "raw-string-2": { - "begin": "##\"", - "beginCaptures": { "0": { "name": "punctuation.definition.string.begin.baml" } }, - "end": "\"##", - "endCaptures": { "0": { "name": "punctuation.definition.string.end.baml" } }, - "name": "string.quoted.raw.baml", - "contentName": "string.quoted.block.baml.prompt", + "object-constructor-property": { + "begin": "([a-zA-Z_][a-zA-Z0-9_]*)\\s*:", + "beginCaptures": { + "1": { + "name": "variable.other.property.baml" + } + }, + "end": "(?=[,}])", "patterns": [ - { "include": "source.baml-jinja" } + { + "include": "#expression" + } ] }, - - "raw-string-1": { - "begin": "#\"", - "beginCaptures": { "0": { "name": "punctuation.definition.string.begin.baml" } }, - "end": "\"#", - "endCaptures": { "0": { "name": "punctuation.definition.string.end.baml" } }, - "name": "string.quoted.raw.baml", - "contentName": "string.quoted.block.baml.prompt", - "patterns": [ - { "include": "source.baml-jinja" } - ] + "number-literal": { + "match": "\\b\\d+(\\.\\d+)?\\b", + "name": "constant.numeric.baml" }, - - "quoted-string": { + "string-literal": { "begin": "\"", - "beginCaptures": { "0": { "name": "punctuation.definition.string.begin.baml" } }, - "end": "\"|$", - "endCaptures": { "0": { "name": "punctuation.definition.string.end.baml" } }, - "name": "string.quoted.double.baml", - "patterns": [ - { - "match": "\\\\(?:[\"\\\\/bfnrt]|u[0-9A-Fa-f]{4})", - "name": "constant.character.escape.baml" - } - ] + "end": "\"", + "name": "string.quoted.double.baml" }, - - "numbers": { - "match": "(?=|&&|\\|\\||<<|>>)", - "name": "keyword.operator.comparison.baml" + "include": "#number-literal" }, { - "match": "(\\+=|-=|\\*=|/=|%=|&=|\\|=|\\^=|<<=|>>=)", - "name": "keyword.operator.assignment.compound.baml" + "include": "#string-literal" }, { - "match": "(->)", - "name": "keyword.operator.arrow.baml" + "include": "#raw-string-literal" }, { - "match": "(=>)", - "name": "keyword.operator.fat-arrow.baml" + "include": "#bool-literal" }, { - "match": "(=)(?!=)", - "name": "keyword.operator.assignment.baml" - }, + "include": "#null-literal" + } + ] + }, + "if-expression": { + "begin": "\\b(if)\\b", + "beginCaptures": { + "1": { + "name": "keyword.control.baml" + } + }, + "end": "(?<=\\})(?!\\s*else\\b)", + "patterns": [ { - "match": "(<|>)(?!=)", - "name": "keyword.operator.comparison.baml" + "include": "#if-condition" }, { - "match": "[+\\-*/%](?!=)", - "name": "keyword.operator.arithmetic.baml" + "include": "#else-clause" }, { - "match": "!(?!=)", - "name": "keyword.operator.logical.not.baml" - }, + "include": "#imperative-block" + } + ] + }, + "if-condition": { + "begin": "\\(", + "end": "\\)", + "patterns": [ { - "match": "\\.\\.\\.", - "name": "keyword.operator.spread.baml" + "include": "#expression" } ] }, - - "punctuation": { + "else-clause": { + "begin": "\\b(else)\\b", + "beginCaptures": { + "1": { + "name": "keyword.control.baml" + } + }, + "end": "(?<=\\})", "patterns": [ - { "match": ";", "name": "punctuation.terminator.baml" }, - { "match": "::", "name": "punctuation.accessor.namespace.baml" }, - { "match": ":", "name": "punctuation.separator.colon.baml" }, - { "match": ",", "name": "punctuation.separator.comma.baml" }, - { "match": "\\.", "name": "punctuation.accessor.dot.baml" } + { + "include": "#if-expression" + }, + { + "include": "#imperative-block" + } ] }, - - "identifier": { - "match": "\\b[A-Za-z_][A-Za-z0-9_-]*\\b", - "name": "variable.other.baml" + "raw-string-literal": { + "begin": "(#+)\"", + "end": "\"\\1", + "name": "string.quoted.raw.baml" } } } diff --git a/typescript2/package.json b/typescript2/package.json index 6ea6620243..eadea6cc30 100644 --- a/typescript2/package.json +++ b/typescript2/package.json @@ -18,6 +18,8 @@ }, "packageManager": "pnpm@9.12.0", "devDependencies": { + "js-yaml": "^4.1.1", + "tsx": "^4.21.0", "turbo": "^2.8.9", "typescript": "^5.7.0" } diff --git a/typescript2/pnpm-lock.yaml b/typescript2/pnpm-lock.yaml index 6e43795529..9ad34f991b 100644 --- a/typescript2/pnpm-lock.yaml +++ b/typescript2/pnpm-lock.yaml @@ -8,6 +8,12 @@ importers: .: devDependencies: + js-yaml: + specifier: ^4.1.1 + version: 4.1.1 + tsx: + specifier: ^4.21.0 + version: 4.21.0 turbo: specifier: ^2.8.9 version: 2.8.9 @@ -134,7 +140,7 @@ importers: version: 5.9.3 vitest: specifier: ^4.0.16 - version: 4.0.16(@types/node@20.19.27)(@vitest/browser-playwright@4.0.16)(jiti@2.6.1)(jsdom@25.0.1)(lightningcss@1.30.2)(msw@2.12.7(@types/node@20.19.27)(typescript@5.9.3)) + version: 4.0.16(@types/node@20.19.27)(@vitest/browser-playwright@4.0.16)(jiti@2.6.1)(jsdom@25.0.1)(lightningcss@1.30.2)(msw@2.12.7(@types/node@20.19.27)(typescript@5.9.3))(tsx@4.21.0) app-vscode-ext: dependencies: @@ -150,13 +156,13 @@ importers: version: 1.107.0 tsup: specifier: ^8.0.0 - version: 8.5.1(jiti@2.6.1)(postcss@8.5.6)(typescript@5.9.3) + version: 8.5.1(jiti@2.6.1)(postcss@8.5.6)(tsx@4.21.0)(typescript@5.9.3) typescript: specifier: ^5.7.0 version: 5.9.3 vitest: specifier: ^4.0.16 - version: 4.0.16(@types/node@22.19.3)(@vitest/browser-playwright@4.0.16)(jiti@2.6.1)(jsdom@25.0.1)(lightningcss@1.30.2)(msw@2.12.7(@types/node@22.19.3)(typescript@5.9.3)) + version: 4.0.16(@types/node@22.19.3)(@vitest/browser-playwright@4.0.16)(jiti@2.6.1)(jsdom@25.0.1)(lightningcss@1.30.2)(msw@2.12.7(@types/node@22.19.3)(typescript@5.9.3))(tsx@4.21.0) app-vscode-webview: dependencies: @@ -175,7 +181,7 @@ importers: devDependencies: '@tailwindcss/vite': specifier: ^4.1.18 - version: 4.1.18(vite@6.4.1(@types/node@22.19.3)(jiti@2.6.1)(lightningcss@1.30.2)) + version: 4.1.18(vite@6.4.1(@types/node@22.19.3)(jiti@2.6.1)(lightningcss@1.30.2)(tsx@4.21.0)) '@testing-library/jest-dom': specifier: ^6.6.3 version: 6.9.1 @@ -193,13 +199,13 @@ importers: version: 18.3.7(@types/react@18.3.27) '@vitejs/plugin-react': specifier: ^4.7.0 - version: 4.7.0(vite@6.4.1(@types/node@22.19.3)(jiti@2.6.1)(lightningcss@1.30.2)) + version: 4.7.0(vite@6.4.1(@types/node@22.19.3)(jiti@2.6.1)(lightningcss@1.30.2)(tsx@4.21.0)) '@vitest/browser': specifier: ^4.0.16 - version: 4.0.16(msw@2.12.7(@types/node@22.19.3)(typescript@5.9.3))(vite@6.4.1(@types/node@22.19.3)(jiti@2.6.1)(lightningcss@1.30.2))(vitest@4.0.16) + version: 4.0.16(msw@2.12.7(@types/node@22.19.3)(typescript@5.9.3))(vite@6.4.1(@types/node@22.19.3)(jiti@2.6.1)(lightningcss@1.30.2)(tsx@4.21.0))(vitest@4.0.16) '@vitest/browser-playwright': specifier: ^4.0.16 - version: 4.0.16(msw@2.12.7(@types/node@22.19.3)(typescript@5.9.3))(playwright@1.57.0)(vite@6.4.1(@types/node@22.19.3)(jiti@2.6.1)(lightningcss@1.30.2))(vitest@4.0.16) + version: 4.0.16(msw@2.12.7(@types/node@22.19.3)(typescript@5.9.3))(playwright@1.57.0)(vite@6.4.1(@types/node@22.19.3)(jiti@2.6.1)(lightningcss@1.30.2)(tsx@4.21.0))(vitest@4.0.16) jotai-devtools: specifier: ^0.13.0 version: 0.13.0(@types/react@18.3.27)(jotai@2.16.0(@babel/core@7.28.5)(@babel/template@7.27.2)(@types/react@18.3.27)(react@18.3.1))(react-dom@18.3.1(react@18.3.1))(react@18.3.1)(redux@5.0.1) @@ -217,10 +223,10 @@ importers: version: 5.9.3 vite: specifier: ^6.0.0 - version: 6.4.1(@types/node@22.19.3)(jiti@2.6.1)(lightningcss@1.30.2) + version: 6.4.1(@types/node@22.19.3)(jiti@2.6.1)(lightningcss@1.30.2)(tsx@4.21.0) vitest: specifier: ^4.0.16 - version: 4.0.16(@types/node@22.19.3)(@vitest/browser-playwright@4.0.16)(jiti@2.6.1)(jsdom@25.0.1)(lightningcss@1.30.2)(msw@2.12.7(@types/node@22.19.3)(typescript@5.9.3)) + version: 4.0.16(@types/node@22.19.3)(@vitest/browser-playwright@4.0.16)(jiti@2.6.1)(jsdom@25.0.1)(lightningcss@1.30.2)(msw@2.12.7(@types/node@22.19.3)(typescript@5.9.3))(tsx@4.21.0) pkg-playground: dependencies: @@ -264,7 +270,7 @@ importers: version: 5.9.3 vitest: specifier: ^3.0.0 - version: 3.2.4(@types/node@22.19.3)(jiti@2.6.1)(jsdom@25.0.1)(lightningcss@1.30.2)(msw@2.12.7(@types/node@22.19.3)(typescript@5.9.3)) + version: 3.2.4(@types/node@22.19.3)(jiti@2.6.1)(jsdom@25.0.1)(lightningcss@1.30.2)(msw@2.12.7(@types/node@22.19.3)(typescript@5.9.3))(tsx@4.21.0) packages: @@ -2363,11 +2369,12 @@ packages: glob@10.3.10: resolution: {integrity: sha512-fa46+tv1Ak0UPK1TOy/pZrIybNNt4HCv7SDzwyfiOZkvZLEbjsZkJBPtDHVshZjbecAoAGSC20MjLDG/qr679g==} engines: {node: '>=16 || 14 >=14.17'} + deprecated: Old versions of glob are not supported, and contain widely publicized security vulnerabilities, which have been fixed in the current version. Please update. Support for old versions may be purchased (at exorbitant rates) by contacting i@izs.me hasBin: true glob@7.2.3: resolution: {integrity: sha512-nFR0zLpU2YCaRxwoCJvL6UvCH2JFyFVIvwTLsIf21AuHlMskA1hhTdk+LlYJtOlYt9v6dvszD2BGRqBL+iQK9Q==} - deprecated: Glob versions prior to v9 are no longer supported + deprecated: Old versions of glob are not supported, and contain widely publicized security vulnerabilities, which have been fixed in the current version. Please update. Support for old versions may be purchased (at exorbitant rates) by contacting i@izs.me globals@13.24.0: resolution: {integrity: sha512-AhO5QUcj8llrbG09iWhPU2B204J1xnPeL8kQmVorSsy+Sjj1sk8gIyh6cUocGmH4L0UuhAJy+hJMRA4mgA4mFQ==} @@ -3588,6 +3595,11 @@ packages: typescript: optional: true + tsx@4.21.0: + resolution: {integrity: sha512-5C1sg4USs1lfG0GFb2RLXsdpXqBSEhAaA/0kPL01wxzpMqLILNxIxIOKiILz+cdg/pLnOUxFYOR5yhHU666wbw==} + engines: {node: '>=18.0.0'} + hasBin: true + turbo-darwin-64@2.8.9: resolution: {integrity: sha512-KnCw1ZI9KTnEAhdI9avZrnZ/z4wsM++flMA1w8s8PKOqi5daGpFV36qoPafg4S8TmYMe52JPWEoFr0L+lQ5JIw==} cpu: [x64] @@ -5003,12 +5015,12 @@ snapshots: postcss: 8.5.6 tailwindcss: 4.1.18 - '@tailwindcss/vite@4.1.18(vite@6.4.1(@types/node@22.19.3)(jiti@2.6.1)(lightningcss@1.30.2))': + '@tailwindcss/vite@4.1.18(vite@6.4.1(@types/node@22.19.3)(jiti@2.6.1)(lightningcss@1.30.2)(tsx@4.21.0))': dependencies: '@tailwindcss/node': 4.1.18 '@tailwindcss/oxide': 4.1.18 tailwindcss: 4.1.18 - vite: 6.4.1(@types/node@22.19.3)(jiti@2.6.1)(lightningcss@1.30.2) + vite: 6.4.1(@types/node@22.19.3)(jiti@2.6.1)(lightningcss@1.30.2)(tsx@4.21.0) '@testing-library/dom@10.4.1': dependencies: @@ -5268,7 +5280,7 @@ snapshots: '@unrs/resolver-binding-win32-x64-msvc@1.11.1': optional: true - '@vitejs/plugin-react@4.7.0(vite@6.4.1(@types/node@22.19.3)(jiti@2.6.1)(lightningcss@1.30.2))': + '@vitejs/plugin-react@4.7.0(vite@6.4.1(@types/node@22.19.3)(jiti@2.6.1)(lightningcss@1.30.2)(tsx@4.21.0))': dependencies: '@babel/core': 7.28.5 '@babel/plugin-transform-react-jsx-self': 7.27.1(@babel/core@7.28.5) @@ -5276,17 +5288,17 @@ snapshots: '@rolldown/pluginutils': 1.0.0-beta.27 '@types/babel__core': 7.20.5 react-refresh: 0.17.0 - vite: 6.4.1(@types/node@22.19.3)(jiti@2.6.1)(lightningcss@1.30.2) + vite: 6.4.1(@types/node@22.19.3)(jiti@2.6.1)(lightningcss@1.30.2)(tsx@4.21.0) transitivePeerDependencies: - supports-color - '@vitest/browser-playwright@4.0.16(msw@2.12.7(@types/node@20.19.27)(typescript@5.9.3))(playwright@1.57.0)(vite@7.3.0(@types/node@20.19.27)(jiti@2.6.1)(lightningcss@1.30.2))(vitest@4.0.16)': + '@vitest/browser-playwright@4.0.16(msw@2.12.7(@types/node@20.19.27)(typescript@5.9.3))(playwright@1.57.0)(vite@7.3.0(@types/node@20.19.27)(jiti@2.6.1)(lightningcss@1.30.2)(tsx@4.21.0))(vitest@4.0.16)': dependencies: - '@vitest/browser': 4.0.16(msw@2.12.7(@types/node@20.19.27)(typescript@5.9.3))(vite@7.3.0(@types/node@20.19.27)(jiti@2.6.1)(lightningcss@1.30.2))(vitest@4.0.16) - '@vitest/mocker': 4.0.16(msw@2.12.7(@types/node@20.19.27)(typescript@5.9.3))(vite@7.3.0(@types/node@20.19.27)(jiti@2.6.1)(lightningcss@1.30.2)) + '@vitest/browser': 4.0.16(msw@2.12.7(@types/node@20.19.27)(typescript@5.9.3))(vite@7.3.0(@types/node@20.19.27)(jiti@2.6.1)(lightningcss@1.30.2)(tsx@4.21.0))(vitest@4.0.16) + '@vitest/mocker': 4.0.16(msw@2.12.7(@types/node@20.19.27)(typescript@5.9.3))(vite@7.3.0(@types/node@20.19.27)(jiti@2.6.1)(lightningcss@1.30.2)(tsx@4.21.0)) playwright: 1.57.0 tinyrainbow: 3.0.3 - vitest: 4.0.16(@types/node@20.19.27)(@vitest/browser-playwright@4.0.16)(jiti@2.6.1)(jsdom@25.0.1)(lightningcss@1.30.2)(msw@2.12.7(@types/node@20.19.27)(typescript@5.9.3)) + vitest: 4.0.16(@types/node@20.19.27)(@vitest/browser-playwright@4.0.16)(jiti@2.6.1)(jsdom@25.0.1)(lightningcss@1.30.2)(msw@2.12.7(@types/node@20.19.27)(typescript@5.9.3))(tsx@4.21.0) transitivePeerDependencies: - bufferutil - msw @@ -5294,26 +5306,26 @@ snapshots: - vite optional: true - '@vitest/browser-playwright@4.0.16(msw@2.12.7(@types/node@22.19.3)(typescript@5.9.3))(playwright@1.57.0)(vite@6.4.1(@types/node@22.19.3)(jiti@2.6.1)(lightningcss@1.30.2))(vitest@4.0.16)': + '@vitest/browser-playwright@4.0.16(msw@2.12.7(@types/node@22.19.3)(typescript@5.9.3))(playwright@1.57.0)(vite@6.4.1(@types/node@22.19.3)(jiti@2.6.1)(lightningcss@1.30.2)(tsx@4.21.0))(vitest@4.0.16)': dependencies: - '@vitest/browser': 4.0.16(msw@2.12.7(@types/node@22.19.3)(typescript@5.9.3))(vite@6.4.1(@types/node@22.19.3)(jiti@2.6.1)(lightningcss@1.30.2))(vitest@4.0.16) - '@vitest/mocker': 4.0.16(msw@2.12.7(@types/node@22.19.3)(typescript@5.9.3))(vite@6.4.1(@types/node@22.19.3)(jiti@2.6.1)(lightningcss@1.30.2)) + '@vitest/browser': 4.0.16(msw@2.12.7(@types/node@22.19.3)(typescript@5.9.3))(vite@6.4.1(@types/node@22.19.3)(jiti@2.6.1)(lightningcss@1.30.2)(tsx@4.21.0))(vitest@4.0.16) + '@vitest/mocker': 4.0.16(msw@2.12.7(@types/node@22.19.3)(typescript@5.9.3))(vite@6.4.1(@types/node@22.19.3)(jiti@2.6.1)(lightningcss@1.30.2)(tsx@4.21.0)) playwright: 1.57.0 tinyrainbow: 3.0.3 - vitest: 4.0.16(@types/node@22.19.3)(@vitest/browser-playwright@4.0.16)(jiti@2.6.1)(jsdom@25.0.1)(lightningcss@1.30.2)(msw@2.12.7(@types/node@22.19.3)(typescript@5.9.3)) + vitest: 4.0.16(@types/node@22.19.3)(@vitest/browser-playwright@4.0.16)(jiti@2.6.1)(jsdom@25.0.1)(lightningcss@1.30.2)(msw@2.12.7(@types/node@22.19.3)(typescript@5.9.3))(tsx@4.21.0) transitivePeerDependencies: - bufferutil - msw - utf-8-validate - vite - '@vitest/browser-playwright@4.0.16(msw@2.12.7(@types/node@22.19.3)(typescript@5.9.3))(playwright@1.57.0)(vite@7.3.0(@types/node@22.19.3)(jiti@2.6.1)(lightningcss@1.30.2))(vitest@4.0.16)': + '@vitest/browser-playwright@4.0.16(msw@2.12.7(@types/node@22.19.3)(typescript@5.9.3))(playwright@1.57.0)(vite@7.3.0(@types/node@22.19.3)(jiti@2.6.1)(lightningcss@1.30.2)(tsx@4.21.0))(vitest@4.0.16)': dependencies: - '@vitest/browser': 4.0.16(msw@2.12.7(@types/node@22.19.3)(typescript@5.9.3))(vite@7.3.0(@types/node@22.19.3)(jiti@2.6.1)(lightningcss@1.30.2))(vitest@4.0.16) - '@vitest/mocker': 4.0.16(msw@2.12.7(@types/node@22.19.3)(typescript@5.9.3))(vite@7.3.0(@types/node@22.19.3)(jiti@2.6.1)(lightningcss@1.30.2)) + '@vitest/browser': 4.0.16(msw@2.12.7(@types/node@22.19.3)(typescript@5.9.3))(vite@7.3.0(@types/node@22.19.3)(jiti@2.6.1)(lightningcss@1.30.2)(tsx@4.21.0))(vitest@4.0.16) + '@vitest/mocker': 4.0.16(msw@2.12.7(@types/node@22.19.3)(typescript@5.9.3))(vite@7.3.0(@types/node@22.19.3)(jiti@2.6.1)(lightningcss@1.30.2)(tsx@4.21.0)) playwright: 1.57.0 tinyrainbow: 3.0.3 - vitest: 4.0.16(@types/node@22.19.3)(@vitest/browser-playwright@4.0.16)(jiti@2.6.1)(jsdom@25.0.1)(lightningcss@1.30.2)(msw@2.12.7(@types/node@22.19.3)(typescript@5.9.3)) + vitest: 4.0.16(@types/node@22.19.3)(@vitest/browser-playwright@4.0.16)(jiti@2.6.1)(jsdom@25.0.1)(lightningcss@1.30.2)(msw@2.12.7(@types/node@22.19.3)(typescript@5.9.3))(tsx@4.21.0) transitivePeerDependencies: - bufferutil - msw @@ -5321,16 +5333,16 @@ snapshots: - vite optional: true - '@vitest/browser@4.0.16(msw@2.12.7(@types/node@20.19.27)(typescript@5.9.3))(vite@7.3.0(@types/node@20.19.27)(jiti@2.6.1)(lightningcss@1.30.2))(vitest@4.0.16)': + '@vitest/browser@4.0.16(msw@2.12.7(@types/node@20.19.27)(typescript@5.9.3))(vite@7.3.0(@types/node@20.19.27)(jiti@2.6.1)(lightningcss@1.30.2)(tsx@4.21.0))(vitest@4.0.16)': dependencies: - '@vitest/mocker': 4.0.16(msw@2.12.7(@types/node@20.19.27)(typescript@5.9.3))(vite@7.3.0(@types/node@20.19.27)(jiti@2.6.1)(lightningcss@1.30.2)) + '@vitest/mocker': 4.0.16(msw@2.12.7(@types/node@20.19.27)(typescript@5.9.3))(vite@7.3.0(@types/node@20.19.27)(jiti@2.6.1)(lightningcss@1.30.2)(tsx@4.21.0)) '@vitest/utils': 4.0.16 magic-string: 0.30.21 pixelmatch: 7.1.0 pngjs: 7.0.0 sirv: 3.0.2 tinyrainbow: 3.0.3 - vitest: 4.0.16(@types/node@20.19.27)(@vitest/browser-playwright@4.0.16)(jiti@2.6.1)(jsdom@25.0.1)(lightningcss@1.30.2)(msw@2.12.7(@types/node@20.19.27)(typescript@5.9.3)) + vitest: 4.0.16(@types/node@20.19.27)(@vitest/browser-playwright@4.0.16)(jiti@2.6.1)(jsdom@25.0.1)(lightningcss@1.30.2)(msw@2.12.7(@types/node@20.19.27)(typescript@5.9.3))(tsx@4.21.0) ws: 8.18.3 transitivePeerDependencies: - bufferutil @@ -5339,16 +5351,16 @@ snapshots: - vite optional: true - '@vitest/browser@4.0.16(msw@2.12.7(@types/node@22.19.3)(typescript@5.9.3))(vite@6.4.1(@types/node@22.19.3)(jiti@2.6.1)(lightningcss@1.30.2))(vitest@4.0.16)': + '@vitest/browser@4.0.16(msw@2.12.7(@types/node@22.19.3)(typescript@5.9.3))(vite@6.4.1(@types/node@22.19.3)(jiti@2.6.1)(lightningcss@1.30.2)(tsx@4.21.0))(vitest@4.0.16)': dependencies: - '@vitest/mocker': 4.0.16(msw@2.12.7(@types/node@22.19.3)(typescript@5.9.3))(vite@6.4.1(@types/node@22.19.3)(jiti@2.6.1)(lightningcss@1.30.2)) + '@vitest/mocker': 4.0.16(msw@2.12.7(@types/node@22.19.3)(typescript@5.9.3))(vite@6.4.1(@types/node@22.19.3)(jiti@2.6.1)(lightningcss@1.30.2)(tsx@4.21.0)) '@vitest/utils': 4.0.16 magic-string: 0.30.21 pixelmatch: 7.1.0 pngjs: 7.0.0 sirv: 3.0.2 tinyrainbow: 3.0.3 - vitest: 4.0.16(@types/node@22.19.3)(@vitest/browser-playwright@4.0.16)(jiti@2.6.1)(jsdom@25.0.1)(lightningcss@1.30.2)(msw@2.12.7(@types/node@22.19.3)(typescript@5.9.3)) + vitest: 4.0.16(@types/node@22.19.3)(@vitest/browser-playwright@4.0.16)(jiti@2.6.1)(jsdom@25.0.1)(lightningcss@1.30.2)(msw@2.12.7(@types/node@22.19.3)(typescript@5.9.3))(tsx@4.21.0) ws: 8.18.3 transitivePeerDependencies: - bufferutil @@ -5356,16 +5368,16 @@ snapshots: - utf-8-validate - vite - '@vitest/browser@4.0.16(msw@2.12.7(@types/node@22.19.3)(typescript@5.9.3))(vite@7.3.0(@types/node@22.19.3)(jiti@2.6.1)(lightningcss@1.30.2))(vitest@4.0.16)': + '@vitest/browser@4.0.16(msw@2.12.7(@types/node@22.19.3)(typescript@5.9.3))(vite@7.3.0(@types/node@22.19.3)(jiti@2.6.1)(lightningcss@1.30.2)(tsx@4.21.0))(vitest@4.0.16)': dependencies: - '@vitest/mocker': 4.0.16(msw@2.12.7(@types/node@22.19.3)(typescript@5.9.3))(vite@7.3.0(@types/node@22.19.3)(jiti@2.6.1)(lightningcss@1.30.2)) + '@vitest/mocker': 4.0.16(msw@2.12.7(@types/node@22.19.3)(typescript@5.9.3))(vite@7.3.0(@types/node@22.19.3)(jiti@2.6.1)(lightningcss@1.30.2)(tsx@4.21.0)) '@vitest/utils': 4.0.16 magic-string: 0.30.21 pixelmatch: 7.1.0 pngjs: 7.0.0 sirv: 3.0.2 tinyrainbow: 3.0.3 - vitest: 4.0.16(@types/node@22.19.3)(@vitest/browser-playwright@4.0.16)(jiti@2.6.1)(jsdom@25.0.1)(lightningcss@1.30.2)(msw@2.12.7(@types/node@22.19.3)(typescript@5.9.3)) + vitest: 4.0.16(@types/node@22.19.3)(@vitest/browser-playwright@4.0.16)(jiti@2.6.1)(jsdom@25.0.1)(lightningcss@1.30.2)(msw@2.12.7(@types/node@22.19.3)(typescript@5.9.3))(tsx@4.21.0) ws: 8.18.3 transitivePeerDependencies: - bufferutil @@ -5391,41 +5403,41 @@ snapshots: chai: 6.2.2 tinyrainbow: 3.0.3 - '@vitest/mocker@3.2.4(msw@2.12.7(@types/node@22.19.3)(typescript@5.9.3))(vite@6.4.1(@types/node@22.19.3)(jiti@2.6.1)(lightningcss@1.30.2))': + '@vitest/mocker@3.2.4(msw@2.12.7(@types/node@22.19.3)(typescript@5.9.3))(vite@6.4.1(@types/node@22.19.3)(jiti@2.6.1)(lightningcss@1.30.2)(tsx@4.21.0))': dependencies: '@vitest/spy': 3.2.4 estree-walker: 3.0.3 magic-string: 0.30.21 optionalDependencies: msw: 2.12.7(@types/node@22.19.3)(typescript@5.9.3) - vite: 6.4.1(@types/node@22.19.3)(jiti@2.6.1)(lightningcss@1.30.2) + vite: 6.4.1(@types/node@22.19.3)(jiti@2.6.1)(lightningcss@1.30.2)(tsx@4.21.0) - '@vitest/mocker@4.0.16(msw@2.12.7(@types/node@20.19.27)(typescript@5.9.3))(vite@7.3.0(@types/node@20.19.27)(jiti@2.6.1)(lightningcss@1.30.2))': + '@vitest/mocker@4.0.16(msw@2.12.7(@types/node@20.19.27)(typescript@5.9.3))(vite@7.3.0(@types/node@20.19.27)(jiti@2.6.1)(lightningcss@1.30.2)(tsx@4.21.0))': dependencies: '@vitest/spy': 4.0.16 estree-walker: 3.0.3 magic-string: 0.30.21 optionalDependencies: msw: 2.12.7(@types/node@20.19.27)(typescript@5.9.3) - vite: 7.3.0(@types/node@20.19.27)(jiti@2.6.1)(lightningcss@1.30.2) + vite: 7.3.0(@types/node@20.19.27)(jiti@2.6.1)(lightningcss@1.30.2)(tsx@4.21.0) - '@vitest/mocker@4.0.16(msw@2.12.7(@types/node@22.19.3)(typescript@5.9.3))(vite@6.4.1(@types/node@22.19.3)(jiti@2.6.1)(lightningcss@1.30.2))': + '@vitest/mocker@4.0.16(msw@2.12.7(@types/node@22.19.3)(typescript@5.9.3))(vite@6.4.1(@types/node@22.19.3)(jiti@2.6.1)(lightningcss@1.30.2)(tsx@4.21.0))': dependencies: '@vitest/spy': 4.0.16 estree-walker: 3.0.3 magic-string: 0.30.21 optionalDependencies: msw: 2.12.7(@types/node@22.19.3)(typescript@5.9.3) - vite: 6.4.1(@types/node@22.19.3)(jiti@2.6.1)(lightningcss@1.30.2) + vite: 6.4.1(@types/node@22.19.3)(jiti@2.6.1)(lightningcss@1.30.2)(tsx@4.21.0) - '@vitest/mocker@4.0.16(msw@2.12.7(@types/node@22.19.3)(typescript@5.9.3))(vite@7.3.0(@types/node@22.19.3)(jiti@2.6.1)(lightningcss@1.30.2))': + '@vitest/mocker@4.0.16(msw@2.12.7(@types/node@22.19.3)(typescript@5.9.3))(vite@7.3.0(@types/node@22.19.3)(jiti@2.6.1)(lightningcss@1.30.2)(tsx@4.21.0))': dependencies: '@vitest/spy': 4.0.16 estree-walker: 3.0.3 magic-string: 0.30.21 optionalDependencies: msw: 2.12.7(@types/node@22.19.3)(typescript@5.9.3) - vite: 7.3.0(@types/node@22.19.3)(jiti@2.6.1)(lightningcss@1.30.2) + vite: 7.3.0(@types/node@22.19.3)(jiti@2.6.1)(lightningcss@1.30.2)(tsx@4.21.0) '@vitest/pretty-format@3.2.4': dependencies: @@ -6029,8 +6041,8 @@ snapshots: '@typescript-eslint/parser': 8.50.1(eslint@8.57.1)(typescript@5.9.3) eslint: 8.57.1 eslint-import-resolver-node: 0.3.9 - eslint-import-resolver-typescript: 3.10.1(eslint-plugin-import@2.32.0)(eslint@8.57.1) - eslint-plugin-import: 2.32.0(@typescript-eslint/parser@8.50.1(eslint@8.57.1)(typescript@5.9.3))(eslint-import-resolver-typescript@3.10.1)(eslint@8.57.1) + eslint-import-resolver-typescript: 3.10.1(eslint-plugin-import@2.32.0(@typescript-eslint/parser@8.50.1(eslint@8.57.1)(typescript@5.9.3))(eslint@8.57.1))(eslint@8.57.1) + eslint-plugin-import: 2.32.0(@typescript-eslint/parser@8.50.1(eslint@8.57.1)(typescript@5.9.3))(eslint-import-resolver-typescript@3.10.1(eslint-plugin-import@2.32.0(@typescript-eslint/parser@8.50.1(eslint@8.57.1)(typescript@5.9.3))(eslint@8.57.1))(eslint@8.57.1))(eslint@8.57.1) eslint-plugin-jsx-a11y: 6.10.2(eslint@8.57.1) eslint-plugin-react: 7.37.5(eslint@8.57.1) eslint-plugin-react-hooks: 5.0.0-canary-7118f5dd7-20230705(eslint@8.57.1) @@ -6049,7 +6061,7 @@ snapshots: transitivePeerDependencies: - supports-color - eslint-import-resolver-typescript@3.10.1(eslint-plugin-import@2.32.0)(eslint@8.57.1): + eslint-import-resolver-typescript@3.10.1(eslint-plugin-import@2.32.0(@typescript-eslint/parser@8.50.1(eslint@8.57.1)(typescript@5.9.3))(eslint@8.57.1))(eslint@8.57.1): dependencies: '@nolyfill/is-core-module': 1.0.39 debug: 4.4.3 @@ -6060,22 +6072,22 @@ snapshots: tinyglobby: 0.2.15 unrs-resolver: 1.11.1 optionalDependencies: - eslint-plugin-import: 2.32.0(@typescript-eslint/parser@8.50.1(eslint@8.57.1)(typescript@5.9.3))(eslint-import-resolver-typescript@3.10.1)(eslint@8.57.1) + eslint-plugin-import: 2.32.0(@typescript-eslint/parser@8.50.1(eslint@8.57.1)(typescript@5.9.3))(eslint-import-resolver-typescript@3.10.1(eslint-plugin-import@2.32.0(@typescript-eslint/parser@8.50.1(eslint@8.57.1)(typescript@5.9.3))(eslint@8.57.1))(eslint@8.57.1))(eslint@8.57.1) transitivePeerDependencies: - supports-color - eslint-module-utils@2.12.1(@typescript-eslint/parser@8.50.1(eslint@8.57.1)(typescript@5.9.3))(eslint-import-resolver-node@0.3.9)(eslint-import-resolver-typescript@3.10.1)(eslint@8.57.1): + eslint-module-utils@2.12.1(@typescript-eslint/parser@8.50.1(eslint@8.57.1)(typescript@5.9.3))(eslint-import-resolver-node@0.3.9)(eslint-import-resolver-typescript@3.10.1(eslint-plugin-import@2.32.0(@typescript-eslint/parser@8.50.1(eslint@8.57.1)(typescript@5.9.3))(eslint@8.57.1))(eslint@8.57.1))(eslint@8.57.1): dependencies: debug: 3.2.7 optionalDependencies: '@typescript-eslint/parser': 8.50.1(eslint@8.57.1)(typescript@5.9.3) eslint: 8.57.1 eslint-import-resolver-node: 0.3.9 - eslint-import-resolver-typescript: 3.10.1(eslint-plugin-import@2.32.0)(eslint@8.57.1) + eslint-import-resolver-typescript: 3.10.1(eslint-plugin-import@2.32.0(@typescript-eslint/parser@8.50.1(eslint@8.57.1)(typescript@5.9.3))(eslint@8.57.1))(eslint@8.57.1) transitivePeerDependencies: - supports-color - eslint-plugin-import@2.32.0(@typescript-eslint/parser@8.50.1(eslint@8.57.1)(typescript@5.9.3))(eslint-import-resolver-typescript@3.10.1)(eslint@8.57.1): + eslint-plugin-import@2.32.0(@typescript-eslint/parser@8.50.1(eslint@8.57.1)(typescript@5.9.3))(eslint-import-resolver-typescript@3.10.1(eslint-plugin-import@2.32.0(@typescript-eslint/parser@8.50.1(eslint@8.57.1)(typescript@5.9.3))(eslint@8.57.1))(eslint@8.57.1))(eslint@8.57.1): dependencies: '@rtsao/scc': 1.1.0 array-includes: 3.1.9 @@ -6086,7 +6098,7 @@ snapshots: doctrine: 2.1.0 eslint: 8.57.1 eslint-import-resolver-node: 0.3.9 - eslint-module-utils: 2.12.1(@typescript-eslint/parser@8.50.1(eslint@8.57.1)(typescript@5.9.3))(eslint-import-resolver-node@0.3.9)(eslint-import-resolver-typescript@3.10.1)(eslint@8.57.1) + eslint-module-utils: 2.12.1(@typescript-eslint/parser@8.50.1(eslint@8.57.1)(typescript@5.9.3))(eslint-import-resolver-node@0.3.9)(eslint-import-resolver-typescript@3.10.1(eslint-plugin-import@2.32.0(@typescript-eslint/parser@8.50.1(eslint@8.57.1)(typescript@5.9.3))(eslint@8.57.1))(eslint@8.57.1))(eslint@8.57.1) hasown: 2.0.2 is-core-module: 2.16.1 is-glob: 4.0.3 @@ -7093,12 +7105,13 @@ snapshots: possible-typed-array-names@1.1.0: {} - postcss-load-config@6.0.1(jiti@2.6.1)(postcss@8.5.6): + postcss-load-config@6.0.1(jiti@2.6.1)(postcss@8.5.6)(tsx@4.21.0): dependencies: lilconfig: 3.1.3 optionalDependencies: jiti: 2.6.1 postcss: 8.5.6 + tsx: 4.21.0 postcss@8.4.31: dependencies: @@ -7648,7 +7661,7 @@ snapshots: tslib@2.8.1: {} - tsup@8.5.1(jiti@2.6.1)(postcss@8.5.6)(typescript@5.9.3): + tsup@8.5.1(jiti@2.6.1)(postcss@8.5.6)(tsx@4.21.0)(typescript@5.9.3): dependencies: bundle-require: 5.1.0(esbuild@0.27.2) cac: 6.7.14 @@ -7659,7 +7672,7 @@ snapshots: fix-dts-default-cjs-exports: 1.0.1 joycon: 3.1.1 picocolors: 1.1.1 - postcss-load-config: 6.0.1(jiti@2.6.1)(postcss@8.5.6) + postcss-load-config: 6.0.1(jiti@2.6.1)(postcss@8.5.6)(tsx@4.21.0) resolve-from: 5.0.0 rollup: 4.54.0 source-map: 0.7.6 @@ -7676,6 +7689,13 @@ snapshots: - tsx - yaml + tsx@4.21.0: + dependencies: + esbuild: 0.27.2 + get-tsconfig: 4.13.0 + optionalDependencies: + fsevents: 2.3.3 + turbo-darwin-64@2.8.9: optional: true @@ -7833,13 +7853,13 @@ snapshots: optionalDependencies: '@types/react': 18.3.27 - vite-node@3.2.4(@types/node@22.19.3)(jiti@2.6.1)(lightningcss@1.30.2): + vite-node@3.2.4(@types/node@22.19.3)(jiti@2.6.1)(lightningcss@1.30.2)(tsx@4.21.0): dependencies: cac: 6.7.14 debug: 4.4.3 es-module-lexer: 1.7.0 pathe: 2.0.3 - vite: 6.4.1(@types/node@22.19.3)(jiti@2.6.1)(lightningcss@1.30.2) + vite: 6.4.1(@types/node@22.19.3)(jiti@2.6.1)(lightningcss@1.30.2)(tsx@4.21.0) transitivePeerDependencies: - '@types/node' - jiti @@ -7854,7 +7874,7 @@ snapshots: - tsx - yaml - vite@6.4.1(@types/node@22.19.3)(jiti@2.6.1)(lightningcss@1.30.2): + vite@6.4.1(@types/node@22.19.3)(jiti@2.6.1)(lightningcss@1.30.2)(tsx@4.21.0): dependencies: esbuild: 0.25.12 fdir: 6.5.0(picomatch@4.0.3) @@ -7867,8 +7887,9 @@ snapshots: fsevents: 2.3.3 jiti: 2.6.1 lightningcss: 1.30.2 + tsx: 4.21.0 - vite@7.3.0(@types/node@20.19.27)(jiti@2.6.1)(lightningcss@1.30.2): + vite@7.3.0(@types/node@20.19.27)(jiti@2.6.1)(lightningcss@1.30.2)(tsx@4.21.0): dependencies: esbuild: 0.27.2 fdir: 6.5.0(picomatch@4.0.3) @@ -7881,8 +7902,9 @@ snapshots: fsevents: 2.3.3 jiti: 2.6.1 lightningcss: 1.30.2 + tsx: 4.21.0 - vite@7.3.0(@types/node@22.19.3)(jiti@2.6.1)(lightningcss@1.30.2): + vite@7.3.0(@types/node@22.19.3)(jiti@2.6.1)(lightningcss@1.30.2)(tsx@4.21.0): dependencies: esbuild: 0.27.2 fdir: 6.5.0(picomatch@4.0.3) @@ -7895,12 +7917,13 @@ snapshots: fsevents: 2.3.3 jiti: 2.6.1 lightningcss: 1.30.2 + tsx: 4.21.0 - vitest@3.2.4(@types/node@22.19.3)(jiti@2.6.1)(jsdom@25.0.1)(lightningcss@1.30.2)(msw@2.12.7(@types/node@22.19.3)(typescript@5.9.3)): + vitest@3.2.4(@types/node@22.19.3)(jiti@2.6.1)(jsdom@25.0.1)(lightningcss@1.30.2)(msw@2.12.7(@types/node@22.19.3)(typescript@5.9.3))(tsx@4.21.0): dependencies: '@types/chai': 5.2.3 '@vitest/expect': 3.2.4 - '@vitest/mocker': 3.2.4(msw@2.12.7(@types/node@22.19.3)(typescript@5.9.3))(vite@6.4.1(@types/node@22.19.3)(jiti@2.6.1)(lightningcss@1.30.2)) + '@vitest/mocker': 3.2.4(msw@2.12.7(@types/node@22.19.3)(typescript@5.9.3))(vite@6.4.1(@types/node@22.19.3)(jiti@2.6.1)(lightningcss@1.30.2)(tsx@4.21.0)) '@vitest/pretty-format': 3.2.4 '@vitest/runner': 3.2.4 '@vitest/snapshot': 3.2.4 @@ -7918,8 +7941,8 @@ snapshots: tinyglobby: 0.2.15 tinypool: 1.1.1 tinyrainbow: 2.0.0 - vite: 6.4.1(@types/node@22.19.3)(jiti@2.6.1)(lightningcss@1.30.2) - vite-node: 3.2.4(@types/node@22.19.3)(jiti@2.6.1)(lightningcss@1.30.2) + vite: 6.4.1(@types/node@22.19.3)(jiti@2.6.1)(lightningcss@1.30.2)(tsx@4.21.0) + vite-node: 3.2.4(@types/node@22.19.3)(jiti@2.6.1)(lightningcss@1.30.2)(tsx@4.21.0) why-is-node-running: 2.3.0 optionalDependencies: '@types/node': 22.19.3 @@ -7938,10 +7961,10 @@ snapshots: - tsx - yaml - vitest@4.0.16(@types/node@20.19.27)(@vitest/browser-playwright@4.0.16)(jiti@2.6.1)(jsdom@25.0.1)(lightningcss@1.30.2)(msw@2.12.7(@types/node@20.19.27)(typescript@5.9.3)): + vitest@4.0.16(@types/node@20.19.27)(@vitest/browser-playwright@4.0.16)(jiti@2.6.1)(jsdom@25.0.1)(lightningcss@1.30.2)(msw@2.12.7(@types/node@20.19.27)(typescript@5.9.3))(tsx@4.21.0): dependencies: '@vitest/expect': 4.0.16 - '@vitest/mocker': 4.0.16(msw@2.12.7(@types/node@20.19.27)(typescript@5.9.3))(vite@7.3.0(@types/node@20.19.27)(jiti@2.6.1)(lightningcss@1.30.2)) + '@vitest/mocker': 4.0.16(msw@2.12.7(@types/node@20.19.27)(typescript@5.9.3))(vite@7.3.0(@types/node@20.19.27)(jiti@2.6.1)(lightningcss@1.30.2)(tsx@4.21.0)) '@vitest/pretty-format': 4.0.16 '@vitest/runner': 4.0.16 '@vitest/snapshot': 4.0.16 @@ -7958,11 +7981,11 @@ snapshots: tinyexec: 1.0.2 tinyglobby: 0.2.15 tinyrainbow: 3.0.3 - vite: 7.3.0(@types/node@20.19.27)(jiti@2.6.1)(lightningcss@1.30.2) + vite: 7.3.0(@types/node@20.19.27)(jiti@2.6.1)(lightningcss@1.30.2)(tsx@4.21.0) why-is-node-running: 2.3.0 optionalDependencies: '@types/node': 20.19.27 - '@vitest/browser-playwright': 4.0.16(msw@2.12.7(@types/node@20.19.27)(typescript@5.9.3))(playwright@1.57.0)(vite@7.3.0(@types/node@20.19.27)(jiti@2.6.1)(lightningcss@1.30.2))(vitest@4.0.16) + '@vitest/browser-playwright': 4.0.16(msw@2.12.7(@types/node@20.19.27)(typescript@5.9.3))(playwright@1.57.0)(vite@7.3.0(@types/node@20.19.27)(jiti@2.6.1)(lightningcss@1.30.2)(tsx@4.21.0))(vitest@4.0.16) jsdom: 25.0.1 transitivePeerDependencies: - jiti @@ -7977,10 +8000,10 @@ snapshots: - tsx - yaml - vitest@4.0.16(@types/node@22.19.3)(@vitest/browser-playwright@4.0.16)(jiti@2.6.1)(jsdom@25.0.1)(lightningcss@1.30.2)(msw@2.12.7(@types/node@22.19.3)(typescript@5.9.3)): + vitest@4.0.16(@types/node@22.19.3)(@vitest/browser-playwright@4.0.16)(jiti@2.6.1)(jsdom@25.0.1)(lightningcss@1.30.2)(msw@2.12.7(@types/node@22.19.3)(typescript@5.9.3))(tsx@4.21.0): dependencies: '@vitest/expect': 4.0.16 - '@vitest/mocker': 4.0.16(msw@2.12.7(@types/node@22.19.3)(typescript@5.9.3))(vite@7.3.0(@types/node@22.19.3)(jiti@2.6.1)(lightningcss@1.30.2)) + '@vitest/mocker': 4.0.16(msw@2.12.7(@types/node@22.19.3)(typescript@5.9.3))(vite@7.3.0(@types/node@22.19.3)(jiti@2.6.1)(lightningcss@1.30.2)(tsx@4.21.0)) '@vitest/pretty-format': 4.0.16 '@vitest/runner': 4.0.16 '@vitest/snapshot': 4.0.16 @@ -7997,11 +8020,11 @@ snapshots: tinyexec: 1.0.2 tinyglobby: 0.2.15 tinyrainbow: 3.0.3 - vite: 7.3.0(@types/node@22.19.3)(jiti@2.6.1)(lightningcss@1.30.2) + vite: 7.3.0(@types/node@22.19.3)(jiti@2.6.1)(lightningcss@1.30.2)(tsx@4.21.0) why-is-node-running: 2.3.0 optionalDependencies: '@types/node': 22.19.3 - '@vitest/browser-playwright': 4.0.16(msw@2.12.7(@types/node@22.19.3)(typescript@5.9.3))(playwright@1.57.0)(vite@7.3.0(@types/node@22.19.3)(jiti@2.6.1)(lightningcss@1.30.2))(vitest@4.0.16) + '@vitest/browser-playwright': 4.0.16(msw@2.12.7(@types/node@22.19.3)(typescript@5.9.3))(playwright@1.57.0)(vite@7.3.0(@types/node@22.19.3)(jiti@2.6.1)(lightningcss@1.30.2)(tsx@4.21.0))(vitest@4.0.16) jsdom: 25.0.1 transitivePeerDependencies: - jiti diff --git a/typescript2/textmate-grammar/baml.tmLanguage.yaml b/typescript2/textmate-grammar/baml.tmLanguage.yaml new file mode 100644 index 0000000000..d0867ace19 --- /dev/null +++ b/typescript2/textmate-grammar/baml.tmLanguage.yaml @@ -0,0 +1,772 @@ +variables: + identifier: "[a-zA-Z_][a-zA-Z0-9_]*" + +fileTypes: + - baml +name: baml +scopeName: source.baml +patterns: + - include: "#comment" + - include: "#item" + +repository: + comment: + patterns: + - name: comment.line.baml + match: //.*$ + - name: comment.block.baml + begin: /\* + end: \*/ + + # A top-level item in a BAML file. + item: + patterns: + - include: "#enum" + - include: "#class" + - include: "#function" + - include: "#template-string" + - include: "#type-alias" + - include: "#client" + - include: "#test" + - include: "#generator" + - include: "#retry-policy" + + # A client declaration, which may optionally include a generic parameter. + client: + begin: \b(client)\b(<({{identifier}})>)? + beginCaptures: + "1": + name: keyword.declaration.baml + "3": + name: entity.name.type.baml + end: (?<=\}) + patterns: + - include: "#comment" + - match: ({{identifier}}) + captures: + "1": + name: entity.name.type.baml + - include: "#config-block" + + # A test declaration. + test: + begin: \b(test)\b + beginCaptures: + "1": + name: keyword.declaration.baml + end: (?<=\}) + patterns: + - include: "#comment" + - match: ({{identifier}}) + captures: + "1": + name: entity.name.type.baml + - include: "#config-block" + + # A generator declaration. + generator: + begin: \b(generator)\b + beginCaptures: + "1": + name: keyword.declaration.baml + end: (?<=\}) + patterns: + - include: "#comment" + - match: ({{identifier}}) + captures: + "1": + name: entity.name.type.baml + - include: "#config-block" + + # A retry policy declaration. + retry-policy: + begin: \b(retry_policy)\b + beginCaptures: + "1": + name: keyword.declaration.baml + end: (?<=\}) + patterns: + - include: "#comment" + - match: ({{identifier}}) + captures: + "1": + name: entity.name.type.baml + - include: "#config-block" + + # A generic dictionary config block used in clients, tests, generators, retry policies, etc. + config-block: + begin: \{ + end: \} + patterns: + - include: "#comment" + - include: "#type-builder" + - include: "#config-block-entry" + + type-builder: + begin: \b(type_builder)\b + beginCaptures: + "1": + name: keyword.declaration.baml + end: (?<=\}) + patterns: + - include: "#comment" + - include: "#type-builder-block" + + # The contents of a type builder block's braces. + type-builder-block: + begin: \{ + end: \} + patterns: + - include: "#comment" + - match: \b(dynamic)\b + captures: + "1": + name: keyword.declaration.baml + - include: "#item" + + # An entry for a config block, i.e. a key-value pair where the key is an identifier and the value is an expression. + config-block-entry: + begin: ({{identifier}}) + beginCaptures: + "1": + name: variable.other.property.baml + end: (?=\})|$ + patterns: + - include: "#comment" + - include: "#config-block" + - include: "#expression" + + # A type alias declaration. + type-alias: + begin: \b(type)\b + beginCaptures: + "1": + name: keyword.declaration.baml + end: (?=;)|$ + patterns: + - include: "#comment" + - match: ({{identifier}}) + captures: + "1": + name: entity.name.type.baml + - include: "#type-expression" + + # An enum declaration. + enum: + begin: \b(enum)\b + beginCaptures: + "1": + name: keyword.declaration.baml + end: (?<=\}) + patterns: + - include: "#comment" + - match: ({{identifier}}) + captures: + "1": + name: entity.name.type.baml + - include: "#enum-block" + + # The contents of an enum declaration's braces. + enum-block: + begin: \{ + end: \} + patterns: + - include: "#comment" + - include: "#attribute" + - include: "#enum-variant" + + # An individual enum variant in an enum block. + enum-variant: + begin: "({{identifier}})" + beginCaptures: + "1": + name: variable.other.baml + end: (?=@)|$ + patterns: + - include: "#comment" + - include: "#attribute" + + # A class declaration. + class: + begin: \b(class)\b + beginCaptures: + "1": + name: keyword.declaration.baml + end: (?<=\}) + patterns: + - include: "#comment" + - match: ({{identifier}}) + captures: + "1": + name: entity.name.type.baml + - include: "#class-block" + + # The contents of a class declaration's braces. + class-block: + begin: \{ + end: \} + patterns: + - include: "#comment" + - include: "#attribute" + - include: "#class-member" + + # A member of a class, which can be either a function or a field. + class-member: + patterns: + - include: "#function" + - include: "#class-field" + + # An individual class field inside a class block, an identifier followed by type expression. + class-field: + begin: "({{identifier}})" + beginCaptures: + "1": + name: variable.other.property.baml + end: (?=@)|$ + patterns: + - include: "#comment" + - include: "#type-expression" + - include: "#attribute" + + # Either a block or member attribute, used for annotating enum bodies and variants, as well as class bodies and members. + attribute: + begin: (@@?{{identifier}}) + beginCaptures: + "1": + name: entity.other.attribute-name.baml + end: (?<=\))|(?![(\s]) + patterns: + - include: "#attribute-arguments" + + # Optional expression arguments for an attribute. + attribute-arguments: + begin: \( + end: \) + patterns: + - include: "#expression" + - match: "," + + # A function declaration, which may be either an LLM or imperative function. + function: + begin: \b(function)\b + beginCaptures: + "1": + name: keyword.declaration.baml + end: (?<=\}) + patterns: + - include: "#comment" + - match: ({{identifier}}) + captures: + "1": + name: entity.name.function.baml + - include: "#parameter-list" + - include: "#return-type" + - include: "#function-block" + + # The contents of a function declaration's braces, which can either be an LLM function body or an imperative function body. + function-block: + begin: \{ + end: \} + patterns: + - include: "#comment" + # Include these two first to allow for matching possible LLM functions, a bit of a hack but this is similar to how the actual parser figures it out. + - include: "#llm-function-client" + - include: "#llm-function-prompt" + - include: "#statement" + + # An individual client field assignment in an LLM function body + llm-function-client: + begin: \b(client)\b + beginCaptures: + "1": + name: keyword.declaration.baml + end: $ + patterns: + - include: "#comment" + - include: "#expression" + + # An individual prompt field assignment in an LLM function body + llm-function-prompt: + begin: \b(prompt)\b + beginCaptures: + "1": + name: keyword.declaration.baml + end: (?<=#) + patterns: + - include: "#comment" + - include: "#template-string-body" + + # A template string declaration. + template-string: + begin: \b(template_string)\b + beginCaptures: + "1": + name: keyword.declaration.baml + patterns: + - include: "#comment" + - match: ({{identifier}}) + captures: + "1": + name: entity.name.function.baml + - include: "#parameter-list" + - include: "#template-string-body" + end: (?<=#) + + # The body of a template string which may include interpolations using Jinja syntax. + template-string-body: + begin: (#+)" + beginCaptures: + "0": + name: string.quoted.raw.baml + end: \1 + endCaptures: + "0": + name: string.quoted.raw.baml + contentName: string.quoted.raw.baml + patterns: + - include: "#jinja-escapes" + + # Patterns for matching Jinja expressions and comments inside template strings, which need to be parsed with Jinja-specific rules. + jinja-escapes: + patterns: + - include: source.baml-jinja#comments + - begin: "{{-?" + captures: + "0": + name: storage.type.jinja.delimiter + end: "-?}}" + name: variable.meta.scope.jinja + patterns: + - include: source.baml-jinja#expression + - begin: "{%-?" + captures: + "0": + name: storage.type.jinja.delimiter + end: "-?%}" + name: meta.scope.jinja.tag + patterns: + - include: source.baml-jinja#expression + + # A return type annotation for a function. + return-type: + begin: ->\s* + end: (?=\{) + patterns: + - include: "#comment" + - include: "#type-expression" + + # An individual parameter in a parameter list + parameter: + begin: "(self)|({{identifier}})" + beginCaptures: + "1": + name: variable.language.self.baml + "2": + name: variable.parameter.baml + end: (?=[,)]) + patterns: + - include: "#comment" + - include: "#type-expression" + + # A list of parameters for a function. + parameter-list: + begin: \( + end: \) + patterns: + - include: "#comment" + - include: "#parameter" + - match: "," + + # An all-encompassing type expression that includes all possible forms. + type-expression: + patterns: + - include: "#type-generic" + - include: "#type-parenthesized" + - include: "#literal" + - include: "#type-namespaced" + + # A parenthesized type expression, used for grouping in complex type expressions like unions. + type-parenthesized: + begin: \( + end: \) + patterns: + - include: "#type-expression" + + # A generic type expression, which is an optionally dotted type name followed by angle brackets containing type arguments, e.g. `Foo`, or `baml.llm.Foo`. + type-generic: + begin: (?:{{identifier}}\.)*({{identifier}})\s*< + beginCaptures: + "1": + name: entity.name.type.baml + end: ">" + patterns: + - include: "#type-expression" + - match: "," + + # An optionally dotted type name made up of identifiers, e.g. `Foo`, or `baml.llm.Foo`. + type-namespaced: + match: (?:{{identifier}}\.)*({{identifier}}) + captures: + "1": + name: entity.name.type.baml + + # An imperative function block + imperative-block: + begin: \{ + end: \} + patterns: + - include: "#comment" + - include: "#statement" + + # A return statement, which can optionally include an expression to return. + return-statement: + begin: \b(return)\b + beginCaptures: + "1": + name: keyword.control.baml + end: ;|(?=\}) + patterns: + - include: "#expression" + + # A throw statement, which must include an expression to throw. + throw-expression: + begin: \b(throw)\b + beginCaptures: + "1": + name: keyword.control.baml + end: ;|(?=\}) + patterns: + - include: "#expression" + + # An all-encompassing statement pattern, that includes all possible forms. + statement: + patterns: + - include: "#let-statement" + - include: "#return-statement" + - include: "#continue-statement" + - include: "#break-statement" + - include: "#for-loop" + - include: "#while-loop" + - include: "#expression" + + # A continue statement. + continue-statement: + begin: \b(continue)\b + beginCaptures: + "1": + name: keyword.control.baml + end: ;|(?=\}) + + # A break statement. + break-statement: + begin: \b(break)\b + beginCaptures: + "1": + name: keyword.control.baml + end: ;|(?=\}) + + # A while loop, which includes a condition in parentheses and a body in braces. + while-loop: + begin: \b(while)\b + beginCaptures: + "1": + name: keyword.control.baml + end: (?<=\}) + patterns: + - include: "#imperative-block" + - include: "#expression" + + # A for loop, which can either be a C-style for loop with an initializer, condition, and increment, or an enhanced for-in loop. + for-loop: + begin: \b(for)\b + beginCaptures: + "1": + name: keyword.control.baml + end: (?<=\}) + patterns: + - include: "#for-in-clause" + - include: "#imperative-block" + - include: "#statement" # Match any statement to allow for C-style for loops + + # An enhanced for-in loop clause with an optional `let` preceding the loop variable + for-in-clause: + begin: (let\s+)?({{identifier}})\s+(in)\s+ + beginCaptures: + "1": + name: keyword.declaration.baml + "2": + name: variable.other.baml + "3": + name: keyword.control.baml + end: \) + patterns: + - include: "#expression" + + # A let statement, which includes a variable declaration and an optional type annotation, followed by an expression for the variable's value. + let-statement: + begin: \b(let)\b + beginCaptures: + "1": + name: keyword.declaration.baml + end: ; + patterns: + - match: ({{identifier}})\s*(?=[:=]) # Only match before equals to avoid consuming something in the bound expression + captures: + "1": + name: variable.other.baml + - include: "#let-type-annotation" + - include: "#expression" + + # The optional type annotation for a let statement. + let-type-annotation: + begin: ":" + end: (?==) + patterns: + - include: "#type-expression" + + # An all-encompassing expression pattern that includes all possible forms. + expression: + patterns: + - include: "#literal" + - include: "#throw-expression" + - include: "#if-expression" + - include: "#match-expression" + - include: "#catch-expression" + - include: "#catch-all-expression" + - include: "#object-constructor-expression" + - include: "#map-expression" + - include: "#array-expression" + - include: "#function-call-expression" + - include: "#variable-expression" + - include: "#property-access-expression" + + # A map literal expression, which is a series of key-value pairs enclosed in braces, e.g. `{key1: value1, key2: value2}`. + map-expression: + begin: \{ + end: \} + patterns: + - include: "#comment" + - include: "#map-entry" + - match: "," + + # An individual key-value pair in a map literal. + map-entry: + end: (?=[,}]) + patterns: + - include: "#map-entry-key" + - include: "#map-entry-value" + + # The key of an individual map entry, which can be either a string literal or an identifier, followed by a colon. + map-entry-key: + end: (?=:) + patterns: + - include: "#string-literal" + - include: "#raw-string-literal" + - match: ({{identifier}}) + captures: + "1": + name: variable.other.property.baml + + # A value in an individual map entry. + map-entry-value: + begin: ":" + end: (?=[,}]) + patterns: + - include: "#expression" + + # A match expression, which includes a scrutinee in parentheses and a block of match cases in braces. + match-expression: + begin: \b(match)\b + beginCaptures: + "1": + name: keyword.control.baml + end: (?<=\}) + patterns: + - include: "#match-scrutinee" + - include: "#match-block" + + # A catch expression, which includes a scrutinee in parentheses and a block of match cases in braces, similar to a match expression but used for catching errors. + catch-expression: + begin: \b(catch)\b + beginCaptures: + "1": + name: keyword.control.baml + end: (?<=\}) + patterns: + - include: "#match-scrutinee" + - include: "#match-block" + + # A catch-all expression, which includes a scrutinee in parentheses and a block of match cases in braces, similar to a match expression but used for catching errors. + catch-all-expression: + begin: \b(catch_all)\b + beginCaptures: + "1": + name: keyword.control.baml + end: (?<=\}) + patterns: + - include: "#match-scrutinee" + - include: "#match-block" + + # The scrutinee of a match or catch expression, which is an expression enclosed in parentheses. + match-scrutinee: + begin: \( + end: \) + patterns: + - include: "#expression" + + # The contents of a match or catch block's parentheses. + match-block: + begin: \{ + end: \} + patterns: + - include: "#comment" + - include: "#match-case-typed" + - include: "#literal" + - include: "#variable-expression" + - include: "#match-case-arrow" + + # A typed match case in a match block, e.g. `identifier: TypeExpr => body`. + match-case-typed: + begin: "({{identifier}})\\s*:" + beginCaptures: + "1": + name: variable.other.baml + end: (?==>) + patterns: + - include: "#type-expression" + + # An untyped match case in a match block, where a bound identifier followed by an arrow precedes either an imperative block or an expression. + match-case-arrow: + begin: => + end: "(?<=\\}),?|,|(?=\\})" + patterns: + - include: "#imperative-block" + - include: "#expression" + + # A property access expression, which is a series of identifiers separated by dots, e.g. `foo.bar.baz`, where all but the first identifier are highlighted as properties and the first identifier is highlighted as a variable. + property-access-expression: + match: (?:{{identifier}}\.?)*\.({{identifier}}) + captures: + "1": + name: variable.other.property.baml + + # A variable expression, which can be either the keyword `self` or an identifier. + variable-expression: + match: (self)|({{identifier}}) + captures: + "1": + name: variable.language.baml + "2": + name: variable.other.baml + + # A function call expression, which is an optionally dotted identifier followed by parentheses containing arguments, e.g. `foo(arg1, arg2)`, or `baml.util.foo(arg)`. + function-call-expression: + begin: \.?({{identifier}})\s*(?:<(?:{{identifier}}\.)*({{identifier}})>)?\s*\( + beginCaptures: + "1": + name: entity.name.function.baml + "2": + name: entity.name.type.baml + end: \) + patterns: + - include: "#comment" + - include: "#expression" + - match: "," + + # An array expression, which is a list of expressions enclosed in square brackets, e.g. `[expr1, expr2, expr3]`. + array-expression: + begin: \[ + end: \] + patterns: + - include: "#comment" + - include: "#expression" + - match: "," + + # An object constructor expression, which is an optionally dotted type identifier followed by braces containing property-value pairs, e.g. `Foo { prop1: value1, prop2: value2 }`, or `baml.util.Foo { prop: value }`. + object-constructor-expression: + begin: (?:{{identifier}}\.)*({{identifier}})\s*\{ + beginCaptures: + "1": + name: entity.name.type.baml + end: \} + patterns: + - include: "#comment" + - include: "#object-constructor-property" + + # A single property-value pair in an object constructor expression, which is an identifier followed by a colon and an expression for the property's value. + object-constructor-property: + begin: "({{identifier}})\\s*:" + beginCaptures: + "1": + name: variable.other.property.baml + end: (?=[,}]) + patterns: + - include: "#expression" + + # An integer or floating point literal. + number-literal: + match: \b\d+(\.\d+)?\b + name: constant.numeric.baml + + # A double-quoted string literal, which can include escape sequences with backslashes. + string-literal: + begin: '"' + end: '"' + name: string.quoted.double.baml + + # A boolean literal, which can be either `true` or `false`. + bool-literal: + match: \b(true|false)\b + name: constant.language.boolean.baml + + # The `null` literal. + null-literal: + match: \bnull\b + name: constant.language.null.baml + + # An all-encompassing pattern for literals, which includes all forms. + literal: + patterns: + - include: "#number-literal" + - include: "#string-literal" + - include: "#raw-string-literal" + - include: "#bool-literal" + - include: "#null-literal" + + # An if expression with its condition, including optional else clauses. + if-expression: + begin: \b(if)\b + beginCaptures: + "1": + name: keyword.control.baml + end: (?<=\})(?!\s*else\b) + patterns: + - include: "#if-condition" + - include: "#else-clause" + - include: "#imperative-block" + + # The condition of an individual if expression. + if-condition: + begin: \( + end: \) + patterns: + - include: "#expression" + + # The else clause in an if expression. + else-clause: + begin: \b(else)\b + beginCaptures: + "1": + name: keyword.control.baml + end: (?<=\}) + patterns: + # Check for an if expression first, in case they're doing else if. + - include: "#if-expression" + - include: "#imperative-block" + + # A raw string literal starting with a number of `#` characters, followed by a double quote, and ending with the same number of `#` characters and a double quote. + raw-string-literal: + begin: (#+)" + end: "\"\\1" + name: string.quoted.raw.baml + diff --git a/typescript2/textmate-grammar/build-grammar.ts b/typescript2/textmate-grammar/build-grammar.ts new file mode 100644 index 0000000000..22dbeb90e2 --- /dev/null +++ b/typescript2/textmate-grammar/build-grammar.ts @@ -0,0 +1,51 @@ +#!/usr/bin/env -S npx tsx +import fs from "fs"; +import path from "path"; +import yaml from "js-yaml"; + +const __dirname = path.dirname(new URL(import.meta.url).pathname); + +const src = path.resolve(__dirname, "baml.tmLanguage.yaml"); +const jinjaSrc = path.resolve(__dirname, "jinja.tmLanguage.json"); + +const doc = yaml.load(fs.readFileSync(src, "utf8")) as Record; + +const variables = (doc.variables ?? {}) as Record; +delete doc.variables; + +function substitute(obj: unknown): unknown { + if (typeof obj === "string") { + return obj.replace(/\{\{(\w+)\}\}/g, (_, name: string) => { + if (!(name in variables)) { + throw new Error(`Unknown variable: {{${name}}}`); + } + return variables[name]; + }); + } + if (Array.isArray(obj)) { + return obj.map(substitute); + } + if (obj && typeof obj === "object") { + const out: Record = {}; + for (const [k, v] of Object.entries(obj)) { + out[k] = substitute(v); + } + return out; + } + return obj; +} + +const result = substitute(doc); +const bamlJson = JSON.stringify(result, null, 2) + "\n"; + +// All destinations that need the generated grammar files. +const destinations = [ + path.resolve(__dirname, "../app-vscode-ext/syntaxes"), + path.resolve(__dirname, "../app-promptfiddle/syntaxes"), +]; + +for (const dir of destinations) { + fs.mkdirSync(dir, { recursive: true }); + fs.writeFileSync(path.join(dir, "baml.tmLanguage.json"), bamlJson); + fs.copyFileSync(jinjaSrc, path.join(dir, "jinja.tmLanguage.json")); +} diff --git a/typescript2/textmate-grammar/jinja.tmLanguage.json b/typescript2/textmate-grammar/jinja.tmLanguage.json new file mode 100644 index 0000000000..5e13694fd9 --- /dev/null +++ b/typescript2/textmate-grammar/jinja.tmLanguage.json @@ -0,0 +1,345 @@ +{ + "name": "jinja", + "scopeName": "source.baml-jinja", + "comment": "Jinja Templates", + "foldingStartMarker": "({%\\s*(block|filter|for|if|macro|raw))", + "foldingStopMarker": "({%\\s*(endblock|endfilter|endfor|endif|endmacro|endraw)\\s*%})", + "patterns": [ + { + "begin": "({%)\\s*(raw)\\s*(%})", + "captures": { + "1": { + "name": "storage.type.jinja.delimiter.tag" + }, + "2": { + "name": "keyword.control.jinja" + }, + "3": { + "name": "storage.type.jinja.delimiter.tag" + } + }, + "end": "({%)\\s*(endraw)\\s*(%})", + "name": "comment.block.jinja.raw" + }, + { + "include": "#comments" + }, + { + "begin": "{{-?", + "captures": [ + { + "name": "storage.type.jinja.delimiter" + } + ], + "end": "-?}}", + "name": "variable.meta.scope.jinja", + "patterns": [ + { + "include": "#expression" + } + ] + }, + { + "begin": "{%-?", + "captures": [ + { + "name": "storage.type.jinja.delimiter" + } + ], + "end": "-?%}", + "name": "meta.scope.jinja.tag", + "patterns": [ + { + "include": "#expression" + } + ] + } + ], + "repository": { + "comments": { + "begin": "{#-?", + "captures": [ + { + "name": "storage.type.jinja.delimiter" + } + ], + "end": "-?#}", + "name": "comment.block.jinja", + "patterns": [ + { + "include": "#comments" + } + ] + }, + "escaped_char": { + "match": "\\\\x[0-9A-F]{2}", + "name": "constant.character.escape.hex.jinja" + }, + "escaped_unicode_char": { + "captures": { + "1": { + "name": "constant.character.escape.unicode.16-bit-hex.jinja" + }, + "2": { + "name": "constant.character.escape.unicode.32-bit-hex.jinja" + }, + "3": { + "name": "constant.character.escape.unicode.name.jinja" + } + }, + "match": "(\\\\U[0-9A-Fa-f]{8})|(\\\\u[0-9A-Fa-f]{4})|(\\\\N\\{[a-zA-Z ]+\\})" + }, + "expression": { + "patterns": [ + { + "captures": { + "1": { + "name": "keyword.control.jinja" + }, + "2": { + "name": "variable.other.jinja.block" + } + }, + "match": "\\s*\\b(block)\\s+([a-zA-Z_][a-zA-Z0-9_]*)\\b" + }, + { + "captures": { + "1": { + "name": "keyword.control.jinja" + }, + "2": { + "name": "variable.other.jinja.filter" + } + }, + "match": "\\s*\\b(filter)\\s+([a-zA-Z_][a-zA-Z0-9_]*)\\b" + }, + { + "captures": { + "1": { + "name": "keyword.control.jinja" + }, + "2": { + "name": "variable.other.jinja.test" + } + }, + "match": "\\s*\\b(is)\\s+([a-zA-Z_][a-zA-Z0-9_]*)\\b" + }, + { + "captures": { + "1": { + "name": "keyword.control.jinja" + } + }, + "match": "(?<=\\{\\%-|\\{\\%)\\s*\\b([a-zA-Z_][a-zA-Z0-9_]*)\\b(?!\\s*[,=])" + }, + { + "match": "\\b(and|else|if|in|import|not|or|recursive|with(out)?\\s+context)\\b", + "name": "keyword.control.jinja" + }, + { + "match": "\\b(true|false|none)\\b", + "name": "constant.language.jinja" + }, + { + "match": "\\b(loop|super|self|varargs|kwargs)\\b", + "name": "variable.language.jinja" + }, + { + "match": "[a-zA-Z_][a-zA-Z0-9_]*", + "name": "variable.other.jinja" + }, + { + "match": "(\\+|\\-|\\*\\*|\\*|//|/|%)", + "name": "keyword.operator.arithmetic.jinja" + }, + { + "captures": { + "1": { + "name": "punctuation.other.jinja" + }, + "2": { + "name": "variable.other.jinja.filter" + } + }, + "match": "(\\|)([a-zA-Z_][a-zA-Z0-9_]*)" + }, + { + "captures": { + "1": { + "name": "punctuation.other.jinja" + }, + "2": { + "name": "variable.other.jinja.attribute" + } + }, + "match": "(\\.)([a-zA-Z_][a-zA-Z0-9_]*)" + }, + { + "begin": "\\[", + "captures": [ + { + "name": "punctuation.other.jinja" + } + ], + "end": "\\]", + "patterns": [ + { + "include": "#expression" + } + ] + }, + { + "begin": "\\(", + "captures": [ + { + "name": "punctuation.other.jinja" + } + ], + "end": "\\)", + "patterns": [ + { + "include": "#expression" + } + ] + }, + { + "begin": "\\{", + "captures": [ + { + "name": "punctuation.other.jinja" + } + ], + "end": "\\}", + "patterns": [ + { + "include": "#expression" + } + ] + }, + { + "match": "(\\.|:|\\||,)", + "name": "punctuation.other.jinja" + }, + { + "match": "(==|<=|=>|<|>|!=)", + "name": "keyword.operator.comparison.jinja" + }, + { + "match": "=", + "name": "keyword.operator.assignment.jinja" + }, + { + "begin": "\"", + "beginCaptures": [ + { + "name": "punctuation.definition.string.begin.jinja" + } + ], + "end": "\"", + "endCaptures": [ + { + "name": "punctuation.definition.string.end.jinja" + } + ], + "name": "string.quoted.double.jinja", + "patterns": [ + { + "include": "#string" + } + ] + }, + { + "begin": "'", + "beginCaptures": [ + { + "name": "punctuation.definition.string.begin.jinja" + } + ], + "end": "'", + "endCaptures": [ + { + "name": "punctuation.definition.string.end.jinja" + } + ], + "name": "string.quoted.single.jinja", + "patterns": [ + { + "include": "#string" + } + ] + }, + { + "begin": "@/", + "beginCaptures": [ + { + "name": "punctuation.definition.regexp.begin.jinja" + } + ], + "end": "/", + "endCaptures": [ + { + "name": "punctuation.definition.regexp.end.jinja" + } + ], + "name": "string.regexp.jinja", + "patterns": [ + { + "include": "#simple_escapes" + } + ] + } + ] + }, + "simple_escapes": { + "captures": { + "1": { + "name": "constant.character.escape.newline.jinja" + }, + "2": { + "name": "constant.character.escape.backlash.jinja" + }, + "3": { + "name": "constant.character.escape.double-quote.jinja" + }, + "4": { + "name": "constant.character.escape.single-quote.jinja" + }, + "5": { + "name": "constant.character.escape.bell.jinja" + }, + "6": { + "name": "constant.character.escape.backspace.jinja" + }, + "7": { + "name": "constant.character.escape.formfeed.jinja" + }, + "8": { + "name": "constant.character.escape.linefeed.jinja" + }, + "9": { + "name": "constant.character.escape.return.jinja" + }, + "10": { + "name": "constant.character.escape.tab.jinja" + }, + "11": { + "name": "constant.character.escape.vertical-tab.jinja" + } + }, + "match": "(\\\\\\n)|(\\\\\\\\)|(\\\\\\\")|(\\\\')|(\\\\a)|(\\\\b)|(\\\\f)|(\\\\n)|(\\\\r)|(\\\\t)|(\\\\v)" + }, + "string": { + "patterns": [ + { + "include": "#simple_escapes" + }, + { + "include": "#escaped_char" + }, + { + "include": "#escaped_unicode_char" + } + ] + } + } +}