[英]Rascal: TrafoFields Syntax error: concrete syntax fragment
I'm trying to re-create Tijs' CurryOn16 example "TrafoFields" scraping the code from the video, but using the Java18.rsc grammar instead of his Java15.rsc.我正在尝试重新创建 Tijs 的CurryOn16示例“TrafoFields”,从视频中抓取代码,但使用 Java18.rsc 语法而不是他的 Java15.rsc。 I've parsed the Example.java successfully in the repl, like he did in the video, yielding a var
pt
.我在 repl 中成功解析了 Example.java ,就像他在视频中所做的那样,产生了一个 var
pt
。 I then try to do the transformation with trafoFields(pt)
.然后我尝试使用
trafoFields(pt)
。 The response I get is:我得到的回应是:
|project://Rascal-Test/src/TrafoFields.rsc|(235,142,<12,9>,<16,11>): Syntax error: concrete syntax fragment
My TrafoFields.rsc looks like this:我的 TrafoFields.rsc 看起来像这样:
module TrafoFields
import lang::java::\syntax::Java18;
/**
* - Make public fields private
* - add getters and setters
*/
start[CompilationUnit] trafoFields(start[CompilationUnit] cu) {
return innermost visit (cu) {
case (ClassBody)`{
' <ClassBodyDeclaration* cs1>
' public <Type t> <ID f>;
' <ClassBodyDeclaration* cs2>
'}`
=> (ClassBody)`{
' <ClassBodyDeclaration* cs1>
' private <Type t> <ID f>;
' public void <ID setter>(<Type t> x) {
' this.<ID f> = x;
' }
' public <Type t> <ID getter>() {
' return this.<ID f>;
' }
' <ClassBodyDeclaration* cs2>
'}`
when
ID setter := [ID]"set<f>",
ID getter := [ID]"get<f>"
}
}
The only deviation from Tijs' code is that I've changed ClassBodyDec*
to ClassBodyDeclaration*
, as the grammar has this as a non-terminal.与 Tijs 代码的唯一偏差是我将
ClassBodyDec*
更改为ClassBodyDeclaration*
,因为语法将此作为非终端。 Any hint what else could be wrong?任何提示还有什么可能是错误的?
UPDATE更新
More non-terminal re-writing adapting to Java18 grammar:更多适配Java18语法的非终端重写:
Ah yes, that is the Achilles-heal of concrete syntax usability;啊,是的,这就是具体语法可用性的致命弱点; parse errors.
解析错误。
Note that a generalized parser (such as GLL which Rascal uses), simulates "unlimited lookahead" and so a parse error may be reported a few characters or even a few lines after the actual cause (but never before!).请注意,通用解析器(例如 Rascal 使用的 GLL)模拟“无限前瞻”,因此可能会在实际原因之后的几个字符甚至几行(但之前不会!)报告解析错误。 So shortening the example (delta debugging) will help localize the cause.
因此缩短示例(增量调试)将有助于定位原因。
My way-of-life in this is:我的生活方式是:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.