Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Error on Compiling - IDE (P32) "/" in string constant + remark (//) on same line
13-01-2012, 06:16 PM, (This post was last modified: 16-04-2012, 09:29 PM by mf01.)
#1
Error on Compiling - IDE (P32) "/" in string constant + remark (//) on same line
Whilst compiling a program that included the slash character "/"in a string constant (quoted text) in a function call I found that adding a comment to the end of the line with "//" caused errors when I attempted to compile the program. I had previously noted that some statements whose syntax appeared OK would not compile but I had not previously realised the correlation with the presence of a // comment on the same line.

Code:
    res = SD.mkdir("/testd");

compiles normally as does

Code:
    res = SD.mkdir("testd");    //

but

Code:
    res = SD.mkdir("/testd");    //

causes the compiler to report the following errors:-

Quote:/home/mark/pinguino32_linux-r245/source/user.c:128:18: warning: missing terminating " character
/home/mark/pinguino32_linux-r245/source/user.c:128:4: error: missing terminating " character
/home/mark/pinguino32_linux-r245/source/user.c:129:7: error: expected expression before 'if'

There were more error messages on the stdout file but they all seemed to be as a consequence of the compiler not dealing with the line contaning the "/" character correctly. To confirm that it was not an issue with the particular function call I also tried:-

Code:
    CDC.println("/New directory added");    //

which resulted in similar error messages. I also tried "escaping" the "/" character with "\" but this resulted in even more compile errors when a comment (//) was added to the end of the line :-(.

Update: The problem does not just occur with function calls, it also occurs when using string constants elsewhere, e.g.

Code:
    char        path_string[256] = "LEVEL_0/LEVEL_1";

compiles normally, as does :-

Code:
    char        path_string[256] = "LEVEL_0";    // Buffer for directory/path string

but :-

Code:
    char        path_string[256] = "LEVEL_0/LEVEL_1";    // Buffer for directory/path string

fails to compile with errors similar to those listed above.

The above behaviour appears to be 100% reproducible on my computer.

Work around - Putting the remark on a separate line to the string constant containing the "/" character also allowed the program to compile normally.

This behaviour was initially found with the following IDE version trunk r245 with the following changes:-
+ sd.pdl32 (x.3 r246)
+ diskio.c, ff.c, fileio.c, fileio.h (x.3 r250)

but was also confirm to occur with IDE Version trunk r235.

I am running Unbuntu 11.10 and use a PIC32 Pinguino OTG and this board was selected in the Pinguino IDE at the time the error messages were reported.

Board = PIC32-Pinguino-OTG Rev C
OS = Linux Unbuntu 11.10 till 26 Apr 2012
OS = Linux Unbuntu 12:04 from 27 Apr 2012
Reply
14-01-2012, 11:30 AM,
#2
RE: Error on Compiling - IDE (P32) "/" in string constant + remark (//) on same line
I think there is something wrong with the Python pre-processor (or how should I call it) - if you look at the generated 'sources/user.c' file, all the code on that specific line is missing after the opening double quotes.

Edit: 2012-01-14 10:38 CET
Yup, found and fixed, 'pinguino.py', function 'replaceword()':
Code:
        # remove end line comment
        if line.find("//")!=-1:
            line = line[0:line.find("/")]
            line = line + "\r\n"
should be
Code:
        # remove end line comment
        if line.find("//")!=-1:
            line = line[0:line.find("//")]
            line = line + "\r\n"
Reply
14-01-2012, 11:53 AM,
#3
RE: Error on Compiling - IDE (P32) "/" in string constant + remark (//) on same line
Following up on Alfred's initial post (since updated above with a fix), I looked at the user.c file and for the array definition (included after Update: in my post above) the corresponding line in user.c is :-

Code:
    char        path_string[256] = "LEVEL_0

i.e. everything after the first "/" (rather than the opening double quote) is stripped off, which would seem to confirm that it is a pre-processor rather than a compiler issue (also confirmed by Alfred's updated post), although though both tasks (pre-processor + compiler) occur after the user has clicked the "compile" button in the Pinguino IDE.
Board = PIC32-Pinguino-OTG Rev C
OS = Linux Unbuntu 11.10 till 26 Apr 2012
OS = Linux Unbuntu 12:04 from 27 Apr 2012
Reply
14-01-2012, 12:24 PM,
#4
RE: Error on Compiling - IDE (P32) "/" in string constant + remark (//) on same line
Yes - sounds like a bug in the IDE.

John
Reply
14-01-2012, 12:30 PM,
#5
RE: Error on Compiling - IDE (P32) "/" in string constant + remark (//) on same line
Just to advise that I have applied Alfred's suggested fix to a local copy of pinguino.py and that his suggested fix at least partially resolves the issue and allows lines with a string constant containing a single "/" character to be compiled in the Pinguino IDE.

However, in the Pinguino IDE a line containing "//" within a string constant e.g.

Code:
    char        path_string[256] = "LEVEL_0//LEVEL_1";    // Buffer for directory-path string

is shown as being a valid format with the quoted text ( "LEVEL_0//LEVEL_1") being shown in brown and the comment (// Buffer for directory-path string) being shown in green. Even with Alfred's suggested change, the pre-processor does not deal with characters within quotes in the same way as they are displayed in the IDE.

Although the IDE edit window/display takes into account quotes (" "), the pre-processor does not. To be consistent the pre-processor should deal with the code in the same way as the editor and ignore all text within string constants. For example the line :-

Code:
    CDC.println("*** CDC.println ***");

actually gives an output

Code:
*** CDCprintln ***

i.e. without the fullstop/period (.) as CDC.println is converted to CDCprintln by the prepocessor.

I originally thought that this was a separate issue, but Alfred's work (in this thread above) has actually shown that it is the same issue.

Board = PIC32-Pinguino-OTG Rev C
OS = Linux Unbuntu 11.10 till 26 Apr 2012
OS = Linux Unbuntu 12:04 from 27 Apr 2012
Reply
14-01-2012, 12:32 PM,
#6
RE: Error on Compiling - IDE (P32) "/" in string constant + remark (//) on same line
Commited to SVN in both trunk (r254) and x.3 (r253). Check if this fixed the problem - it fixed it for me.

PS Too much edits, I think it got lost along the way...
You are right, it does break with double slashes, it should ignore all quoted text. I think this needs a different approach than just simple 'String.find()'.
This function seems to do the trick, add it after 'replaceword()':
Code:
    def removecomment(self, text):
        def replacer(match):
            s = match.group(0)
            if s.startswith('/'):
                return ""
            else:
                return s
        pattern = re.compile(
            r'//.*?$|/\*.*?\*/|\'(?:\\.|[^\\\'])*\'|"(?:\\.|[^\\"])*"',
            re.DOTALL | re.MULTILINE
        )
        return re.sub(pattern, replacer, text)
and place the call:
Code:
        # remove end line comment
        if line.find("//")!=-1:
            line = self.removecomment(line)
            line = line + "\r\n"
I'll wait with a commit until you test and confirm this time... Wink
Reply
14-01-2012, 02:40 PM,
#7
RE: Error on Compiling - IDE (P32) "/" in string constant + remark (//) on same line
If it's going to allow C-style and C++-style comments and strings then it's got allow for all sorts of combinations and probably needs a proper (but simple) parser.

Next test you might like to try would be a mix of strings, comments and embedded escapes such as
\"

Or if you've the time, a simple parser so the IDE is fixed for good Smile

John
Reply
14-01-2012, 03:02 PM,
#8
RE: Error on Compiling - IDE (P32) "/" in string constant + remark (//) on same line
Well, the function I provided can deal with a whole file and strip it from comments (hence the re.MULTILINE switch). It would only have to be ran once before, instead of being called inside, 'replaceword()'.
Reply
14-01-2012, 05:20 PM,
#9
RE: Error on Compiling - IDE (P32) "/" in string constant + remark (//) on same line
Ok, here is a patch with code that completely strips comments first, then pre-processes. Barely tested, so give it a try!


Attached Files
.txt   replace.diff.txt (Size: 2.4 KB / Downloads: 3)
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)