Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/ant/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Antlr4 运行JSON2XML\u ST时出错_Antlr4_Stringtemplate 4 - Fatal编程技术网

Antlr4 运行JSON2XML\u ST时出错

Antlr4 运行JSON2XML\u ST时出错,antlr4,stringtemplate-4,Antlr4,Stringtemplate 4,我尝试运行JSON2XML,如下所示: bab@maz:~/tpantlr2-code/code/listeners$ antlr4 JSON.g4 bab@maz:~/tpantlr2-code/code/listeners$ javac JSON2XML_ST.java bab@maz:~/tpantlr2-code/code/listeners$ java JSON2XML_ST t.json 但是我得到了一个答案: (json (object { (pair "descripti

我尝试运行JSON2XML,如下所示:

bab@maz:~/tpantlr2-code/code/listeners$ antlr4 JSON.g4 
bab@maz:~/tpantlr2-code/code/listeners$ javac JSON2XML_ST.java 
bab@maz:~/tpantlr2-code/code/listeners$ java JSON2XML_ST t.json 
但是我得到了一个答案:

(json (object { (pair "description" : (value "An imaginary server config file")) ,      
(pair "logs" : (value (object { (pair "level" : (value "verbose")) , (pair "dir" :  
(value "/var/log")) }))) , (pair "host" : (value "antlr.org")) , (pair "admin" : (value 
(array [ (value "parrt") , (value "tombu") ]))) , (pair "aliases" : (value (array [ 
]))) }))
Exception in thread "main" java.lang.IllegalArgumentException: No such group file: XML.stg
at org.stringtemplate.v4.STGroupFile.<init>(STGroupFile.java:69)
at org.stringtemplate.v4.STGroupFile.<init>(STGroupFile.java:48)
at JSON2XML_ST$XMLEmitter.<init>(JSON2XML_ST.java:45)
at JSON2XML_ST.main(JSON2XML_ST.java:140)
(json(对象{(对“描述”):(值“一个虚构的服务器配置文件”),
(对“日志”:(值)(对象{(对“级别”:(值“详细”),(对“目录”:
(值“/var/log”))})、对“主机”:(值“antlr.org”)、对“管理员”:(值
(数组[(值“parrt”),(值“tombu”)),(对“别名”:(值(数组)[
]))) }))
线程“main”java.lang.IllegalArgumentException中的异常:没有这样的组文件:XML.stg
位于org.stringtemplate.v4.STGroupFile。(STGroupFile.java:69)
位于org.stringtemplate.v4.STGroupFile。(STGroupFile.java:48)
在JSON2XML_ST$XMLEmitter(JSON2XML_ST.java:45)
在JSON2XML_ST.main(JSON2XML_ST.java:140)

为什么??有人能帮我吗?谢谢。

问题在于XML.stg不是源代码的一部分。i、 e.运行该示例时,文件XML.stg不存在,因此无法找到,因此错误为没有此类组文件

Exception in thread "main" java.lang.IllegalArgumentException: No such group file: XML.stg
这似乎是一个已知问题,已在ANTLR勘误表中报告:

50831: 有一个对JSON2XML_ST.java源代码的引用,它使用StringTemplate进行XML翻译。但在源代码本身中,有对XML.stg文件的引用,该文件在《源代码归档》一书中不存在。 JSON2XML_ST.java(第45行): STGroup templates=newstgroupfile(“XML.stg”); 如果你把它存档就好了,因为在别处找到它并不容易。 谢谢

这里有一个对xml.stg的引用:您可以使用它

创建一个新文件,将其命名为XML.stg,并放入以下内容:

group XML;

file(props) ::= <<
    \<properties>
    <props; separator="\n">
    \</properties>
>>

prop(ID,v) ::= "\<property id=\"<ID>\"><v>\</property>"
group-XML;
文件(道具):=>
道具(ID,v):=“\\”

然后重新运行您已有的示例,它可能会起作用。

这是一个XML.stg,可以与JSON2XML_ST.java一起使用。源代码下载仍然不包含XML.stg。然而,自己提出这个文件是一个很好的学习练习。是给我的

group XML;

empty() ::= ""

value(x) ::= "<x>"

object(fields) ::= <<

<fields; separator="\n">

>>

enclose_element(x) ::= <<
\<element><x>\</element>
>>

array(values) ::= <<

<values:enclose_element(); separator="\n">

>>

tag(name,content) ::= <<
\<<name>\><content>\</<name>\>
>>
group-XML;
空():=“”
值(x):=“”
对象(字段):=>
包含元素(x):=>
数组(值):=>
标签(名称、内容):=>