Skip to content
Snippets Groups Projects
Commit 6ace9245 authored by Mick Jordan's avatar Mick Jordan
Browse files

fix bug for length 0/1 blocks deparse

parent e7388106
Branches
No related tags found
No related merge requests found
...@@ -79,7 +79,8 @@ public class BlockNode extends SequenceNode implements RSyntaxNode, VisibilityCo ...@@ -79,7 +79,8 @@ public class BlockNode extends SequenceNode implements RSyntaxNode, VisibilityCo
@Override @Override
public void deparseImpl(RDeparse.State state) { public void deparseImpl(RDeparse.State state) {
state.startNodeDeparse(this); state.startNodeDeparse(this);
if (sequence.length > 1) { // empty deparses as {}
if (sequence.length != 1) {
state.writeOpenCurlyNLIncIndent(); state.writeOpenCurlyNLIncIndent();
} }
for (int i = 0; i < sequence.length; i++) { for (int i = 0; i < sequence.length; i++) {
...@@ -91,7 +92,7 @@ public class BlockNode extends SequenceNode implements RSyntaxNode, VisibilityCo ...@@ -91,7 +92,7 @@ public class BlockNode extends SequenceNode implements RSyntaxNode, VisibilityCo
state.mark(); // in case last state.mark(); // in case last
} }
} }
if (sequence.length > 1) { if (sequence.length != 1) {
state.decIndentWriteCloseCurly(); state.decIndentWriteCloseCurly();
} }
state.endNodeDeparse(this); state.endNodeDeparse(this);
...@@ -138,10 +139,15 @@ public class BlockNode extends SequenceNode implements RSyntaxNode, VisibilityCo ...@@ -138,10 +139,15 @@ public class BlockNode extends SequenceNode implements RSyntaxNode, VisibilityCo
/* /*
* We can't get this completely compatible with GnuR without knowing if the source had a "{" * We can't get this completely compatible with GnuR without knowing if the source had a "{"
* or not. However, semantically what really matters is that if the length is > 1, there * or not. However, semantically what really matters is that if the length is > 1, there
* *must* have been a "{", so we fabricate it. * *must* have been a "{", so we fabricate it. Furthermore, if length==1, then we must
* delegate to the underlying node
*/ */
int len = getSequence().length; int len = getSequence().length;
return len == 1 ? 1 : len + 1; if (len == 1) {
return getSequence()[0].asRSyntaxNode().getRlengthImpl();
} else {
return len + 1;
}
} }
@Override @Override
...@@ -156,7 +162,7 @@ public class BlockNode extends SequenceNode implements RSyntaxNode, VisibilityCo ...@@ -156,7 +162,7 @@ public class BlockNode extends SequenceNode implements RSyntaxNode, VisibilityCo
return RASTUtils.createLanguageElement(seq[index - 1]); return RASTUtils.createLanguageElement(seq[index - 1]);
} }
} else { } else {
return RASTUtils.createLanguageElement(seq[0]); return getSequence()[0].asRSyntaxNode().getRelementImpl(index);
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment