-
Notifications
You must be signed in to change notification settings - Fork 220
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
Fix parse error of system default /usr/share/nano/*.nanorc
#1157
base: master
Are you sure you want to change the base?
Conversation
@snazy, I think we should do a more general fix rather than start to resolve patterns one by one. In java regex characters [ and ] must be always escaped in a bracket expression. In POSIX regex [ character can be added in a bracket expression without escaping. Also ] character can be added without escaping if it is the first character of the bracket expression. We can add a static method |
Wonder whether this gets into parsing the regex itself. However, do you think its good enough to handle the cases that the |
Regexes in nanorc-files follow POSIX standard. Intersections (
In regex the first unescaped '[' starts a bracket expression. In POSIX a bracket expression is closed by unescaped ']' if it is not the next character after '[' which started the bracket expression. Every square bracket between the starting and closing brackets must be escaped in order to obtain valid java pattern. |
4e472b9
to
46280b7
Compare
/usr/share/nano/json.nanorc
/usr/share/nano/*.nanorc
Okay, I think I have it now. There are quite some more cases that needed to be handled. I've added real world test cases for those - all escapings yielded by |
2c9df3b
to
4d62902
Compare
builtins/src/main/java/org/jline/builtins/SyntaxHighlighter.java
Outdated
Show resolved
Hide resolved
builtins/src/main/java/org/jline/builtins/SyntaxHighlighter.java
Outdated
Show resolved
Hide resolved
(Recent) `nano` packages in Ubuntu come with some `.nanorc` files preinstalled. jline's `NanorcParser` sadly fails parsing a couple of the regular expressions. This change translates the regular expressions to Java regular expressions. The differences are described in `org.jline.builtins.SyntaxHighlighter#posixToJavaRegex`: * The first `]` in a bracket expression does not need to be escaped in Posix,translate to `\]`. * Same as above for a negating bracket expression like `[^][]`, translate to `[^\]\[]`. * Any `[` in a bracket expression does not need to be escaped in Posix, translate to `\[`. * Any `]` not in a bracket expression is valid in both Posix and Java, no translation. * A backslash before the closing bracket like `[.f\]` is not an escape of the closing bracket, the backslash needs to be escaped for Java, translate to `[.f\\]`. * Do not perform the above translations within an escape via `\`. * Do not perform the above translations for Posix "classes" like `[[:word:]]` or `[[:digit:]]` and their negation `[-[:word]]`. * Do not perform the above translations for single-bracket Posix classes like `[:digit:]`, and handle the case of single-bracket Posix classes inside bracket expressions, like `[[:digit:]-.]`. Test cases have been added. There are however two regexes that still don't work, but those look invalid. To let jnano not trip over these, any `PatternSyntaxException` lets jnano just ignore the particular rule. A warning is logged in such cases. Fixes jline#1156
Pull functionality (`\<`/`\>` and posix class translation) of previous `fixRegexes` into the new one. Added a "test" (it just parses and prints) to process all locally installed `.nanorc` files. Adopted existing tests using the previous `fixRegexes` function. Fixed the wrong handling in the previous commit of Posix classes in bracket expressions.
4d62902
to
6c26cf7
Compare
Updated the PR quite a bit in the 2nd commit. Looking at the regexes and source rules printed by the |
c7bf80c
to
1ba7439
Compare
(Recent)
nano
packages in Ubuntu come with some.nanorc
files preinstalled.jline's
NanorcParser
sadly fails parsing a couple of the regular expressions.This change translates the regular expressions to Java regular expressions.
The differences are described in
org.jline.builtins.SyntaxHighlighter#posixToJavaRegex
:]
in a bracket expression does not need to be escaped in Posix,translate to\]
.[^][]
, translate to[^\]\[]
.[
in a bracket expression does not need to be escaped in Posix, translate to\[
.]
not in a bracket expression is valid in both Posix and Java, no translation.[.f\]
is not an escape of the closing bracket, the backslash needs to be escaped for Java, translate to[.f\\]
.\
, except for\<
and\>
to\b
.[:word:]
or[:digit:]
to Java classes, inside and outside a bracket expression.Test cases have been added.
There are however two regexes that still don't work, but those look invalid. To let jnano not trip over these, any
PatternSyntaxException
lets jnano just ignore the particular rule. A warning is logged in such cases.Fixes #1156