Skip to content
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] Strict special parameter highlighting #184

Closed
zufuliu opened this issue Jul 14, 2023 · 4 comments
Closed

[Bash] Strict special parameter highlighting #184

zufuliu opened this issue Jul 14, 2023 · 4 comments
Labels
bash Caused by the bash lexer committed Issue fixed in repository but not in release

Comments

@zufuliu
Copy link
Contributor

zufuliu commented Jul 14, 2023

Current code treat all punctuation and white spaces as single character special parameter that will case bugs, like the one reported at zufuliu/notepad4#684:
image

*, @, #, ?, -, $, ! are supported in bash, zsh, dash, and ksh; tcsh adds% and < (highlight $< seems will cause other bug).

A simple fix is adding extra check after scalar has no delimiter pair comment:

// `setParam` will be replaced with `IsBashParameter()`.
if (!IsBashParameter(sc.chNext) && !IsSpecialParameter(sc.chNext)) {
	stylingInside = false;
}

lexilla/lexers/LexBash.cxx

Lines 362 to 368 in 5f0c215

} else {
// scalar has no delimiter pair
}
if (!stylingInside) {
sc.ChangeState(state);
} else {
sc.ChangeState(sc.state | insideCommand);

@zufuliu
Copy link
Contributor Author

zufuliu commented Jul 14, 2023

Another fix is adding

const CharacterSet setParamStart(CharacterSet::setAlphaNum, "\'\"`{[(_*@#?-$!");

if (sc.ch == '$' && setParamStart.Contains(sc.chNext)) {
	QuoteStack.Expand(sc, cmdState, stylingInside);
	continue;	
}

so special parameter list could be configurable.

@nyamatongwe
Copy link
Member

Since the different shells have different choices, using a CharacterSet that could be modified by options appears sensible to me.

@zufuliu
Copy link
Contributor Author

zufuliu commented Jul 16, 2023

The patch, added setParamStart into QuoteStackCls to avoid code duplication.
bash-param-0716.zip

zufuliu added a commit to zufuliu/lexilla that referenced this issue Jul 16, 2023
Added property `lexer.bash.special.parameter` to set custom special parameters.
@zufuliu
Copy link
Contributor Author

zufuliu commented Jul 16, 2023

Uploaded another fix at #186, which added property lexer.bash.special.parameter to set custom special parameters.

nyamatongwe pushed a commit that referenced this issue Jul 17, 2023
Added property `lexer.bash.special.parameter` to set custom special parameters.
@nyamatongwe nyamatongwe added the committed Issue fixed in repository but not in release label Jul 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bash Caused by the bash lexer committed Issue fixed in repository but not in release
Projects
None yet
Development

No branches or pull requests

2 participants