Skip to content

Commit 99200ed

Browse files
techeenyamatongwe
authored andcommitted
#315 Zig: Add error state for unterminated string
1 parent df885ca commit 99200ed

File tree

7 files changed

+31
-0
lines changed

7 files changed

+31
-0
lines changed

doc/LexillaHistory.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -613,6 +613,10 @@ <h3>
613613
TOML: Add error state SCE_TOML_STRINGEOL for unterminated string.
614614
<a href="https://github.com/ScintillaOrg/lexilla/pull/315">Pull request #315</a>.
615615
</li>
616+
<li>
617+
Zig: Add error state SCE_ZIG_STRINGEOL for unterminated string.
618+
<a href="https://github.com/ScintillaOrg/lexilla/pull/315">Pull request #315</a>.
619+
</li>
616620
</ul>
617621
<h3>
618622
<a href="https://www.scintilla.org/lexilla544.zip">Release 5.4.4</a>

include/LexicalStyles.iface

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2430,6 +2430,7 @@ val SCE_ZIG_KW_SECONDARY=14
24302430
val SCE_ZIG_KW_TERTIARY=15
24312431
val SCE_ZIG_KW_TYPE=16
24322432
val SCE_ZIG_IDENTIFIER_STRING=17
2433+
val SCE_ZIG_STRINGEOL=18
24332434
# Lexical states for SCLEX_NIX
24342435
lex Nix=SCLEX_NIX SCE_NIX_
24352436
val SCE_NIX_DEFAULT=0

include/SciLexer.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2170,6 +2170,7 @@
21702170
#define SCE_ZIG_KW_TERTIARY 15
21712171
#define SCE_ZIG_KW_TYPE 16
21722172
#define SCE_ZIG_IDENTIFIER_STRING 17
2173+
#define SCE_ZIG_STRINGEOL 18
21732174
#define SCE_NIX_DEFAULT 0
21742175
#define SCE_NIX_COMMENTLINE 1
21752176
#define SCE_NIX_COMMENTBLOCK 2

lexers/LexZig.cxx

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ LexicalClass lexicalClasses[] = {
163163
15, "SCE_ZIG_KW_TERTIARY", "identifier", "Tertiary keywords",
164164
16, "SCE_ZIG_KW_TYPE", "identifier", "Global types",
165165
17, "SCE_ZIG_IDENTIFIER_STRING", "identifier", "Identifier using @\"\" syntax",
166+
18, "SCE_ZIG_STRINGEOL", "error literal string", "End of line where string is not closed",
166167
};
167168

168169
class LexerZig : public DefaultLexer {
@@ -262,6 +263,10 @@ void LexerZig::Lex(Sci_PositionU startPos, Sci_Position lengthDoc, int initStyle
262263
int lineState = 0;
263264
EscapeSequence escSeq;
264265

266+
if (initStyle == SCE_ZIG_STRINGEOL) {
267+
initStyle = SCE_ZIG_DEFAULT;
268+
}
269+
265270
StyleContext sc(startPos, lengthDoc, initStyle, styler);
266271

267272
while (sc.More()) {
@@ -311,6 +316,8 @@ void LexerZig::Lex(Sci_PositionU startPos, Sci_Position lengthDoc, int initStyle
311316
case SCE_ZIG_IDENTIFIER_STRING:
312317
if (sc.atLineStart) {
313318
sc.SetState(SCE_ZIG_DEFAULT);
319+
} else if (sc.atLineEnd && sc.state != SCE_ZIG_MULTISTRING) {
320+
sc.ChangeState(SCE_ZIG_STRINGEOL);
314321
} else if (sc.ch == '\\' && sc.state != SCE_ZIG_MULTISTRING) {
315322
escSeq.resetEscapeState(sc.state, sc.chNext);
316323
sc.SetState(SCE_ZIG_ESCAPECHAR);
@@ -326,6 +333,12 @@ void LexerZig::Lex(Sci_PositionU startPos, Sci_Position lengthDoc, int initStyle
326333
}
327334
break;
328335

336+
case SCE_ZIG_STRINGEOL:
337+
if (sc.atLineStart) {
338+
sc.SetState(SCE_ZIG_DEFAULT);
339+
}
340+
break;
341+
329342
case SCE_ZIG_ESCAPECHAR:
330343
if (escSeq.atEscapeEnd(sc.ch)) {
331344
if (escSeq.brace && sc.ch == '}') {

test/examples/zig/AllStyles.zig

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,3 +288,7 @@ const Color = enum {
288288
@"really red",
289289
};
290290
const color: Color = .@"really red";
291+
292+
const s1 = "Unterminated string
293+
const s2 = 'Unterminated character
294+
const s3 = @"Unterminated identifier string

test/examples/zig/AllStyles.zig.folded

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,4 +288,8 @@
288288
0 401 401 | @"really red",
289289
0 401 400 | };
290290
0 400 400 const color: Color = .@"really red";
291+
0 400 400
292+
0 400 400 const s1 = "Unterminated string
293+
0 400 400 const s2 = 'Unterminated character
294+
0 400 400 const s3 = @"Unterminated identifier string
291295
0 400 0

test/examples/zig/AllStyles.zig.styled

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,3 +288,7 @@
288288
{17}@"really red"{5},{0}
289289
{5}};{0}
290290
{13}const{0} {10}color{5}:{0} {10}Color{0} {5}={0} {5}.{17}@"really red"{5};{0}
291+
292+
{13}const{0} {10}s1{0} {5}={0} {18}"Unterminated string
293+
{13}const{0} {10}s2{0} {5}={0} {18}'Unterminated character
294+
{13}const{0} {10}s3{0} {5}={0} {18}@"Unterminated identifier string

0 commit comments

Comments
 (0)