HEEx grammer for Tree-sitter

Overview

Tree-sitter HEEx

Tree-sitter grammar and parser for HEEx, the HTML-aware and component-friendly extension of EEx for Phoenix.

For Surface support, see tree-sitter-surface.

Features

Parsing support for the following nodes:

  • Tags
  • Components
  • Directives
  • Expressions
  • Attributes
  • Text
  • Comments
  • Doctype

Queries

  • Highlights
  • Folds
  • Indents
  • Injections

Currently supported in NeoVim via nvim-treesitter.

Comments
  • Add support for :for and :let attrs

    Add support for :for and :let attrs

    See https://github.com/phoenixframework/phoenix_live_view/pull/2023 and https://github.com/phoenixframework/phoenix_live_view/pull/2013 for more information.

    opened by connorlay 6
  • Support special attributes :let, :for, :stream

    Support special attributes :let, :for, :stream

    Adds supports for HEEx special attributes: :let, :for, and :stream.

    A new node has been added to the grammar, special_attribute, that behaves similarly to the attribute node with the following changes:

    • a special_attribute must have a corresponding expression node.
    • a special_attribute can only be added to the following tags: start_component, start_slot, start_tag, and self_closing_tag.
    • a special_attribute_name can only be one of the following values (more could be added in the future): let, for, stream.
    • a special_attribute_name is highlighted as keyword

    This PR also adds the prettier code formatter with configuration borrowed from tree-sitter-elixir.

    opened by connorlay 3
  • Error on `do` blocks

    Error on `do` blocks

    I created a vanilla phx project and created a new resource using the generators and I am seeing an error on the do in do blocks.

    Here you can see the screenshot with the corresponding nodes in nvim treesitter playground.

    image
    opened by mhanberg 3
  • allow brackets in expression_value nodes

    allow brackets in expression_value nodes

    I found some odd behavior parsing a case like this:

    <div phx-value-target={ "##{@id}" }></div>
    

    where the expression_value node has a hard time dealing with the brackets {..}. Here's the parse result:

    (fragment [0, 0] - [1, 0]
      (tag [0, 0] - [0, 42]
        (start_tag [0, 0] - [0, 36]
          (tag_name [0, 1] - [0, 4])
          (attribute [0, 5] - [0, 35]
            (attribute_name [0, 5] - [0, 21])
            (expression [0, 22] - [0, 35]
              (ERROR [0, 23] - [0, 27]
                (expression_value [0, 23] - [0, 27]))
              (expression_value [0, 27] - [0, 32])
              (ERROR [0, 32] - [0, 33]))))
        (end_tag [0, 36] - [0, 42]
          (tag_name [0, 38] - [0, 41]))))
    

    I shuffled around the grammar rules for expression_value a bit so we use a hidden $._expression_value which can repeat to capture everything in the expression's brackets. Then we alias those repeating hidden nodes all together as one expression_value node. The tree for that example case ends up looking like so

    (fragment [0, 0] - [1, 0]
      (tag [0, 0] - [0, 42]
        (start_tag [0, 0] - [0, 36]
          (tag_name [0, 1] - [0, 4])
          (attribute [0, 5] - [0, 35]
            (attribute_name [0, 5] - [0, 21])
            (expression [0, 22] - [0, 35]
              (expression_value [0, 23] - [0, 34]))))
        (end_tag [0, 36] - [0, 42]
          (tag_name [0, 38] - [0, 41]))))
    
    opened by the-mikedavis 3
  • Indentation and `Pair Matching` not working

    Indentation and `Pair Matching` not working

    Hi!

    First of all, thank you for putting this together so close to the release of LV 0.16 I was so stoked when I saw there was treesitter support already ❤️

    I'm having some issues where indentation motions with = are just putting everything flat on the same level, and the % motion to go to a "matching pair" which I expect should take me to the closing take for a div for example if I'm on the opening tag, isn't working. It's just doing nothing.

    Odds are my configuration are just wrong, any ideas on how to trouble shoot this most effectively?

    opened by heimann 3
  • New to TS - Unable to install heex

    New to TS - Unable to install heex

    Hi,

    I'm using neovim and tree-sitter but ran into an issue when trying to install heex.

    :TSInstall heex
    Parser not available for language heex
    

    Any ideas on what could be wrong with my system? I was able to use :TSInstall to install elixir/erlang/html grammar, so something works.

    Thanks!!

    opened by fkumro 3
  • freature request: sigil-H support?

    freature request: sigil-H support?

    Thanks for this lib! now my html.heex files are a lot more readable. Are you planning on implementing support for ~H heex regions? I'm interested in helping out with this, seems like it may relate to this call https://github.com/neovim/neovim/blob/master/runtime/lua/vim/treesitter/languagetree.lua#L263.

    opened by briandunn 2
  • add highlight and injection queries and partial_expression_value node

    add highlight and injection queries and partial_expression_value node

    connects https://github.com/connorlay/tree-sitter-eex/issues/1 connects https://github.com/elixir-lang/tree-sitter-elixir/issues/2

    Pretty much the same thing as https://github.com/connorlay/tree-sitter-eex/pull/4 but for the heex directives. I'm open to renaming the new node, naming things is hard :sweat_smile:

    With this change to the grammar I'm seeing good combined injections results:

    heex-highlights

    Although the error -> affects heex as well as eex.

    I also slightly modified the queries so that the <%, <%=, etc. act like keywords like in tree-sitter-embedded-template or the eex highlight PR. I did like the old scopes for those though; it was nice to have them look subtle. Maybe it makes sense to use punctuation.directive so that theme authors can make a distinction but it defaults to looking like otherwise punctuation?

    opened by the-mikedavis 1
  • Separate ending expressions from beginning/middle expressions

    Separate ending expressions from beginning/middle expressions

    This allows consumers to detect when an expression that is broken up over multiple directives ends, which can be used to calculate indentation more accurately.

    Connects #28

    opened by the-mikedavis 0
  • Fix link to sigil_H/2

    Fix link to sigil_H/2

    sigil_H/2 and the HEEx documentation moved from Phoenix.LiveView.Helpers to Phoenix.Component in https://github.com/phoenixframework/phoenix_live_view/commit/02e20e4f5a01356004efd7fb965bbeeb99534c35.

    With the 0.18.0 release, this left the HEEx link in the README broken. This change points to the new URL.

    Closes #25

    opened by the-mikedavis 0
  • Usage in editor extensions

    Usage in editor extensions

    Hey folks,

    I'm working on adding TreeSitter Elixir syntax highlighting to the Nova editor. I would love to also support HEEx templates using this project but I noticed the repo doesn't contain a licence. Can I use this project in an editor extension? And if so are there any specific attribution requirements you have?

    opened by raulchedrese 0
  • Directive blocks are not represented

    Directive blocks are not represented

    I am currently implementing indentation using emacs treesit ( tree-sitter integration ), which uses this library. Everything works well except for directive blocks like

    <%= if true do %>
    <.some_tag_or_component>
    </.some_tag_or_component>
    <% end %>
    

    which produces

    (fragment [0, 0] - [4, 0]
      (directive [0, 0] - [0, 17]
        (partial_expression_value [0, 3] - [0, 14]))
      (component [1, 0] - [2, 25]
        (start_component [1, 0] - [1, 24]
          (component_name [1, 1] - [1, 23]
            (function [1, 2] - [1, 23])))
        (end_component [2, 0] - [2, 25]
          (component_name [2, 2] - [2, 24]
            (function [2, 3] - [2, 24]))))
      (directive [3, 0] - [3, 10]
        (partial_expression_value [3, 3] - [3, 7])))
    

    Since the directive is not the parent of the component there is no simple way of checking parent for indentation.

    opened by wkirschbaum 4
Releases(v0.5.0)
  • v0.5.0(Jun 13, 2022)

    • Add new nodes to support HEEx special attributes
    • Support self-closing HEEx slots
    • Support hyphens in HTML tag names
    • Update README
    • Add prettier code formatter
    Source code(tar.gz)
    Source code(zip)
  • v0.4.1(Apr 17, 2022)

  • v0.4.0(Jan 30, 2022)

    • Add new nodes to support HEEx slots
    • Fix: allow for empty comments
    • Update highlights to better match those in nvim-treesitter
    • Update README
    Source code(tar.gz)
    Source code(zip)
  • v0.3.1(Jan 24, 2022)

  • v0.3.0(Jan 17, 2022)

    • Add highlight queries, thanks @the-mikedavis!
    • Add injection queries, thanks @the-mikedavis!
    • Add partial_expression_value node to support multi-clause directives, thanks @the-mikedavis!
    • Add support for multi-line EEx comments, thanks @the-mikedavis!
    • Add support for HTML comments, thanks @the-mikedavis!
    Source code(tar.gz)
    Source code(zip)
  • v0.2.1(Oct 19, 2021)

Owner
Connor Lay (Clay)
He/Him software engineer interested in NeoVim, Elixir, photography, plants, and cats.
Connor Lay (Clay)
An intrusive C++17 implementation of a Red-Black-Tree, a Weight Balanced Tree, a Dynamic Segment Tree and much more!

This is Ygg (short for Yggdrasil), a C++17 implementation of several intrusive data structures: several balanced binary search trees: a red-black Tree

Lukas Barth 98 Dec 25, 2022
SQL grammar for tree sitter

tree-sitter-sql I want to do something fun at work since we have stuff like this in Go: const hoverDocumentQuery = ` -- source: enterprise/internal/co

TJ DeVries 22 Sep 10, 2022
Tree sitter grammar for Svelte

Tree-sitter-svelte Tree-sitter grammar for svelte Install npm i tree-sitter-svelte tree-sitter Usage To get started with exploring the grammar in a w

Himujjal Upadhyaya 48 Dec 2, 2022
A tree-sitter grammar for go.mod files

tree-sitter-go-mod tree-sitter grammar for go.mod files. Status The grammar is fairly small, and has been working well for highlighting for me. I expe

Camden Cheek 24 Dec 3, 2022
A tree-sitter grammar for HCL (HashiCorp Configuration Language), used by projects such as Terraform.

tree-sitter-hcl tree-sitter grammar for HCL (HashiCorp Configuration Language) files. HCL is the configuration format used by projects such as Terrafo

Mitchell Hashimoto 65 Nov 29, 2022
A tree-sitter grammar for protocol buffer files (proto3).

tree-sitter-proto tree-sitter grammar for protocol buffer files (proto3 only). Status The grammar should be complete. I'm still working on the highlig

Mitchell Hashimoto 43 Nov 2, 2022
Build a tree-sitter dynamic module

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! I should clarify that this module is NOT a standalone tree-sitter module. It is supo

Yuan Fu 53 Jan 5, 2023
tree-sitter parser and syntax highlighter for the Dwarf Fortress raw language

tree-sitter-dfraw A simple language parser and highlighter made with tree-sitter tokyonight nightfly Using with nvim-treesitter Please refer to the ad

null 2 Apr 1, 2022
Org grammar for tree-sitter

tree-sitter-org Unstable: This build will change. Org grammar for tree-sitter. It is not meant to implement emacs' orgmode parser, but to implement a

Emilia Simmons 161 Jan 7, 2023
Golang template grammar for tree-sitter

tree-sitter-go-template Golang templates grammar for tree-sitter. NeoVim integration using nvim-treesitter Add gotmpl parser following nvim-treesitter

Nikita Galaiko 28 Nov 30, 2022
Surface grammar for Tree-sitter

Tree-sitter Surface Tree-sitter grammar and parser for Surface, the server-side rendering component library for Phoenix. Supports the Surface 0.5+ tem

Clay 13 Jul 12, 2022
A tree-sitter grammar for the Gleam programming language

tree-sitter-gleam A tree-sitter grammar for the Gleam programming language This is, presently, very much a work-in-progress. DONE Parsing import state

Jonathan Arnett 0 Mar 30, 2022
A tree-sitter grammar for `git diff` output

tree-sitter-git-diff A tree-sitter grammar for git diffs. Status Working, but needs more testing. Examples Highlighting a .diff file: Injecting this g

Michael Davis 5 Dec 9, 2022
Languages for the Tree-sitter parser generator wrapped in Swift packages

TreeSitterLanguages Languages for the Tree-sitter parser generator wrapped in Swift packages. Motivation There are two reasons this package exists: As

Simon Støvring 23 Dec 21, 2022
Promela grammar for tree-sitter

tree-sitter-promela Promela grammar for tree-sitter. Motivation Promela is a language used for specifying models, especially in distributed systems co

Ben Siraphob 6 Nov 22, 2022
Scheme grammar for tree-sitter

tree-sitter-scheme Scheme grammar for tree-sitter. Status tree-sitter-scheme should work on a superset of Scheme. The standards are expected to suppor

null 6 Dec 27, 2022
This repository provides implementation of an incremental k-d tree for robotic applications.

ikd-Tree ikd-Tree is an incremental k-d tree designed for robotic applications. The ikd-Tree incrementally updates a k-d tree with new coming points o

HKU-Mars-Lab 362 Jan 4, 2023
Device Tree for Redmi K30 Ultra

Copyright (C) 2020 PixelExperience Plus Edition Device configuration for Redmi K30 Ultra ========================================= The Redmi K30 Ultra

Xayah 22 Jun 2, 2022