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

deparse/indexing fixes for BlockNode

parent c8afa9d7
Branches
No related tags found
No related merge requests found
......@@ -127,9 +127,17 @@ public class RRuntimeASTAccessImpl implements RRuntimeASTAccess {
return 3;
} else if (node instanceof ReplacementNode) {
return 3;
} else if (node instanceof BlockNode) {
/*
* 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 *must* have been a "{", so we fabricate it.
*/
int len = ((BlockNode) node).getSequence().length;
return len == 1 ? 1 : len + 1;
} else {
// TODO fill out
assert false : node;
throw RInternalError.unimplemented(node.toString());
}
return result;
}
......@@ -221,11 +229,24 @@ public class RRuntimeASTAccessImpl implements RRuntimeASTAccess {
default:
assert false;
}
} else if (node instanceof BlockNode) {
/* See related comments in getLength. */
RNode[] seq = ((BlockNode) node).getSequence();
if (seq.length > 1) {
switch (index) {
case 0:
return RDataFactory.createSymbol("{");
default:
return RASTUtils.createLanguageElement(seq[index - 1]);
}
} else {
return RASTUtils.createLanguageElement(seq[0]);
}
} else if (node instanceof ReplacementNode) {
return RNull.instance;
} else {
// TODO fill out
assert false;
throw RInternalError.unimplemented(node.toString());
}
return null;
}
......
......@@ -77,6 +77,9 @@ public class BlockNode extends SequenceNode implements RSyntaxNode, VisibilityCo
@Override
public void deparseImpl(RDeparse.State state) {
state.startNodeDeparse(this);
if (sequence.length > 1) {
state.writeOpenCurlyNLIncIndent();
}
for (int i = 0; i < sequence.length; i++) {
state.mark();
sequence[i].deparse(state);
......@@ -86,6 +89,9 @@ public class BlockNode extends SequenceNode implements RSyntaxNode, VisibilityCo
state.mark(); // in case last
}
}
if (sequence.length > 1) {
state.decIndentWriteCloseCurly();
}
state.endNodeDeparse(this);
}
......@@ -96,7 +102,7 @@ public class BlockNode extends SequenceNode implements RSyntaxNode, VisibilityCo
* it is represented as a LANGSXP with symbol "{" and a NULL cdr, representing the empty
* sequence. This is an unpleasant special case in FastR that we can only detect by
* re-examining the original source.
*
*
* A sequence of length 1, i.e. a single statement, is represented as itself, e.g. a SYMSXP
* for "x" or a LANGSXP for a function call. Otherwise, the representation is a LISTSXP
* pairlist, where the car is the statement and the cdr is either NILSXP or a LISTSXP for
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment