Skip to content

Use rx macro and add more possibilities for type annotations #33

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

Merged
merged 1 commit into from
Oct 13, 2020
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
31 changes: 16 additions & 15 deletions zig-mode.el
Original file line number Diff line number Diff line change
@@ -128,23 +128,24 @@ If given a SOURCE, execute the CMD on it."
(compilation-mode))
(revert-buffer :ignore-auto :noconfirm)))))))

(defun zig-re-word (inner)
"Construct a regular expression for the word INNER."
(concat "\\<" inner "\\>"))
(defconst zig-re-identifier
(rx (any "_" word)
(* (any "_" word digit))))

(defun zig-re-grab (inner)
"Construct a group regular expression for INNER."
(concat "\\(" inner "\\)"))
(defconst zig-re-type
(rx (* (| "?" "[_]" "*" "[]"))
(regexp zig-re-identifier)))

(defconst zig-re-identifier "[[:word:]_][[:word:]_[:digit:]]*")
(defconst zig-re-type-annotation
(concat (zig-re-grab zig-re-identifier)
"[[:space:]]*:[[:space:]]*"
(zig-re-grab zig-re-identifier)))
(rx (group (regexp zig-re-identifier))
(* (any space)) ":" (* (any space))
(group (regexp zig-re-type))))

(defun zig-re-definition (dtype)
"Construct a regular expression for definitions of type DTYPE."
(concat (zig-re-word dtype) "[[:space:]]+" (zig-re-grab zig-re-identifier)))
(rx bow (literal dtype) eow
(+ (any space))
(group (regexp zig-re-identifier))))

(defconst zig-mode-syntax-table
(let ((table (make-syntax-table)))
@@ -383,10 +384,10 @@ If given a SOURCE, execute the CMD on it."
;;; Imenu support
(defun zig-re-structure-def-imenu (stype)
"Construct a regular expression for strucutres definitions of type STYPE."
(concat (zig-re-word "const") "[[:space:]]+"
(zig-re-grab zig-re-identifier)
".*"
(zig-re-word stype)))
(rx bow "const" eow (+ (any space))
(group (regexp zig-re-identifier))
(* not-newline)
bow (literal stype) eow))

(defvar zig-imenu-generic-expression
(append (mapcar (lambda (x)