Skip to content

Commit 83d62d4

Browse files
author
jdf
committed
1 parent cecc3b0 commit 83d62d4

File tree

5 files changed

+64
-3
lines changed

5 files changed

+64
-3
lines changed

app/src/processing/app/preproc/PdeEmitter.java

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -257,11 +257,27 @@ private void printIfThenElse(final AST literalIf) throws RunnerException {
257257
print(thenPath);
258258

259259
// optional "else" clause: an SLIST or an EXPR
260+
// what could be simpler?
260261
final AST elsePath = thenPath.getNextSibling();
261262
if (elsePath != null) {
262263
out.print("else");
263-
dumpHiddenBefore(getBestPrintableNode(elsePath, true));
264-
print(elsePath);
264+
final AST bestPrintableNode = getBestPrintableNode(elsePath, true);
265+
dumpHiddenBefore(bestPrintableNode);
266+
final CommonHiddenStreamToken hiddenBefore =
267+
((CommonASTWithHiddenTokens) elsePath).getHiddenBefore();
268+
if (elsePath.getType() == PdeTokenTypes.SLIST && elsePath.getNumberOfChildren() == 0 &&
269+
hiddenBefore == null) {
270+
out.print("{");
271+
final CommonHiddenStreamToken hiddenAfter =
272+
((CommonASTWithHiddenTokens) elsePath).getHiddenAfter();
273+
if (hiddenAfter == null) {
274+
out.print("}");
275+
} else {
276+
dumpHiddenTokens(hiddenAfter);
277+
}
278+
} else {
279+
print(elsePath);
280+
}
265281
}
266282
}
267283

app/src/processing/app/preproc/PdePreprocessor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,7 @@ private String write(final String program, final PrintWriter stream)
430430
// Because the meanings of < and > are overloaded to support
431431
// type arguments and type parameters, we have to treat them
432432
// as copyable to hidden text (or else the following syntax,
433-
// such as (); and what not gets lost under certain circumstances
433+
// such as (); and what not gets lost under certain circumstances)
434434
// -- jdf
435435
filter.copy(PdeRecognizer.LT);
436436
filter.copy(PdeRecognizer.GT);
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import processing.core.*;
2+
import processing.xml.*;
3+
4+
import java.applet.*;
5+
import java.awt.Dimension;
6+
import java.awt.Frame;
7+
import java.awt.event.MouseEvent;
8+
import java.awt.event.KeyEvent;
9+
import java.awt.event.FocusEvent;
10+
import java.awt.Image;
11+
import java.io.*;
12+
import java.net.*;
13+
import java.text.*;
14+
import java.util.*;
15+
import java.util.zip.*;
16+
import java.util.regex.*;
17+
18+
public class bug400g extends PApplet {
19+
20+
////
21+
public void setup(){
22+
size(100,100);
23+
24+
if(true){
25+
}
26+
else{ // Syntax error on token "else", } expected
27+
}
28+
}
29+
static public void main(String args[]) {
30+
PApplet.main(new String[] { "--bgcolor=null", "bug400g" });
31+
}
32+
}

app/test/resources/bug400g.pde

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
////
2+
void setup(){
3+
size(100,100);
4+
5+
if(true){
6+
}
7+
else{ // Syntax error on token "else", } expected
8+
}
9+
}

app/test/src/test/processing/parsing/ParserTests.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,4 +275,8 @@ public void bug315g() {
275275
expectGood("bug315g");
276276
}
277277

278+
@Test
279+
public void bug400g() {
280+
expectGood("bug400g");
281+
}
278282
}

0 commit comments

Comments
 (0)