| shendric |
 |
Friday, August 22 2008 @ 10:15 AM CEST (Read 1145 times) |
|
|

User
Status: offline
Registered: 08/18/08
Posts: 17
|
The built in STRING definition is incorrect, I think. In the generated ANTLR file, it is:
RULE_STRING :
'"' ( '\\' ('b'|'t'|'n'|'f'|'r'|'\"'|'\''|'\\') | ~('\\'|'"') )* '"' |
'\'' ( '\\' ('b'|'t'|'n'|'f'|'r'|'\"'|'\''|'\\') | ~('\\'|'\'') )* '\''
;
Below, I have added some comments to RULE_STRING to highlight the problem.
RULE_STRING :
'"'<--- not escaped ( '\\' ('b'|'t'|'n'|'f'|'r'|'\"' <--- escaped |'\''|'\\')
| ~('\\'|'"' <--- not escaped ) )* '"'<--- not escaped |
'\'' ( '\\' ('b'|'t'|'n'|'f'|'r'|'\"' <--- escaped |'\''|'\\') | ~('\\'|'\'') )* '\''
;
Because the two double quotes are incorrectly escaped, it is not possible to express strings with quotes in them. For example, I'm trying to parse a file where a String has backslashes, but they are meant to be treated as backslashes, not as special characters. I'm trying to express this in my xText file as the following:
Native DoubleQuotedStringLiteral
: " '\"' ~('\"')* '\"' "
;
Not only does this not display correctly, it simply refuses to be processed.
This is related to a post on the newsgroup here:
http://dev.eclipse.org/newslists/news.eclipse.modeling.gmt/msg00811.html
(Speaking of which, which newsgroup should I be posting to?)
Could you please fix this?
Thank you,
-- Scott
|
| |
|
|
| Patrick Schönbach |
 |
Friday, August 22 2008 @ 02:09 PM CEST |
|
|

Senior Member
 Status: offline
Registered: 11/03/07
Posts: 236
|
The fix will appear in the next nightly build.
Regards,
Patrick
|
| |
|
|
| Lorenzo Bettini |
 |
Saturday, August 23 2008 @ 07:10 PM CEST |
|
|

User
 Status: offline
Registered: 08/08/08
Posts: 30
|
Actually, concerning the bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=243608, which now should be fixed in the CVS, the strings with backslashed quotes used to work correctly as before (the parser used to parse it correctly), it was the highlighter that was wrong...
http://www.lorenzobettini.it - http://tronprog.blogspot.com
|
| |
|
|
| Patrick Schönbach |
 |
Saturday, August 23 2008 @ 07:14 PM CEST |
|
|

Senior Member
 Status: offline
Registered: 11/03/07
Posts: 236
|
I already fixed the highlighter some weeks ago, as far as I remember.
Regards,
Patrick
|
| |
|
|
| Lorenzo Bettini |
 |
Saturday, August 23 2008 @ 07:17 PM CEST |
|
|

User
 Status: offline
Registered: 08/08/08
Posts: 30
|
Yes, I had provided a patch in that bug report.
But I just wanted to point out that it was not related to the parser rule (which worked correctly) but to the highlighter rule (which did not take into consideration the escape char).
http://www.lorenzobettini.it - http://tronprog.blogspot.com
|
| |
|
|
| Patrick Schönbach |
 |
Saturday, August 23 2008 @ 07:21 PM CEST |
|
|

Senior Member
 Status: offline
Registered: 11/03/07
Posts: 236
|
Does my change hurt? Should I change it back?
Regards,
Patrick
|
| |
|
|
| Lorenzo Bettini |
 |
Saturday, August 23 2008 @ 08:08 PM CEST |
|
|

User
 Status: offline
Registered: 08/08/08
Posts: 30
|
If you refer to the change based on my patch, I think that patch is correct: it fixes the highlighter.
Also the ANTLR rule is correct, as far as I know
http://www.lorenzobettini.it - http://tronprog.blogspot.com
|
| |
|
|
| shendric |
 |
Saturday, August 23 2008 @ 11:13 PM CEST |
|
|

User
Status: offline
Registered: 08/18/08
Posts: 17
|
I could be wrong, but if the previous ANTLR rule was correct, shouldn't it be possible to have the following rule in an xText file?
Native DoubleQuotedStringLiteral
: " '\"' ~('\"')* '\"' "
;
Unfortunately, I cannot test the two different rules for String. I've tried checking out the source, but there are a lot of projects for which I cannot get the dependencies fixed. Also, the team project set doesn't seem to work either. Finally, I cannot install the source projects from the update site either. So, I'm sort of stuck.
The nightly build seems to be broken too. The last nightly build was on the 19th. I've looked at the following locations:
http://oaw.pluginbuilder.org/nightly/updateSite/site.xml
http://oawbranch.pluginbuilder.org/latest/
and
http://oawbranch.pluginbuilder.org/nightly/updateSite/
So, I'm still not sure that the new STRING rule that I suggested will actually solve the problem. If you can get the nightly build working, or help me check out the source, I'll be happy to experiment a bit.
Thanks,
-- Scott
|
| |
|
|
| Patrick Schönbach |
 |
Saturday, August 23 2008 @ 11:21 PM CEST |
|
|

Senior Member
 Status: offline
Registered: 11/03/07
Posts: 236
|
I just triggered a new build manually.
Regards,
Patrick
|
| |
|
|
| Lorenzo Bettini |
 |
Sunday, August 24 2008 @ 10:18 AM CEST |
|
|

User
 Status: offline
Registered: 08/08/08
Posts: 30
|
Quote by: shendricI could be wrong, but if the previous ANTLR rule was correct, shouldn't it be possible to have the following rule in an xText file?
Native DoubleQuotedStringLiteral
: " '"' ~('"')* '"' "
;
But would this rule be able to parse strings such as
"string with \" escaped quotes"
I think that rule would return
"string with \"
which is wrong, isn't it?
http://www.lorenzobettini.it - http://tronprog.blogspot.com
|
| |
|
|
| shendric |
 |
Sunday, August 24 2008 @ 04:48 PM CEST |
|
|

User
Status: offline
Registered: 08/18/08
Posts: 17
|
Normally, you would be correct. However, in the particular case that I'm using, I'm trying to parse a string that doesn't use '\' as an escape character. Someone gave me files with entries like:
file "C:\path\to\file.txt"
Where the backslashes are not escaped, and there aren't any special characters like \t, \r, etc.
The thing that makes it difficult is that there are also "normal" strings in the file as well, but consistently in a different context. So, I need rules that parse both cases for the same file. It's one of those situations where I wish I could have had the files uses consistent strings in the first place :)
-- Scott
|
| |
|
|
| Lorenzo Bettini |
 |
Monday, August 25 2008 @ 11:24 AM CEST |
|
|

User
 Status: offline
Registered: 08/08/08
Posts: 30
|
Sorry, now I see your point
http://www.lorenzobettini.it - http://tronprog.blogspot.com
|
| |
|
|