Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't fail silently when grammar is missing #1

Merged
merged 1 commit into from
Mar 31, 2024
Merged
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
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