ziglang / zig-mode

Zig mode for Emacs
GNU General Public License v3.0
166 stars 55 forks source link

add `.` to `zig-re-identifier` to highlight namespaced types #102

Closed mega-dean closed 6 months ago

mega-dean commented 6 months ago

This change adds . to the zig-re-identifier regex so that namespaced types are entirely highlighted using font-lock-type-face, instead of only highlighting the first namespace.

Before: before

After: after

I tried to look at what zig-re-identifier is used for to make sure there wouldn't be any unintended side effects from this change, but I can't tell for sure. I skimmed some zig files and it looked like it only affected struct field types and function arguments.

mega-dean commented 6 months ago

I update the PR so now it adds (defconst zig-re-type "[[:word:]_.][[:word:]_.[:digit:]]*") and uses that in zig-re-type-annotation.

At first I tried updating the zig-re-type-annotation regex to keep using zig-re-identifier and I got it working with this:

(defconst zig-re-type-annotation
  (concat (zig-re-grab zig-re-identifier)
          "[[:space:]]*:[[:space:]]*"
          zig-re-optionals-pointers-arrays
          (zig-re-grab (concat (zig-re-grab (concat zig-re-identifier "\\.?")) "*"))))

But I think it's probably better to just define the new constant. Let me know if you want me to change it though.

joachimschmidt557 commented 6 months ago

Thanks! For now, this is perfectly fine. I think the regexes need to be revamped altogether in future to more closely match the zig grammar – or use tree sitter as basis.