From 8c43e37fdaa05d9f3626fde7ad56614610727348 Mon Sep 17 00:00:00 2001 From: Greg Hale Date: Sat, 9 Nov 2024 10:04:48 -0800 Subject: [PATCH] Update textmate parser (#1151) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Updates the textmate parser to handle `template_string_declaration`. The previous version defined a separate `block_string` rule that could be shared across use sites. However, it was easier to define a special-purpose block string handler within `template_string_definition`, that could coordinate with the `template_string_definition`. Specifically, the inlined block string parser uses a lookahead parser to scan for the ending `"#` without consuming it, so that `"#` can be owned by the outer `template_string_definition` parser. This PR: ![Screenshot 2024-11-08 at 4 34 02 PM](https://github.com/user-attachments/assets/79733f8b-43ad-4df5-8758-8cb874a259ca) (Multiline parameters still highlight correctly) Screenshot 2024-11-09 at 10 04 04 AM canary prior to this PR: ![Screenshot 2024-11-08 at 4 35 19 PM](https://github.com/user-attachments/assets/979f58d8-d554-4751-92a1-3de63c6c66f1) canary prior to the last change to the textmate grammar (https://github.com/BoundaryML/baml/pull/1130/files): ![Screenshot 2024-11-08 at 4 36 46 PM](https://github.com/user-attachments/assets/c450c170-af6c-4294-99d6-2c3521682221) ---- > [!IMPORTANT] > Updates `template_string_declaration` in `baml.tmLanguage.json` to handle block strings directly, removing the separate `block_string` rule. > > - **Behavior**: > - Updates `template_string_declaration` in `baml.tmLanguage.json` to handle block strings with a lookahead parser for ending `"#`. > - Removes separate `block_string` rule, integrating its functionality directly into `template_string_declaration`. > - **Patterns**: > - Adjusts `end` pattern in `template_string_declaration` to `"#{1,3}`. > - Adds inline block string handling with `begin` and `end` patterns for `#{1,3}"` and `"#{1,3}` respectively. > - **Misc**: > - Removes `block_string` from the repository. > > This description was created by [Ellipsis](https://www.ellipsis.dev?ref=BoundaryML%2Fbaml&utm_source=github&utm_medium=referral) for 2663d77d7bd9482870c72a3e2a4d7bb2e390398e. It will automatically update as commits are pushed. --- .../packages/syntaxes/baml.tmLanguage.json | 34 +++++++++---------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/typescript/vscode-ext/packages/syntaxes/baml.tmLanguage.json b/typescript/vscode-ext/packages/syntaxes/baml.tmLanguage.json index 0d9b4a7b1..bf940a0b6 100644 --- a/typescript/vscode-ext/packages/syntaxes/baml.tmLanguage.json +++ b/typescript/vscode-ext/packages/syntaxes/baml.tmLanguage.json @@ -83,13 +83,25 @@ "1": { "name": "storage.type.declaration.function" }, "2": { "name": "entity.name.function" } }, - "end": "(\")(#)", + "end": "(\")(#{1,3})", "endCaptures": { - "1": { "name": "string.quoted.block.baml" }, - "2": { "name": "string.quoted.block.baml" } + "0": { "name": "string.quoted.block.baml" } }, - "name": "string.quoted.block.baml", - "patterns": [{ "include": "#comment" }, { "include": "#function_parameters" }, { "include": "#block_string" }] + "patterns": [ + { "include": "#comment" }, + { "include": "#function_parameters" }, + { + "begin": "(#{1,3}\")", + "beginCaptures": { + "0": { "name": "string.quoted.block.baml" } + }, + "end": "(?=\"#{1,3})", + "contentName": "string.quoted.block.baml", + "patterns": [ + { "include": "source.baml-jinja" } + ] + } + ] }, "function_declaration": { "comment": "Function declaration", @@ -576,18 +588,6 @@ } ] }, - "block_string": { - "begin": "(#(\"){1,3})", - "beginCaptures": { - "1": { "name": "string.quoted.block.baml.startquote" } - }, - "end": "((\"){1,3}#)", - "endCaptures": { - "1": { "name": "string.quoted.block.baml.endquote" } - }, - "contentName": "string.quoted.block.baml", - "patterns": [{ "include": "source.baml-jinja" }] - }, "block_string_pair": { "begin": "(\\w+)?\\s+(#(\"){1,3})", "beginCaptures": {