Groovy:这个“Hello World”出了什么问题?程序? [英] Groovy: What's wrong with this "Hello World" program?
问题描述
$ groovy -e'printlnHello,world!'
org .codehaus.groovy.control.MultipleCompilationErrorsException:启动失败:
script_from_command_line:1:意外char:0xFFFF @第1行,第23列。
printlnHello,world!
^
1错误
但是,在最后的双引号和单引号之间加上一个空格...
$ $ p $ $ groovy -e' printlnHello,world!'
Hello,world!
...即使 bash
似乎能够正确处理尾随的'
对(即没有任何中介空间),如下所示:
$ echo'您好,世界!'
您好,世界!
另外,将 println
细:
$ groovy -e'println(Hello,world!)'
Hello,world!
现在,我想知道为什么第一个案例无效。
我正在使用:
- bash,version4.2.45(1)-release x86_64-pc-linux-gnu)
- groovy,版本2.1.3
正如BDKosher已经指出的那样,这是Apache Commons CLI的一个缺陷。 Groovy希望更新到1.3,但CLI人员花时间使用该版本,并且它包含不兼容性。
正如我在上面评论中所写的,0xFFFF被使用antlr显示文件的结尾,它不必是一个有效的unicode字符。措辞因此受到批评,但措辞来自解析器生成器antlr,而不是来自我们。
This does not work:
$ groovy -e 'println "Hello, world!"'
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
script_from_command_line: 1: unexpected char: 0xFFFF @ line 1, column 23.
println "Hello, world!
^
1 error
However, putting a space between the last double- and single-quote works...
$ # groovy -e 'println "Hello, world!"'
$ groovy -e 'println "Hello, world!" '
Hello, world!
... even though bash
seems to be able to correctly handle the trailing "'
pair (i.e., without any intervening space) as follows:
$ echo '"Hello, world!"'
"Hello, world!"
Also, parenthesizing the println
argument works just fine:
$ groovy -e 'println ("Hello, world!")'
Hello, world!
Now, I would like to know why the very first case does not work.
I'm using:
- bash, version "4.2.45(1)-release (x86_64-pc-linux-gnu)"
- groovy, version 2.1.3
As BDKosher already stated, this is a bug from Apache Commons CLI. Groovy wants to update to 1.3, but the CLI folks take their time with that version and it contains incompatibilities.
And as I wrote in an above comment already 0xFFFF is used by antlr to show the end of the file, it does not have to be a valid unicode character for that. The wording was criticized because of this, but the wording is from the parser generator antlr, not from us.
这篇关于Groovy:这个“Hello World”出了什么问题?程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!