From 5ed245459c46f7ec29821a871ab756cf30945443 Mon Sep 17 00:00:00 2001 From: "Frank.R.Wu" Date: Wed, 10 Nov 2021 22:07:19 +0800 Subject: [PATCH] fix: fix syntax error in compiling functions fix syntax error in DesktopEngine.compileFunction --- src/main/base/org/bdware/sc/node/ContractNode.java | 6 +----- src/main/base/org/bdware/sc/node/Script.java | 12 +++++++++--- .../base/org/bdware/sc/visitor/FunctionReader.java | 1 - 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/main/base/org/bdware/sc/node/ContractNode.java b/src/main/base/org/bdware/sc/node/ContractNode.java index dffe64d..ad302d8 100644 --- a/src/main/base/org/bdware/sc/node/ContractNode.java +++ b/src/main/base/org/bdware/sc/node/ContractNode.java @@ -62,11 +62,7 @@ public class ContractNode { cn.initText(cts); } for (FunctionNode fun : functions) { - if (fun.isExport) { - fun.initTextWithoutExport(cts); - } else { - fun.initText(cts); - } + fun.initTextWithCleaning(cts, fun.isExport, fun.isView()); if (fun.isExport || fun.functionName.equals("onCreate")) { fun.initTextWithRequester(); } diff --git a/src/main/base/org/bdware/sc/node/Script.java b/src/main/base/org/bdware/sc/node/Script.java index 62fe552..805349d 100644 --- a/src/main/base/org/bdware/sc/node/Script.java +++ b/src/main/base/org/bdware/sc/node/Script.java @@ -34,10 +34,16 @@ public class Script { public void initText(CommonTokenStream cts) { plainText = cts.getText(interval); - } - public void initTextWithoutExport(CommonTokenStream cts) { - plainText = cts.getText(interval).replaceFirst("export", ""); + public void initTextWithCleaning(CommonTokenStream cts, boolean isExported, boolean isView) { + String plainText = cts.getText(interval); + if (isExported) { + plainText = plainText.replaceFirst("exported", ""); + } + if (isView) { + plainText = plainText.replaceFirst("\\)\\s?view\\s?\\{", "){"); + } + this.plainText = plainText; } } diff --git a/src/main/base/org/bdware/sc/visitor/FunctionReader.java b/src/main/base/org/bdware/sc/visitor/FunctionReader.java index b7c047f..445a49d 100644 --- a/src/main/base/org/bdware/sc/visitor/FunctionReader.java +++ b/src/main/base/org/bdware/sc/visitor/FunctionReader.java @@ -57,7 +57,6 @@ public class FunctionReader extends YJSParserBaseVisitor { node.setInterval( new Interval(ctx.Function().getSourceInterval().a, ctx.getSourceInterval().b)); - List annotations = new ArrayList<>(); if (null != ctx.annotations()) { annotations = ctx.annotations().annotation();