From 942ac3fed715116b1fd83dce4f04cd0eb70d4856 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ji=C5=99=C3=AD=20Techet?= Date: Tue, 5 Nov 2024 08:08:50 +1100 Subject: [PATCH] #287 Add SCE_ZIG_IDENTIFIER_STRING for identifiers expressed as strings. See https://ziglang.org/documentation/0.13.0/#Identifiers --- doc/LexillaHistory.html | 4 ++++ include/LexicalStyles.iface | 1 + include/SciLexer.h | 1 + lexers/LexZig.cxx | 16 +++++++--------- test/examples/zig/AllStyles.zig | 13 +++++++++++++ test/examples/zig/AllStyles.zig.folded | 13 +++++++++++++ test/examples/zig/AllStyles.zig.styled | 13 +++++++++++++ 7 files changed, 52 insertions(+), 9 deletions(-) diff --git a/doc/LexillaHistory.html b/doc/LexillaHistory.html index 08855e44..c0076ee9 100644 --- a/doc/LexillaHistory.html +++ b/doc/LexillaHistory.html @@ -614,6 +614,10 @@ TOML: Don't treat keys without values as errors. Pull request #283. +
  • + Zig: Add SCE_ZIG_IDENTIFIER_STRING for identifiers expressed as strings. + Pull request #287. +
  • Release 5.4.1 diff --git a/include/LexicalStyles.iface b/include/LexicalStyles.iface index 38151474..cdd3085a 100644 --- a/include/LexicalStyles.iface +++ b/include/LexicalStyles.iface @@ -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 diff --git a/include/SciLexer.h b/include/SciLexer.h index b9a89f56..496bbf2c 100644 --- a/include/SciLexer.h +++ b/include/SciLexer.h @@ -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 diff --git a/lexers/LexZig.cxx b/lexers/LexZig.cxx index b262fee2..a2e14684 100644 --- a/lexers/LexZig.cxx +++ b/lexers/LexZig.cxx @@ -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 { @@ -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) { @@ -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; @@ -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); } diff --git a/test/examples/zig/AllStyles.zig b/test/examples/zig/AllStyles.zig index 53a221fc..04685347 100644 --- a/test/examples/zig/AllStyles.zig +++ b/test/examples/zig/AllStyles.zig @@ -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"; diff --git a/test/examples/zig/AllStyles.zig.folded b/test/examples/zig/AllStyles.zig.folded index 602db1f6..30bff04a 100644 --- a/test/examples/zig/AllStyles.zig.folded +++ b/test/examples/zig/AllStyles.zig.folded @@ -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 \ No newline at end of file diff --git a/test/examples/zig/AllStyles.zig.styled b/test/examples/zig/AllStyles.zig.styled index 67afab7c..853f3c13 100644 --- a/test/examples/zig/AllStyles.zig.styled +++ b/test/examples/zig/AllStyles.zig.styled @@ -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}