Skip to content

Commit

Permalink
#287 Add SCE_ZIG_IDENTIFIER_STRING for identifiers expressed as strings.
Browse files Browse the repository at this point in the history
  • Loading branch information
techee authored and nyamatongwe committed Nov 4, 2024
1 parent 0882e42 commit 942ac3f
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 9 deletions.
4 changes: 4 additions & 0 deletions doc/LexillaHistory.html
Original file line number Diff line number Diff line change
Expand Up @@ -614,6 +614,10 @@ <h3>
TOML: Don't treat keys without values as errors.
<a href="https://github.com/ScintillaOrg/lexilla/pull/283">Pull request #283</a>.
</li>
<li>
Zig: Add SCE_ZIG_IDENTIFIER_STRING for identifiers expressed as strings.
<a href="https://github.com/ScintillaOrg/lexilla/pull/287">Pull request #287</a>.
</li>
</ul>
<h3>
<a href="https://www.scintilla.org/lexilla541.zip">Release 5.4.1</a>
Expand Down
1 change: 1 addition & 0 deletions include/LexicalStyles.iface
Original file line number Diff line number Diff line change
Expand Up @@ -2425,6 +2425,7 @@ val SCE_ZIG_KW_PRIMARY=13
val SCE_ZIG_KW_SECONDARY=14
val SCE_ZIG_KW_TERTIARY=15
val SCE_ZIG_KW_TYPE=16
val SCE_ZIG_IDENTIFIER_STRING=17
# Lexical states for SCLEX_NIX
lex Nix=SCLEX_NIX SCE_NIX_
val SCE_NIX_DEFAULT=0
Expand Down
1 change: 1 addition & 0 deletions include/SciLexer.h
Original file line number Diff line number Diff line change
Expand Up @@ -2165,6 +2165,7 @@
#define SCE_ZIG_KW_SECONDARY 14
#define SCE_ZIG_KW_TERTIARY 15
#define SCE_ZIG_KW_TYPE 16
#define SCE_ZIG_IDENTIFIER_STRING 17
#define SCE_NIX_DEFAULT 0
#define SCE_NIX_COMMENTLINE 1
#define SCE_NIX_COMMENTBLOCK 2
Expand Down
16 changes: 7 additions & 9 deletions lexers/LexZig.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ LexicalClass lexicalClasses[] = {
14, "SCE_ZIG_KW_SECONDARY", "identifier", "Secondary keywords",
15, "SCE_ZIG_KW_TERTIARY", "identifier", "Tertiary keywords",
16, "SCE_ZIG_KW_TYPE", "identifier", "Global types",
17, "SCE_ZIG_IDENTIFIER_STRING", "identifier", "Identifier using @\"\" syntax",
};

class LexerZig : public DefaultLexer {
Expand Down Expand Up @@ -307,6 +308,7 @@ void LexerZig::Lex(Sci_PositionU startPos, Sci_Position lengthDoc, int initStyle
case SCE_ZIG_CHARACTER:
case SCE_ZIG_STRING:
case SCE_ZIG_MULTISTRING:
case SCE_ZIG_IDENTIFIER_STRING:
if (sc.atLineStart) {
sc.SetState(SCE_ZIG_DEFAULT);
} else if (sc.ch == '\\' && sc.state != SCE_ZIG_MULTISTRING) {
Expand All @@ -318,16 +320,9 @@ void LexerZig::Lex(Sci_PositionU startPos, Sci_Position lengthDoc, int initStyle
escSeq.digitsLeft = 9;
sc.Forward();
}
} else if ((sc.ch == '\'' && sc.state == SCE_ZIG_CHARACTER) || (sc.ch == '\"' && sc.state == SCE_ZIG_STRING)) {
} else if ((sc.ch == '\'' && sc.state == SCE_ZIG_CHARACTER) ||
(sc.ch == '\"' && (sc.state == SCE_ZIG_STRING || sc.state == SCE_ZIG_IDENTIFIER_STRING))) {
sc.ForwardSetState(SCE_ZIG_DEFAULT);
} else if (sc.state != SCE_ZIG_CHARACTER) {
if (sc.ch == '{' || sc.ch == '}') {
if (sc.ch == sc.chNext) {
escSeq.resetEscapeState(sc.state);
sc.SetState(SCE_ZIG_ESCAPECHAR);
sc.Forward();
}
}
}
break;

Expand Down Expand Up @@ -373,6 +368,9 @@ void LexerZig::Lex(Sci_PositionU startPos, Sci_Position lengthDoc, int initStyle
sc.SetState(SCE_ZIG_NUMBER);
} else if ((sc.ch == '@' && IsIdentifierStartEx(sc.chNext)) || IsIdentifierStartEx(sc.ch)) {
sc.SetState((sc.ch == '@') ? SCE_ZIG_BUILTIN_FUNCTION : SCE_ZIG_IDENTIFIER);
} else if (sc.ch == '@' && sc.chNext == '"') {
sc.SetState(SCE_ZIG_IDENTIFIER_STRING);
sc.Forward();
} else if (IsAGraphic(sc.ch)) {
sc.SetState(SCE_ZIG_OPERATOR);
}
Expand Down
13 changes: 13 additions & 0 deletions test/examples/zig/AllStyles.zig
Original file line number Diff line number Diff line change
Expand Up @@ -275,3 +275,16 @@ const optional_value: ?i32 = null;
//! This module provides functions for retrieving the current date and
//! time with varying degrees of precision and accuracy. It does not
//! depend on libc, but will use functions from it if available.

const @"identifier with spaces in it" = 0xff;
const @"1SmallStep4Man" = 112358;

const c = @import("std").c;
pub extern "c" fn @"error"() void;
pub extern "c" fn @"fstat$INODE64"(fd: c.fd_t, buf: *c.Stat) c_int;

const Color = enum {
red,
@"really red",
};
const color: Color = .@"really red";
13 changes: 13 additions & 0 deletions test/examples/zig/AllStyles.zig.folded
Original file line number Diff line number Diff line change
Expand Up @@ -275,4 +275,17 @@
2 400 401 + //! This module provides functions for retrieving the current date and
0 401 401 | //! time with varying degrees of precision and accuracy. It does not
0 401 400 | //! depend on libc, but will use functions from it if available.
0 400 400
0 400 400 const @"identifier with spaces in it" = 0xff;
0 400 400 const @"1SmallStep4Man" = 112358;
0 400 400
0 400 400 const c = @import("std").c;
0 400 400 pub extern "c" fn @"error"() void;
0 400 400 pub extern "c" fn @"fstat$INODE64"(fd: c.fd_t, buf: *c.Stat) c_int;
0 400 400
2 400 401 + const Color = enum {
0 401 401 | red,
0 401 401 | @"really red",
0 401 400 | };
0 400 400 const color: Color = .@"really red";
0 400 0
13 changes: 13 additions & 0 deletions test/examples/zig/AllStyles.zig.styled
Original file line number Diff line number Diff line change
Expand Up @@ -275,3 +275,16 @@
{3}//! This module provides functions for retrieving the current date and
//! time with varying degrees of precision and accuracy. It does not
//! depend on libc, but will use functions from it if available.
{0}
{13}const{0} {17}@"identifier with spaces in it"{0} {5}={0} {4}0xff{5};{0}
{13}const{0} {17}@"1SmallStep4Man"{0} {5}={0} {4}112358{5};{0}

{13}const{0} {10}c{0} {5}={0} {12}@import{5}({7}"std"{5}).{10}c{5};{0}
{13}pub{0} {13}extern{0} {7}"c"{0} {13}fn{0} {17}@"error"{5}(){0} {11}void{5};{0}
{13}pub{0} {13}extern{0} {7}"c"{0} {13}fn{0} {17}@"fstat$INODE64"{5}({11}fd{5}:{0} {10}c{5}.{10}fd_t{5},{0} {10}buf{5}:{0} {5}*{10}c{5}.{10}Stat{5}){0} {10}c_int{5};{0}

{13}const{0} {10}Color{0} {5}={0} {13}enum{0} {5}{{0}
{10}red{5},{0}
{17}@"really red"{5},{0}
{5}};{0}
{13}const{0} {10}color{5}:{0} {10}Color{0} {5}={0} {5}.{17}@"really red"{5};{0}

0 comments on commit 942ac3f

Please sign in to comment.