-
Notifications
You must be signed in to change notification settings - Fork 67
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Bash] Highlight ++
, --
( in arithmetic expression) and +=
as operator
#197
Comments
zufuliu
changed the title
[Bash] Highlight
[Bash] Highlight Aug 13, 2023
++
and --
as operator in arithmetic expression++
, --
( in arithmetic expression) and +=
as operator
zufuliu
added a commit
to zufuliu/notepad4
that referenced
this issue
Aug 13, 2023
This change uses @@ -996,7 +996,7 @@ void SCI_METHOD LexerBash::Lex(Sci_PositionU startPos, Sci_Position length, int
}
}
} else if (setWordStart.Contains(sc.ch)) {
- sc.SetState(SCE_SH_WORD | insideCommand);
+ sc.SetState(((cmdState == CmdState::Arithmetic) ? SCE_SH_IDENTIFIER : SCE_SH_WORD) | insideCommand);
} else if (sc.ch == '#') {
if (stylePrev != SCE_SH_WORD && stylePrev != SCE_SH_IDENTIFIER &&
(sc.currentPos == 0 || setMetaCharacter.Contains(sc.chPrev))) {
@@ -1045,7 +1045,11 @@ void SCI_METHOD LexerBash::Lex(Sci_PositionU startPos, Sci_Position length, int
} else if (sc.ch == '-' && // test operator or short and long option
(IsUpperOrLowerCase(sc.chNext) || sc.chNext == '-') &&
IsASpace(sc.chPrev)) {
- sc.SetState(SCE_SH_WORD | insideCommand);
+ if (cmdState == CmdState::Arithmetic && sc.ch == '-') {
+ sc.SetState(SCE_SH_OPERATOR | insideCommand);
+ } else {
+ sc.SetState(SCE_SH_WORD | insideCommand);
+ }
sc.Forward();
} else if (setBashOperator.Contains(sc.ch)) {
bool isCmdDelim = false; |
Try following patch? diff --git a/lexers/LexBash.cxx b/lexers/LexBash.cxx
index d9506690..aab2d7a7 100644
--- a/lexers/LexBash.cxx
+++ b/lexers/LexBash.cxx
@@ -647,7 +647,7 @@ void SCI_METHOD LexerBash::Lex(Sci_PositionU startPos, Sci_Position length, int
break;
case SCE_SH_WORD:
// "." never used in Bash variable names but used in file names
- if (!setWord.Contains(sc.ch)) {
+ if (!setWord.Contains(sc.ch) || sc.Match('+', '=')) {
char s[500];
sc.GetCurrent(s, sizeof(s));
int identifierStyle = SCE_SH_IDENTIFIER | insideCommand;
@@ -996,7 +996,7 @@ void SCI_METHOD LexerBash::Lex(Sci_PositionU startPos, Sci_Position length, int
}
}
} else if (setWordStart.Contains(sc.ch)) {
- sc.SetState(SCE_SH_WORD | insideCommand);
+ sc.SetState(((cmdState == CmdState::Arithmetic)? SCE_SH_IDENTIFIER : SCE_SH_WORD) | insideCommand);
} else if (sc.ch == '#') {
if (stylePrev != SCE_SH_WORD && stylePrev != SCE_SH_IDENTIFIER &&
(sc.currentPos == 0 || setMetaCharacter.Contains(sc.chPrev))) {
@@ -1043,6 +1043,7 @@ void SCI_METHOD LexerBash::Lex(Sci_PositionU startPos, Sci_Position length, int
HereDoc.Indent = false;
}
} else if (sc.ch == '-' && // test operator or short and long option
+ cmdState != CmdState::Arithmetic &&
(IsUpperOrLowerCase(sc.chNext) || sc.chNext == '-') &&
IsASpace(sc.chPrev)) {
sc.SetState(SCE_SH_WORD | insideCommand); |
Similar to issue #203, arithmetic expression can span multilines without line continuation. echo $((2
- 1))
echo $[2
- 1]
for ((i = 0; i < 2;
i++)); do
echo postfix inc $i
done
for ((i = 1; i < 4;
i<<=1)); do
echo postfix inc $i
done diff --git a/lexers/LexBash.cxx b/lexers/LexBash.cxx
index 647cc262..47e4a54a 100644
--- a/lexers/LexBash.cxx
+++ b/lexers/LexBash.cxx
@@ -662,7 +662,7 @@ void SCI_METHOD LexerBash::Lex(Sci_PositionU startPos, Sci_Position length, int
// handle line continuation, updates per-line stored state
if (sc.atLineStart) {
CmdState state = CmdState::Body; // force backtrack while retaining cmdState
- if (!StyleForceBacktrack(MaskCommand(sc.state))) {
+ if (!StyleForceBacktrack(MaskCommand(sc.state)) && !AnyOf(cmdState, CmdState::Arithmetic)) {
if (!QuoteStack.lineContinuation) { // retain last line's state
cmdState = CmdState::Start;
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
test case:
The text was updated successfully, but these errors were encountered: