Skip to content

Commit

Permalink
[TOML] Fix quoted key and inline table key highlighting.
Browse files Browse the repository at this point in the history
  • Loading branch information
zufuliu committed Jan 19, 2024
1 parent 7a72f1f commit 24afa81
Showing 1 changed file with 21 additions and 18 deletions.
39 changes: 21 additions & 18 deletions scintilla/lexers/LexTOML.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ void ColouriseTOMLDoc(Sci_PositionU startPos, Sci_Position lengthDoc, int initSt
if (IsISODateTime(sc.ch, sc.chNext)) {
sc.ChangeState(SCE_TOML_DATETIME);
} else if (IsTOMLKey(sc, braceCount, nullptr)) {
keyState = TOMLKeyState::Unquoted;
continue;
}
}
Expand All @@ -146,6 +147,7 @@ void ColouriseTOMLDoc(Sci_PositionU startPos, Sci_Position lengthDoc, int initSt
case SCE_TOML_DATETIME:
if (!(IsIdentifierChar(sc.ch) || IsISODateTime(sc.ch, sc.chNext))) {
if (IsTOMLKey(sc, braceCount, nullptr)) {
keyState = TOMLKeyState::Unquoted;
continue;
}
}
Expand All @@ -154,6 +156,7 @@ void ColouriseTOMLDoc(Sci_PositionU startPos, Sci_Position lengthDoc, int initSt
case SCE_TOML_IDENTIFIER:
if (!IsIdentifierChar(sc.ch)) {
if (IsTOMLKey(sc, braceCount, &keywordLists[0])) {
keyState = TOMLKeyState::Unquoted;
continue;
}
}
Expand All @@ -167,16 +170,16 @@ void ColouriseTOMLDoc(Sci_PositionU startPos, Sci_Position lengthDoc, int initSt
switch (keyState) {
case TOMLKeyState::Literal:
if (sc.ch == '\'') {
sc.Forward();
keyState = TOMLKeyState::Unquoted;
sc.Forward();
}
break;
case TOMLKeyState::Quoted:
if (sc.ch == '\\') {
sc.Forward();
} else if (sc.ch == '\"') {
sc.Forward();
keyState = TOMLKeyState::Unquoted;
sc.Forward();
}
break;
default:
Expand All @@ -188,11 +191,13 @@ void ColouriseTOMLDoc(Sci_PositionU startPos, Sci_Position lengthDoc, int initSt
} else if (sc.ch == '\"') {
keyState = TOMLKeyState::Quoted;
} else if (sc.ch == '.') {
if (sc.state == SCE_TOML_KEY) {
if (sc.state == SCE_TOML_TABLE) {
++tableLevel;
} else {
sc.SetState(SCE_TOML_OPERATOR);
sc.ForwardSetState(SCE_TOML_KEY);
} else {
++tableLevel;
// TODO: skip space after dot
continue;
}
} else if (sc.state == SCE_TOML_KEY && sc.ch == '=') {
keyState = TOMLKeyState::End;
Expand Down Expand Up @@ -235,6 +240,7 @@ void ColouriseTOMLDoc(Sci_PositionU startPos, Sci_Position lengthDoc, int initSt
}
sc.Forward();
if (!IsTripleString(sc.state) && IsTOMLKey(sc, braceCount, nullptr)) {
keyState = TOMLKeyState::Unquoted;
continue;
}
sc.SetState(SCE_TOML_DEFAULT);
Expand Down Expand Up @@ -267,11 +273,13 @@ void ColouriseTOMLDoc(Sci_PositionU startPos, Sci_Position lengthDoc, int initSt
}

if (sc.state == SCE_TOML_DEFAULT) {
if (visibleChars == 0 && !braceCount) {
if (sc.ch == '#') {
sc.SetState(SCE_TOML_COMMENT);
if (sc.ch == '#') {
sc.SetState(SCE_TOML_COMMENT);
if (visibleChars == 0) {
lineType = TOMLLineType::CommentLine;
} else if (sc.ch == '[') {
}
} else if (visibleChars == 0 && braceCount == 0) {
if (sc.ch == '[') {
tableLevel = 0;
sc.SetState(SCE_TOML_TABLE);
if (sc.chNext == '[') {
Expand All @@ -280,22 +288,17 @@ void ColouriseTOMLDoc(Sci_PositionU startPos, Sci_Position lengthDoc, int initSt
keyState = TOMLKeyState::Unquoted;
lineType = TOMLLineType::Table;
} else if (sc.ch == '\'' || sc.ch == '\"') {
sc.SetState(SCE_TOML_KEY);
keyState = (sc.ch == '\'')? TOMLKeyState::Literal : TOMLKeyState::Quoted;
} else if (IsTOMLUnquotedKey(sc.ch)) {
sc.SetState(SCE_TOML_KEY);
} else if (IsTOMLUnquotedKey(sc.ch)) {
keyState = TOMLKeyState::Unquoted;
sc.SetState(SCE_TOML_KEY);
} else if (!isspacechar(sc.ch)) {
// each line must be: key = value
sc.SetState(SCE_TOML_ERROR);
}
} else {
if (sc.ch == '#') {
sc.SetState(SCE_TOML_COMMENT);
if (visibleChars == 0) {
lineType = TOMLLineType::CommentLine;
}
} else if (sc.ch == '\'') {
if (sc.ch == '\'') {
if (sc.MatchNext('\'', '\'')) {
sc.SetState(SCE_TOML_TRIPLE_STRING_SQ);
sc.Advance(2);
Expand All @@ -320,8 +323,8 @@ void ColouriseTOMLDoc(Sci_PositionU startPos, Sci_Position lengthDoc, int initSt
}
} else if (braceCount && IsTOMLUnquotedKey(sc.ch)) {
// Inline Table
sc.SetState(SCE_TOML_KEY);
keyState = TOMLKeyState::Unquoted;
sc.SetState(SCE_TOML_KEY);
}
}
}
Expand Down

1 comment on commit 24afa81

@lifenjoiner
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great! You noticed the the bug on inline tables and fixed it. I don’t have to keep working on it.

Please sign in to comment.