Skip to content

Commit

Permalink
Merge pull request #1 from purcell/patch-2
Browse files Browse the repository at this point in the history
Don't fail silently when grammar is missing
  • Loading branch information
hhamud authored Mar 31, 2024
2 parents 4b70b72 + ac9205e commit eb399cc
Showing 1 changed file with 28 additions and 27 deletions.
55 changes: 28 additions & 27 deletions noir-ts-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,12 @@
table)
"Syntax table for `noir-ts-mode'.")

(defvar noir-ts-mode--keywords
(defvar noir-ts-mode--keywords
'("as" "else" "fn" "for" "if"
"impl" "in" "let" "mod" "global" "assert" "constrain"
"struct" "use" (crate) (super) (return) (self)
(mutable) (viewer) (comptime))
"Noir keywords for tree-sitter font-locking.")
"Noir keywords for tree-sitter font-locking.")

(defvar noir-ts-mode--operators
'("!" "!=" "%" "&" "&=" "&&" "*" "+" "+=" "," "-" "-="
Expand Down Expand Up @@ -125,7 +125,7 @@
'((function_definition
(identifier) @font-lock-function-name-face)
(function_call
(identifier) @font-lock-function-call-face))
(identifier) @font-lock-function-call-face))

:feature 'builtin
:override t
Expand Down Expand Up @@ -193,38 +193,39 @@
:group 'noir
:syntax-table noir-ts-mode--syntax-table

(when (treesit-ready-p 'noir)
(treesit-parser-create 'noir)
(unless (treesit-ready-p 'noir)
(error "Language grammar for %s is missing" 'noir))

;; Comments.
(setq-local comment-start "// ")
(setq-local comment-end "")
(setq-local comment-start-skip (rx (or "//" "/*")))
(setq-local comment-end-skip (rx (or "\n" "*/")))
(treesit-parser-create 'noir)

;; Indent.
(setq-local indent-tabs-mode nil
treesit-simple-indent-rules noir-ts-mode--indent-rules)
;; Comments.
(setq-local comment-start "// ")
(setq-local comment-end "")
(setq-local comment-start-skip (rx (or "//" "/*")))
(setq-local comment-end-skip (rx (or "\n" "*/")))

;; Font-lock
(setq-local treesit-font-lock-settings noir-ts-mode--font-lock-settings)
(setq-local treesit-font-lock-feature-list
'((comment)
(keyword string)
(constant variable type function-name builtin number)
(bracket delimiter operator)))
;; Indent.
(setq-local indent-tabs-mode nil
treesit-simple-indent-rules noir-ts-mode--indent-rules)

;; Navigation.
(setq-local treesit-defun-type-regexp
(regexp-opt '("function_definition"
"struct_method"
"struct_definition")))
;; Font-lock
(setq-local treesit-font-lock-settings noir-ts-mode--font-lock-settings)
(setq-local treesit-font-lock-feature-list
'((comment)
(keyword string)
(constant variable type function-name builtin number)
(bracket delimiter operator)))

;; Navigation.
(setq-local treesit-defun-type-regexp
(regexp-opt '("function_definition"
"struct_method"
"struct_definition")))

(treesit-major-mode-setup)))

(treesit-major-mode-setup))


(provide 'noir-ts-mode)

;;; noir-ts-mode.el ends here

0 comments on commit eb399cc

Please sign in to comment.