Skip to content

Commit

Permalink
Update textmate parser (#1151)
Browse files Browse the repository at this point in the history
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)
<img width="368" alt="Screenshot 2024-11-09 at 10 04 04 AM"
src="https://github.com/user-attachments/assets/49d337a3-f89f-47c5-81bb-9045070ab78c">

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)

<!-- ELLIPSIS_HIDDEN -->


----

> [!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.
> 
> <sup>This description was created by </sup>[<img alt="Ellipsis"
src="https://img.shields.io/badge/Ellipsis-blue?color=175173">](https://www.ellipsis.dev?ref=BoundaryML%2Fbaml&utm_source=github&utm_medium=referral)<sup>
for 2663d77. It will automatically
update as commits are pushed.</sup>


<!-- ELLIPSIS_HIDDEN -->
  • Loading branch information
imalsogreg authored Nov 9, 2024
1 parent cbe3c92 commit 8c43e37
Showing 1 changed file with 17 additions and 17 deletions.
34 changes: 17 additions & 17 deletions typescript/vscode-ext/packages/syntaxes/baml.tmLanguage.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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": {
Expand Down

0 comments on commit 8c43e37

Please sign in to comment.