Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Changelog

All notable changes to tree-sitter-vento will be documented in this file.

Version changes are relative to 0.20.0.

## 0.21.0

### Added

- `locals.scm` query file for local scope and variable reference tracking
Copy link

Copilot AI Feb 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The CHANGELOG mentions adding a locals.scm query file, but this file is not present in the PR and does not exist in the queries directory. Either the file should be added, or this entry should be removed from the CHANGELOG.

Copilot uses AI. Check for mistakes.
- Support for single-character variable names (e.g., `{{ i }}`, `{{ x }}`)
- Example file `examples/for-loop-scoping.vto` demonstrating variable scoping in loops
- Example file `examples/with-frontmatter.vto` demonstrating YAML front matter with Vento
- Example file `examples/all-keywords.vto` demonstrating all supported Vento keywords
- `tree-sitter.json` configuration file
- **Front matter support**: YAML front matter delimited by `---` with proper YAML injection
- **New keywords**: `echo`, `slot`/`/slot`, and `default`/`/default` tags
- Grammar rules: `front_matter`, `echo_tag`, `slot_block`, `slot_tag_start`, `slot_tag_end`, `default_block`, `default_tag_start`, `default_tag_end`
- Syntax highlighting for front matter delimiters and all new keywords
- Test cases for front matter and new keyword tags

### Changed

- Modified `code_snippet` rule in `grammar.js` to make external code scanner optional
- This allows single-character variables to be parsed correctly
- Updated precedence levels for expression parsing to ensure correct keyword vs. variable resolution
- Improved external scanner to handle YAML front matter and `of` keyword detection

### Fixed

- YAML front matter is recognized and styled with proper language injection
- Single-character loop variables (like `i` in `for i of items`) are now properly recognized as code blocks
- Variable scoping now works correctly in for loops - variables like `i` in `aria-label="Page {{ i }}"` are properly scoped within their containing for loop
- Keywords (such as `layout`, `slot`, `echo`, and `default`) are now recognized as keywords rather than variable references
- `of` in `{{ for menu of site.menu }}` is recognized as a keyword rather than a variable reference
- **Scanner**: Added `echo`, `slot`, and `default` to the KEYWORDS array for proper keyword detection
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "tree-sitter-vento"
description = "Vento grammar for tree-sitter",
version = "0.20.0"
version = "0.21.0"
authors = [
"Matthew Taylor"
]
Expand Down
61 changes: 61 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,64 @@ tree-sitter-vento
[![Discord](https://img.shields.io/badge/join-chat-blue?logo=discord&logoColor=white)](https://discord.gg/YbTmpACHWB)

A [tree-sitter](https://github.com/tree-sitter/tree-sitter) parser for the [Vento](https://vento.js.org/) templating language.

## Features

- Full support for Vento template syntax
- YAML front matter parsing with language injection
- JavaScript code injection for dynamic expressions
- HTML content injection for template markup
- Syntax highlighting for all Vento constructs

### Supported Keywords

All Vento keywords are properly parsed and highlighted:

#### Control Flow

- `{{ if }}` / `{{ /if }}` - Conditional blocks
- `{{ else if }}` - Else-if branches
- `{{ else }}` - Else branches
- `{{ for }}` / `{{ /for }}` - Loop blocks (with optional `await`)

#### Variables and Output

- `{{ set }}` / `{{ /set }}` - Variable assignment (tag and block forms)
- `{{ echo }}` - Output expressions

#### Layout and Composition

- `{{ layout }}` / `{{ /layout }}` - Layout blocks
- `{{ slot }}` / `{{ /slot }}` - Slot definitions
- `{{ default }}` / `{{ /default }}` - Default content blocks
- `{{ include }}` - Include other templates
- `{{ fragment }}` / `{{ /fragment }}` - Fragment blocks (plugin)

#### Functions and Modules

- `{{ function }}` / `{{ /function }}` - Function definitions (with optional `async` and `export`)
- `{{ import }}` - Import from other templates
- `{{ export }}` / `{{ /export }}` - Export variables (tag and block forms)

#### Special Tags

- `{{> }}` - JavaScript execution tag
- `{{# #}}` - Comment tag

### Front Matter Support

The parser supports YAML front matter at the beginning of Vento templates:

```vento
---
title: My Page
date: 2024-01-01
tags:
- vento
- template
---

<h1>{{ title }}</h1>
```

The YAML content within the front matter delimiters (`---`) will be properly injected and highlighted as YAML.
Loading