jline在自动补全中出现转义字符的问题

huangapple go评论83阅读模式
英文:

jline problems with escape character in completion

问题

以下是您提供的内容的翻译部分:

我正在使用Java中的jline version3进行项目开发,但在完成时,我需要使用“else if”,但它将\用作转义空格的转义字符,而我没有任何转义字符,我还尝试过将null替换为char[],但它会崩溃并出现空指针异常。

另外,我查看了https://github.com/jline/jline3/issues/173

错误内容如下:

        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)
英文:

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)

答案1

得分: 0

我假设您正在使用JLine内置的StringsCompleterDefaultParser作为自动补全功能。

如果您的自动补全候选包含空格字符,则:

  1. 如果defaultParser.escapeChars != null,则空格字符将被转义;
    或者
  2. 如果defaultParser.escapeChars == null,则自动补全候选将被引用。

这就是StringsCompleter的工作原理。
请参阅StringsCompleterTest.java中的方法:escapeCharsNull()escapeChars()

空指针异常(NPE)在提交68a9c1f中已修复。您应该使用JLine版本3.10或更高版本。

英文:

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.

huangapple
  • 本文由 发表于 2020年9月6日 02:40:10
  • 转载请务必保留本文链接:https://go.coder-hub.com/63757353.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定