Skip to content

Commit

Permalink
More tinkering with comments around Code eObjects.
Browse files Browse the repository at this point in the history
  • Loading branch information
petervdonovan committed Jun 14, 2023
1 parent 7c50334 commit 438faf2
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
6 changes: 3 additions & 3 deletions core/src/main/java/org/lflang/ast/ToLf.java
Original file line number Diff line number Diff line change
Expand Up @@ -206,9 +206,9 @@ private static List<INode> getContainedComments(INode node) {
&& (child.getText().contains("\n") || child.getText().contains("\r"))
&& !inSemanticallyInsignificantLeadingRubbish) {
break;
} else if (child instanceof ICompositeNode compositeNode
&& compositeNode.getGrammarElement().eContainer() instanceof ParserRuleImpl pri
&& pri.getName().equals("Body")) {
} else if (child.getParent() != null
&& child.getParent().getGrammarElement().eContainer() instanceof ParserRuleImpl pri
&& pri.getName().equals("Body") && !child.getText().isBlank()) {
break;
}
}
Expand Down
17 changes: 10 additions & 7 deletions core/src/main/java/org/lflang/ast/ToText.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,19 @@ public String caseCode(Code code) {
StringBuilder builder = new StringBuilder(Math.max(node.getTotalLength(), 1));
boolean started = false;
for (ILeafNode leaf : node.getLeafNodes()) {
if (!leaf.getText().contains("{=")
&& (leaf.getText().contains("\n") && !ASTUtils.isComment(leaf))) {
started = true;
if (!leaf.getText().equals("{=") && !leaf.getText().equals("=}")) {
var nothing = leaf.getText().isBlank() || ASTUtils.isComment(leaf);
if (!nothing || started || leaf.getText().startsWith("\n"))
builder.append(leaf.getText());
if ((leaf.getText().contains("\n") || (!nothing))) {
started = true;
}
}
if (started && !leaf.getText().contains("=}")) builder.append(leaf.getText());
}
String str = builder.toString().trim();
if (str.split("\n").length > 1) {
String str = builder.toString();
if (str.contains("\n")) {
// multi line code
return StringUtil.trimCodeBlock(str, 1);
return StringUtil.trimCodeBlock(str, 0);
} else {
// single line code
return str.trim();
Expand Down

0 comments on commit 438faf2

Please sign in to comment.