Skip to content

Commit 8df4efd

Browse files
author
Andrea Orru
authored
Merge pull request #33 from joachimschmidt557/use-rx
Use rx macro and add more possibilities for type annotations
2 parents ffaffb7 + 859a4dc commit 8df4efd

File tree

1 file changed

+16
-15
lines changed

1 file changed

+16
-15
lines changed

zig-mode.el

+16-15
Original file line numberDiff line numberDiff line change
@@ -130,23 +130,24 @@ If given a SOURCE, execute the CMD on it."
130130
(compilation-mode))
131131
(revert-buffer :ignore-auto :noconfirm)))))))
132132

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

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

141-
(defconst zig-re-identifier "[[:word:]_][[:word:]_[:digit:]]*")
142141
(defconst zig-re-type-annotation
143-
(concat (zig-re-grab zig-re-identifier)
144-
"[[:space:]]*:[[:space:]]*"
145-
(zig-re-grab zig-re-identifier)))
142+
(rx (group (regexp zig-re-identifier))
143+
(* (any space)) ":" (* (any space))
144+
(group (regexp zig-re-type))))
146145

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

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

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

0 commit comments

Comments
 (0)