0

I am working on a project with jline version3 in java but in completion, I need to have "else if" but it puts \ to escape space as an escape character and I don't have any escape character also I tried null instead of a char[] but it crashes with null pointer exception

also, I checked https://github.com/jline/jline3/issues/173

Error is:

        at org.jline.reader.impl.DefaultParser$ArgumentList.escape(DefaultParser.java:383)
        at org.jline.reader.impl.LineReaderImpl$MenuSupport.update(LineReaderImpl.java:4403)
        at org.jline.reader.impl.LineReaderImpl$MenuSupport.next(LineReaderImpl.java:4317)
        at org.jline.reader.impl.LineReaderImpl.doMenu(LineReaderImpl.java:4471)
        at org.jline.reader.impl.LineReaderImpl.doList(LineReaderImpl.java:4614)
        at org.jline.reader.impl.LineReaderImpl.doComplete(LineReaderImpl.java:4149)
        at org.jline.reader.impl.LineReaderImpl.expandOrComplete(LineReaderImpl.java:3875)
        at org.jline.reader.impl.LineReaderImpl.readLine(LineReaderImpl.java:585)
        at org.jline.reader.impl.LineReaderImpl.readLine(LineReaderImpl.java:443)
        at REPLReader.readLine(REPLReader.java:99)
        at Compiler.getInputCode(Compiler.java:24)
        at CompilerMain.lex(CompilerMain.java:75)
        at CompilerMain.compile(CompilerMain.java:15)
        at Main.main(Main.java:59)
radinParsaei
  • 28
  • 1
  • 6

1 Answers1

0

I assume that you are using JLine builtin completer StringsCompleter and DefaultParser.

If you have completion candidate that have space character(s) then either

  1. space chars are escaped if defaultParser.escapeChars != null or
  2. completion candidate will be quoted if defaultParser.escapeChars == null.

That is how StringsCompleter is supposed to work. See StringsCompleterTest.java methods: escapeCharsNull() and escapeChars().

NPE is fixed in commit 68a9c1f. You should use JLine version 3.10 or greater.

mattirn
  • 26
  • 4
  • thanks, but I use RegexCompleter, and when I set escape chars to null program crashed with exception added to question you can see REPLReader.java in https://github.com/radinParsaei/Compiler/blob/master/repl/src/main/java/REPLReader.java – radinParsaei Sep 08 '20 at 08:14
  • NPE is fixed in commit [68a9c1f](https://github.com/jline/jline3/commit/8ae798f09d6d409df79f8fbd963784bf068a9c1f). You should use JLine version 3.10 or greater. Inside RegexCompleter you are using StringsCompleter. So in completion spaces are escaped or candidate will be quoted (if escapeChars=null) – mattirn Sep 08 '20 at 10:58
  • I have created a ticket [jline3#567](https://github.com/jline/jline3/issues/567). The fix will be included in the next release. – mattirn Sep 08 '20 at 21:06
  • thank you for your answer, but another question is if I need to remove both of quoting and character escaping because `else if` can't be quoted – radinParsaei Sep 09 '20 at 11:37
  • The next relaese of JLine will work as you requested when you set `parser ` `escapeChars` as an empty `char` array. – mattirn Sep 09 '20 at 12:25