Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Dart: Add error state for unterminated string
  • Loading branch information
techee committed May 13, 2025
commit d771b88d2e12c06a711da08bf4045cc9dc87588e
1 change: 1 addition & 0 deletions include/LexicalStyles.iface
Original file line number Diff line number Diff line change
Expand Up @@ -2409,6 +2409,7 @@ val SCE_DART_KW_PRIMARY=23
val SCE_DART_KW_SECONDARY=24
val SCE_DART_KW_TERTIARY=25
val SCE_DART_KW_TYPE=26
val SCE_DART_STRINGEOL=27
# Lexical states for SCLEX_ZIG
lex Zig=SCLEX_ZIG SCE_ZIG_
val SCE_ZIG_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 @@ -2151,6 +2151,7 @@
#define SCE_DART_KW_SECONDARY 24
#define SCE_DART_KW_TERTIARY 25
#define SCE_DART_KW_TYPE 26
#define SCE_DART_STRINGEOL 27
#define SCE_ZIG_DEFAULT 0
#define SCE_ZIG_COMMENTLINE 1
#define SCE_ZIG_COMMENTLINEDOC 2
Expand Down
13 changes: 13 additions & 0 deletions lexers/LexDart.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ LexicalClass lexicalClasses[] = {
24, "SCE_DART_KW_SECONDARY", "identifier", "Secondary keywords",
25, "SCE_DART_KW_TERTIARY", "identifier", "Tertiary keywords",
26, "SCE_DART_KW_TYPE", "identifier", "Global types",
27, "SCE_DART_STRINGEOL", "error literal string", "End of line where string is not closed",
};

class LexerDart : public DefaultLexer {
Expand Down Expand Up @@ -342,6 +343,10 @@ void LexerDart::Lex(Sci_PositionU startPos, Sci_Position lengthDoc, int initStyl
int chPrevNonWhite = 0;
EscapeSequence escSeq;

if (initStyle == SCE_DART_STRINGEOL) {
initStyle = SCE_DART_DEFAULT;
}

if (startPos != 0) {
// backtrack to the line where interpolation starts
BacktrackToStart(styler, DartLineStateMaskInterpolation, startPos, lengthDoc, initStyle);
Expand Down Expand Up @@ -457,6 +462,8 @@ void LexerDart::Lex(Sci_PositionU startPos, Sci_Position lengthDoc, int initStyl
case SCE_DART_TRIPLE_RAWSTRING_DQ:
if (sc.atLineStart && !IsTripleString(sc.state)) {
sc.SetState(SCE_DART_DEFAULT);
} else if (sc.atLineEnd && !IsTripleString(sc.state)) {
sc.ChangeState(SCE_DART_STRINGEOL);
} else if (sc.ch == '\\' && !IsRaw(sc.state)) {
if (escSeq.resetEscapeState(sc.state, sc.chNext)) {
sc.SetState(SCE_DART_ESCAPECHAR);
Expand Down Expand Up @@ -489,6 +496,12 @@ void LexerDart::Lex(Sci_PositionU startPos, Sci_Position lengthDoc, int initStyl
}
break;

case SCE_DART_STRINGEOL:
if (sc.atLineStart) {
sc.SetState(SCE_DART_DEFAULT);
}
break;

case SCE_DART_ESCAPECHAR:
if (escSeq.atEscapeEnd(sc.ch)) {
if (escSeq.brace && sc.ch == '}') {
Expand Down
5 changes: 5 additions & 0 deletions test/examples/dart/AllStyles.dart
Original file line number Diff line number Diff line change
Expand Up @@ -332,3 +332,8 @@ var s3 = """multi-line
${x}
strings
""";

var s1 = 'Unterminated string;
var s2 = "Unterminated string;
var s3 = r'Unterminated raw string;
var s4 = r'Unterminated raw string;
5 changes: 5 additions & 0 deletions test/examples/dart/AllStyles.dart.folded
Original file line number Diff line number Diff line change
Expand Up @@ -332,4 +332,9 @@
0 401 401 | ${x}
0 401 401 | strings
0 401 400 | """;
0 400 400
0 400 400 var s1 = 'Unterminated string;
0 400 400 var s2 = "Unterminated string;
0 400 400 var s3 = r'Unterminated raw string;
0 400 400 var s4 = r'Unterminated raw string;
0 400 0
5 changes: 5 additions & 0 deletions test/examples/dart/AllStyles.dart.styled
Original file line number Diff line number Diff line change
Expand Up @@ -332,3 +332,8 @@ strings
{17}${{14}x{17}}{8}
strings
"""{16};{0}

{23}var{0} {14}s1{0} {16}={0} {27}'Unterminated string;
{23}var{0} {14}s2{0} {16}={0} {27}"Unterminated string;
{23}var{0} {14}s3{0} {16}={0} {27}r'Unterminated raw string;
{23}var{0} {14}s4{0} {16}={0} {27}r'Unterminated raw string;