String escape issue in preprocessor #5016

Closed
ottenm opened this Issue Apr 20, 2017 · 5 comments

Comments

Projects
None yet
3 participants
@ottenm

ottenm commented Apr 20, 2017

I have a sketch that compiles and runs in P2. In P3 it says { missing a matching }. It works after removing the comment below from the code:

// 720x960 = 7.5" x 10" (0.5" borders)

@gohai

This comment has been minimized.

Show comment
Hide comment
@gohai

gohai Apr 20, 2017

Contributor

can you attach the full sketch, so we can try to replicate?

Contributor

gohai commented Apr 20, 2017

can you attach the full sketch, so we can try to replicate?

@ottenm

This comment has been minimized.

Show comment
Hide comment
@ottenm

ottenm Apr 21, 2017

Hope this helps!

// compiles and runs in 2.2.1. In P3 I get this when I try to run: "found a { that's missing a matching }"
String exportPath = "c:\files\";
String exportFile = "XXX get above setup() XXX";

void setup() {
size(720, 960); // 720x960 = 7.5" x 10" (0.5" borders)
background(255);
textFont(createFont("Garamond", 18, true));
text("test", 20, 30);
}

ottenm commented Apr 21, 2017

Hope this helps!

// compiles and runs in 2.2.1. In P3 I get this when I try to run: "found a { that's missing a matching }"
String exportPath = "c:\files\";
String exportFile = "XXX get above setup() XXX";

void setup() {
size(720, 960); // 720x960 = 7.5" x 10" (0.5" borders)
background(255);
textFont(createFont("Garamond", 18, true));
text("test", 20, 30);
}

@gohai gohai added the preprocessor label Apr 21, 2017

@gohai

This comment has been minimized.

Show comment
Hide comment
@gohai

gohai Apr 21, 2017

Contributor

I reduced the issue to

String foo = "\\";

void setup() {
  // "
}

In the first line, the preprocessor seems to be thrown-off by the escaped backslash (@ottenm: you need to add two backslashes for paths, since a single one starts an escape sequence, see here). This alone only causes the syntax to be colored erroneously, but the sketch still starts.

The second issue a comment with an odd number of quotation marks. On its own this doesn't cause an issue, but here it does.

Contributor

gohai commented Apr 21, 2017

I reduced the issue to

String foo = "\\";

void setup() {
  // "
}

In the first line, the preprocessor seems to be thrown-off by the escaped backslash (@ottenm: you need to add two backslashes for paths, since a single one starts an escape sequence, see here). This alone only causes the syntax to be colored erroneously, but the sketch still starts.

The second issue a comment with an odd number of quotation marks. On its own this doesn't cause an issue, but here it does.

@gohai gohai changed the title from commented code breaking P3 compiler to String escape issue in preprocessor Apr 21, 2017

JakubValtar added a commit to JakubValtar/processing that referenced this issue Apr 21, 2017

@JakubValtar

This comment has been minimized.

Show comment
Hide comment
@JakubValtar

JakubValtar Apr 21, 2017

Contributor

Thanks @ottenm & @gohai, your code helped to track down the issue.

Contributor

JakubValtar commented Apr 21, 2017

Thanks @ottenm & @gohai, your code helped to track down the issue.

@ottenm

This comment has been minimized.

Show comment
Hide comment
@ottenm

ottenm Apr 21, 2017

ottenm commented Apr 21, 2017

@benfry benfry closed this in #5019 Apr 21, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment