Skip to content

Commit

Permalink
refactor(parser): use angular parser
Browse files Browse the repository at this point in the history
  • Loading branch information
steelsojka committed Dec 16, 2020
1 parent d66851e commit ee86c29
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 17 deletions.
15 changes: 6 additions & 9 deletions after/queries/html/injections.scm
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,24 @@
((attribute_name) @_name
(#lua-match? @_name "%[.*%]"))
(quoted_attribute_value
((attribute_value) @injection
(#set! "lang" "javascript"))))
(attribute_value) @angular))

; (myEvent)="handle($event)"
(attribute
((attribute_name) @_name
(#lua-match? @_name "%(.*%)"))
(quoted_attribute_value
((attribute_value) @injection
(#set! "lang" "javascript"))))
((attribute_value) @angular)))

; *ngIf="blorgy"
(attribute
((attribute_name) @_name
(#lua-match? @_name "^%*.*"))
(quoted_attribute_value
((attribute_value) @injection
(#set! "lang" "javascript"))))
((attribute_value) @angular)))

; {{ someBinding }}
(element
((text) @_name @injection
(#lua-match? @_name "%{%{.*%}%}")
(#set! "lang" "javascript")))
((text) @angular
(#lua-match? @angular "%{%{.*%}%}")
(#offset! @angular 0 2 0 -2)))
12 changes: 4 additions & 8 deletions after/queries/javascript/injections.scm
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@
(pair
key: ((property_identifier) @_prop
(#eq? @_prop "template"))
value: ((template_string) @injection
(#set! "lang" "html"))))))))
value: ((template_string) @html)))))))

(export_statement
decorator: (decorator
Expand All @@ -24,8 +23,7 @@
(pair
key: ((property_identifier) @_prop
(#eq? @_prop "template"))
value: ((template_string) @injection
(#set! "lang" "html")))))))
value: ((template_string) @html))))))
declaration: (class_declaration))

(class_declaration
Expand All @@ -39,8 +37,7 @@
key: ((property_identifier) @_prop
(#eq? @_prop "styles"))
value: (array
((template_string) @injection
(#set! "lang" "css")))))))))
((template_string) @css))))))))

(export_statement
decorator: (decorator
Expand All @@ -53,6 +50,5 @@
key: ((property_identifier) @_prop
(#eq? @_prop "styles"))
value: (array
((template_string) @injection
(#set! "lang" "css"))))))))
((template_string) @css)))))))
declaration: (class_declaration))
21 changes: 21 additions & 0 deletions lua/nvim-treesitter-angular/internal.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
local parsers = require "nvim-treesitter.parsers"
local installer = require "nvim-treesitter.install"

local M = {}

function M.init()
parsers.get_parser_configs().angular = {
install_info = {
url = "https://github.com/steelsojka/tree-sitter-angular",
files = { "src/parser.c" },
branch = "main"
},
maintainers = {"@steelsojka"}
}

if not parsers.has_parser("angular") then
installer.update("angular")
end
end

return M
1 change: 1 addition & 0 deletions plugin/nvim-treesitter-angular.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
lua require "nvim-treesitter-angular.internal".init()

0 comments on commit ee86c29

Please sign in to comment.