Skip to content

Commit

Permalink
#267 Backport Zig lexer from Notepad4
Browse files Browse the repository at this point in the history
This patch adds the Zig lexer from the Notepad4 editor originally
created by Zufu Liu (@zufuliu) and convert it to an object lexer.

Some changes have been made to make it compile and work in Scintilla
since Notepad4 contains a modified Scintilla version.
Also, some features of the Notepad4 lexer have been removed/changed:

- special highlighting of formatting strings has been removed as
  it uses some extra functions added to Notepad4's Scintilla and I didn't
  want to spend much time on figuring out what would have to be
  back-ported - other lexilla lexers don't do this either anyway
- folding has been modified to use simple folding like the rest of
  Scintilla lexers and not folding of the previous line based on brace
  presence on the next line like Notepad4
- "semi-syntactic" coloring of Notepad4 which colors functions following
  "fn" has been removed as this is not performed in other Scintilla lexers
- highlighting of tasks such as TODOs in comments has been removed as it
  isn't present in other Scintilla lexers
- colorig states and keywords have been renamed slightly - keywords at
  index 3 have been reserved for caller-supplied type names using
  SCI_SETKEYWORDS like in the C lexer (which we use in Geany to supply
  type names obtained using ctags)

  Add SCE_ZIG_COMMENTLINETOP state for top-level comments.

  Add styling function definitions
  I.e. identifiers after the "fn" keywords.

Fixes #237.
  • Loading branch information
techee authored and nyamatongwe committed Sep 14, 2024
1 parent 5cfd04a commit 7da58b3
Show file tree
Hide file tree
Showing 13 changed files with 1,380 additions and 0 deletions.
4 changes: 4 additions & 0 deletions doc/LexillaHistory.html
Original file line number Diff line number Diff line change
Expand Up @@ -615,6 +615,10 @@ <h3>
Smalltalk: Fix scaled decimal numbers without decimal separator.
<a href="https://github.com/ScintillaOrg/lexilla/pull/274">Pull request #274</a>.
</li>
<li>
Lexer added for Zig "zig".
<a href="https://github.com/ScintillaOrg/lexilla/pull/267">Pull request #267</a>.
</li>
</ul>
<h3>
<a href="https://www.scintilla.org/lexilla540.zip">Release 5.4.0</a>
Expand Down
20 changes: 20 additions & 0 deletions include/LexicalStyles.iface
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ val SCLEX_GDSCRIPT=135
val SCLEX_TOML=136
val SCLEX_TROFF=137
val SCLEX_DART=138
val SCLEX_ZIG=139

# When a lexer specifies its language as SCLEX_AUTOMATIC it receives a
# value assigned in sequence from SCLEX_AUTOMATIC+1.
Expand Down Expand Up @@ -2389,3 +2390,22 @@ val SCE_DART_KW_PRIMARY=23
val SCE_DART_KW_SECONDARY=24
val SCE_DART_KW_TERTIARY=25
val SCE_DART_KW_TYPE=26
# Lexical states for SCLEX_ZIG
lex Zig=SCLEX_ZIG SCE_ZIG_
val SCE_ZIG_DEFAULT=0
val SCE_ZIG_COMMENTLINE=1
val SCE_ZIG_COMMENTLINEDOC=2
val SCE_ZIG_COMMENTLINETOP=3
val SCE_ZIG_NUMBER=4
val SCE_ZIG_OPERATOR=5
val SCE_ZIG_CHARACTER=6
val SCE_ZIG_STRING=7
val SCE_ZIG_MULTISTRING=8
val SCE_ZIG_ESCAPECHAR=9
val SCE_ZIG_IDENTIFIER=10
val SCE_ZIG_FUNCTION=11
val SCE_ZIG_BUILTIN_FUNCTION=12
val SCE_ZIG_KW_PRIMARY=13
val SCE_ZIG_KW_SECONDARY=14
val SCE_ZIG_KW_TERTIARY=15
val SCE_ZIG_KW_TYPE=16
18 changes: 18 additions & 0 deletions include/SciLexer.h
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@
#define SCLEX_TOML 136
#define SCLEX_TROFF 137
#define SCLEX_DART 138
#define SCLEX_ZIG 139
#define SCLEX_AUTOMATIC 1000
#define SCE_P_DEFAULT 0
#define SCE_P_COMMENTLINE 1
Expand Down Expand Up @@ -2131,6 +2132,23 @@
#define SCE_DART_KW_SECONDARY 24
#define SCE_DART_KW_TERTIARY 25
#define SCE_DART_KW_TYPE 26
#define SCE_ZIG_DEFAULT 0
#define SCE_ZIG_COMMENTLINE 1
#define SCE_ZIG_COMMENTLINEDOC 2
#define SCE_ZIG_COMMENTLINETOP 3
#define SCE_ZIG_NUMBER 4
#define SCE_ZIG_OPERATOR 5
#define SCE_ZIG_CHARACTER 6
#define SCE_ZIG_STRING 7
#define SCE_ZIG_MULTISTRING 8
#define SCE_ZIG_ESCAPECHAR 9
#define SCE_ZIG_IDENTIFIER 10
#define SCE_ZIG_FUNCTION 11
#define SCE_ZIG_BUILTIN_FUNCTION 12
#define SCE_ZIG_KW_PRIMARY 13
#define SCE_ZIG_KW_SECONDARY 14
#define SCE_ZIG_KW_TERTIARY 15
#define SCE_ZIG_KW_TYPE 16
/* --Autogenerated -- end of section automatically generated from Scintilla.iface */

#endif
Loading

0 comments on commit 7da58b3

Please sign in to comment.