使用parsertree时出现奇怪的错误
strange errors when using parsertree
我正在尝试使用 java15 语法解析代码。
我注意到在解析整个 class 时,如果 class 文件以空行结尾,它会给我一个错误。我写了一些代码来在解析之前删除这些空行,但是有没有更结构化的解决方案?还是我遗漏了什么?
相关:当我尝试解析单个方法时:一旦我将某些内容更改为赞誉 { }
的位置(例如,在单独的行上或不在行上),我就会收到错误消息。
|std:///ParseTree.rsc|(14967,5,<455,80>,<455,85>): ParseError(|java+class:///smallsql/database/language/Language_it|(10537,0,<152,0>,<152,0>))
at parse(|std:///ParseTree.rsc|(14967,5,<455,80>,<455,85>))
at $root$(|prompt:///|(0,7,<1,0>,<1,7>))
at *** somewhere ***(|std:///ParseTree.rsc|(14967,5,<455,80>,<455,85>))
at parse(|std:///ParseTree.rsc|(14967,5,<455,80>,<455,85>))
at $root$(|prompt:///|(0,7,<1,0>,<1,7>))
我猜您正在使用如下代码进行解析:
parse(#CompilationUnit, file)
[CompilationUnit] file
但是:CompilationUnit
不以 layout
符号开始或结束。
要解决这个问题,您应该像这样声明语法的起始非终结符:
start syntax CompilationUnit = ... ;
layout L = [\t\n\r\ ]*; // it's necessary to have L be nullable
这将(内部和隐藏)为您生成一个新作品,如下所示:
syntax start[CompilationUnit] = L CompilationUnit top L;
有了这个,您就可以解析可能以布局结尾的整个文件:
parse(#start[CompilationUnit], file)
[start[CompilationUnit]] file
要提取 CompilationUnit,top
字段会派上用场:
CompilationUnit u = parse(#CompilationUnit, file).top
我正在尝试使用 java15 语法解析代码。
我注意到在解析整个 class 时,如果 class 文件以空行结尾,它会给我一个错误。我写了一些代码来在解析之前删除这些空行,但是有没有更结构化的解决方案?还是我遗漏了什么?
相关:当我尝试解析单个方法时:一旦我将某些内容更改为赞誉 { }
的位置(例如,在单独的行上或不在行上),我就会收到错误消息。
|std:///ParseTree.rsc|(14967,5,<455,80>,<455,85>): ParseError(|java+class:///smallsql/database/language/Language_it|(10537,0,<152,0>,<152,0>))
at parse(|std:///ParseTree.rsc|(14967,5,<455,80>,<455,85>))
at $root$(|prompt:///|(0,7,<1,0>,<1,7>))
at *** somewhere ***(|std:///ParseTree.rsc|(14967,5,<455,80>,<455,85>))
at parse(|std:///ParseTree.rsc|(14967,5,<455,80>,<455,85>))
at $root$(|prompt:///|(0,7,<1,0>,<1,7>))
我猜您正在使用如下代码进行解析:
parse(#CompilationUnit, file)
[CompilationUnit] file
但是:CompilationUnit
不以 layout
符号开始或结束。
要解决这个问题,您应该像这样声明语法的起始非终结符:
start syntax CompilationUnit = ... ;
layout L = [\t\n\r\ ]*; // it's necessary to have L be nullable
这将(内部和隐藏)为您生成一个新作品,如下所示:
syntax start[CompilationUnit] = L CompilationUnit top L;
有了这个,您就可以解析可能以布局结尾的整个文件:
parse(#start[CompilationUnit], file)
[start[CompilationUnit]] file
要提取 CompilationUnit,top
字段会派上用场:
CompilationUnit u = parse(#CompilationUnit, file).top