https://github.com/dlvandenberg/tree-sitter-angular
Tree Sitter Grammar for Angular
https://github.com/dlvandenberg/tree-sitter-angular
angular grammar lexer parser tree-sitter tree-sitter-parser treesitter
Last synced: 4 months ago
JSON representation
Tree Sitter Grammar for Angular
- Host: GitHub
- URL: https://github.com/dlvandenberg/tree-sitter-angular
- Owner: dlvandenberg
- License: mit
- Created: 2023-11-28T18:22:48.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2025-10-08T08:53:00.000Z (4 months ago)
- Last Synced: 2025-10-08T10:27:12.398Z (4 months ago)
- Topics: angular, grammar, lexer, parser, tree-sitter, tree-sitter-parser, treesitter
- Language: C
- Homepage:
- Size: 2.59 MB
- Stars: 49
- Watchers: 3
- Forks: 12
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
✨ Tree Sitter Grammar for Angular ✨
## Specification
This parser is a complete rewrite of steelsojka's [tree-sitter-angular](https://github.com/steelsojka/tree-sitter-angular/tree/main).
This parser extends [tree-sitter-html](https://github.com/tree-sitter/tree-sitter-html) because the new _Control Flow_ syntax is not valid HTML code.
## Supported Features
- [x] Structural Directives
- [x] Property binding
- [x] Event binding
- [x] String interpolation
- [x] If-statements (v17)
- [x] For-statements (v17)
- [x] Switch-statements (v17)
- [x] Defer-statements (v17)
- [x] Let-expression (v18.1)
- [x] ICU message format
- [x] Untagged Template Literals (v19.2)
- [x] Exponentiation (`**`) and `in` operators (v20)
- [x] Binary assignment (`+=`, `*=`, etc) operators (v20.1)
## Requirements
- [Neovim](https://neovim.io/) v 0.11.x required (as it includes the filetype detection of Angular Templates)
## Filetype
Since neovim release 0.11.x, the filetype detection for Angular templates is included. It will detect Angular HTML templates, based on it's contents, and set the filetype to `htmlangular`.
### Older versions
If you are using an older version, you must set the filetype yourself.
E.g. mark the file as `htmlangular` if it matches the pattern `*.component.html`:
Create a `plugin` in `~/.config/nvim/plugin/angular.lua` with the following:
```lua
vim.filetype.add({
pattern = {
[".*%.component%.html"] = "htmlangular", -- Sets the filetype to `htmlangular` if it matches the pattern
},
})
```
Next, create a `ftplugin` for `htmlangular` that does the following:
```vim
runtime! ftplugin/html.vim!
```
Or, in lua:
```lua
vim.cmd('runtime! ftplugin/html.vim!')
```
## LSP's or other plugins
You may need to include this new filetype (`htmlangular`) for other plugins, like [LSP](https://github.com/neovim/nvim-lspconfig/blob/master/doc/server_configurations.md#angularls) for example:
```lua
require('lspconfig').angularls.setup {
filetypes = { 'typescript', 'html', 'typescriptreact', 'typescript.tsx', 'htmlangular' }
}
```
## Issues
If you experience any issues, please feel free to open an issue with the code that's causing problems.