-
Notifications
You must be signed in to change notification settings - Fork 60
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 nested quotes and shell expansions #154
Comments
First change, add |
… Remove inline. Separate variable declarations. Remove unnecessary destructors. Assign more type-specific literals. Include C++ headers.
Looks good. Changed order of includes to match |
scoped enumeration changes: |
Extend unnamed namespace to cover all declarations.
Added in Started working on nested and multi-line tests but am not sure which tests are good. Here is the current state: # Nested elements
# String with backtick inclusion
"x`ls`"
# Nested string
"x`ls "*.c"`"
# Not terminated at first "
"x`ls" # "`" #
# String with command inclusion
"x$(ls)"
# Nested command
$(ls -la$(ls *.c))
# Check strings and backticks in command
$('x' "x" `ls` $'x' $"x")
# $( not terminated by ) if contains unterminated string
$('x) # ') #
$("x) # ") #
$(`x) # `) #
$($'x) # ') #
$($"x) # ") #
# Multi-line
$(ls |
more)
$(
`x`
"x"
`ls`
$'x'
$"x"
)
#end -- checks termination of previous |
There also needs a test for parameter expansion: var=abcdef
sub=abc
rep='& '
echo ${var/$sub/"${rep}}"} # Change |
Remove |
Move out |
|
|
QuoteStack.Up can only be in { '(', '{', '"', '\'', '`'}, never '\\'.
Merge QuoteCls::open into QuoteCls::Start as its only called from Start.
Change for loop to while loop, new test case: echo $?Status |
This seems a bit heavy to just avoid the The code could be changed to check that @@ -856,6 +856,10 @@ void SCI_METHOD LexerBash::Lex(Sci_PositionU startPos, Sci_Position length, int
continue;
}
sc.SetState(SCE_SH_SCALAR);
+ if (!AnyOf(sc.chNext, '{', '\'', '\"', '(', '`')) {
+ // scalar has no delimiter pair
+ continue;
+ }
sc.Forward();
if (sc.ch == '{') {
sc.ChangeState(SCE_SH_PARAM);
@@ -872,8 +876,6 @@ void SCI_METHOD LexerBash::Lex(Sci_PositionU startPos, Sci_Position length, int
} else if (sc.ch == '`') { // $` seen in a configure script, valid?
sc.ChangeState(SCE_SH_BACKTICKS);
QuoteStack.Start(sc.ch, QuoteStyle::Backtick);
- } else {
- continue; // scalar has no delimiter pair
}
} else if (sc.Match('<', '<')) {
sc.SetState(SCE_SH_HERE_DELIM); |
OK I think convert for loop to while is still needed, current code for handling nested highlighting: case SCE_SH_STRING_DQ: // delimited styles, can nest
case SCE_SH_PARAM: // ${parameter}
case SCE_SH_BACKTICKS:
if (sc.ch == '\\') {
sc.Forward();
} else if (sc.ch == QuoteStack.Current.Down) {
if (QuoteStack.CountDown(sc, cmdState)) {
continue;
}
} else if (sc.ch == QuoteStack.Current.Up) {
QuoteStack.Current.Count++;
} else { and if (Current.Count == 0) {
cmdState = CmdState::Body;
const int outer = Current.Outer;
if (Depth > 0) {
Pop();
} else {
Clear();
}
sc.ForwardSetState(outer);
return true;
} |
Whole code block for } else if (sc.ch == '$') {
QuoteStack.Expand(sc, cmdState);
continue; |
Implement nested highlighting, new test case: echo "$((1 + 2))" #
echo "$[1 + 2]" # |
The However, I don't think this feature will be universally wanted, including by myself and the original lexer author Kein-Hong Man. For me, its highlighting smaller elements that I am less interested in most of the time, similar to highlighting escape sequences in C++ strings which I turn off. This new behaviour should be a choice although it may not be just a binary choice - some may want more fine-grained styling inside |
OK, then need to add property for each nested quote style + scalar variable, and what would the property names? |
I'm unsure whether or not the multiple settings is required but I'm fairly sure at least one is. It could start with a single option and grow to a full set when there is demand or it seems worthwhile. Perhaps a single If there are multiple settings they should match the class name or the element name in bash documentation |
|
Added |
Controlled with properties "lexer.bash.styling.inside.string", "lexer.bash.styling.inside.backticks", and "lexer.bash.styling.inside.parameter". https://sourceforge.net/p/scintilla/feature-requests/1033/
Committed with an added Duplicated |
Use |
Simplify preview patch. |
Implement nested highlighting inside here document, new test case (undocumented at https://www.gnu.org/software/bash/manual/bash.html#Here-Documents, but same behavior as Perl when there are backslash inside delimiter): cat <<-\EOF
$((1+2))
`date`
$(date)
EOF |
Previous patch has bugs when cat <<EOF
heredoc line 1
$(echo \
EOF
)
heredoc line 3
EOF
echo $(cat <<'EOF'
heredoc line 1
$(echo \
EOF
)
#
|
If its undocumented, where is the need coming from? |
it's common in configure script, e.g. there 20 Add |
Moved |
Change the code to use |
With this It really is worthwhile running the tests after making a change.
|
test failure caused by |
Another fix to not do the magic call |
lexer.bash.styling.inside.heredoc set.
Also ensured initialization to avoid warnings with d56956e. |
…and ")" as operators and interior styled as bash code. Controlled with property lexer.bash.command.substitution.
Included in release 5.2.5. |
This is a big change, I would like to spit it as following small changes:
noexcept
and clang-tidy suggested changes.BASH_CMD_*
andBASH_DELIM_*
macros into scoped enumeration.${}
same as backticks on handling nested quotes and shell expansions, as the document says:QuoteCls Quote;
variable as single quoted string has no inner states.QuoteStackCls
definition, and change it to useQuoteCls
array as stack.$?1
highlighted as variable instead of just$?
.$()
command substitution still colored asSCE_SH_BACKTICKS
.case SCE_SH_HERE_Q
by usingsc.Match()
to match the delimiter.The text was updated successfully, but these errors were encountered: