Home » Modeling » TMF (Xtext) » [xText] Error in the generated PartitionScanner
[xText] Error in the generated PartitionScanner [message #19272] |
Wed, 06 August 2008 15:24 |
|
by taking a look at the generated antlr grammar, the STRING token takes
care of escaping character \ (which is a really good thing :-)
RULE_STRING :
'"' ( '\\' ('b'|'t'|'n'|'f'|'r'|'\"'|'\''|'\\') | ~('\\'|'"') )* '"' |
'\'' ( '\\' ('b'|'t'|'n'|'f'|'r'|'\"'|'\''|'\\') | ~('\\'|'\'') )* '\''
;
However, the generated GeneratedPartitionScanner.java in the .editor
plugin, does not consider the escape character:
public class GeneratedPartitionScanner extends AbstractPartitionScanner {
@Override
public List<IPredicateRule> getRules() {
List<IPredicateRule> rules = new ArrayList<IPredicateRule>();
...
rules.add(new MultiLineRule("\"","\"", string));
rules.add(new MultiLineRule("'","'", string));
return rules;
}
in fact, in the generated editor the highlighting of a string of the shape
"this is \"a test\""
does not generate an error (right!) but it is not highlighted correctly.
The generated partition scanner should consider the escape character:
public class GeneratedPartitionScanner extends AbstractPartitionScanner {
@Override
public List<IPredicateRule> getRules() {
List<IPredicateRule> rules = new ArrayList<IPredicateRule>();
...
rules.add(new MultiLineRule("\"","\"", string, '\\'));
rules.add(new MultiLineRule("'","'", string, '\\'));
return rules;
}
where should I fix this?
if I modify the generated partition scanner directly I assume it will be
overwritten...
thanks
Lorenzo
--
Lorenzo Bettini, PhD in Computer Science, DI, Univ. Torino
ICQ# lbetto, 16080134 (GNU/Linux User # 158233)
HOME: http://www.lorenzobettini.it MUSIC: http://www.purplesucker.com
http://www.myspace.com/supertrouperabba
BLOGS: http://tronprog.blogspot.com http://longlivemusic.blogspot.com
http://www.gnu.org/software/src-highlite
http://www.gnu.org/software/gengetopt
http://www.gnu.org/software/gengen http://doublecpp.sourceforge.net
HOME: http://www.lorenzobettini.it
TDD Book: https://leanpub.com/tdd-buildautomation-ci
Xtext Book: https://www.packtpub.com/application-development/implementing-domain-specific-languages-xtext-and-xtend-second-edition
|
|
|
Re: [xText] Error in the generated PartitionScanner [message #19558 is a reply to message #19272] |
Fri, 08 August 2008 06:44 |
Eclipse User |
|
|
|
Originally posted by: sven.efftinge.de
Hi Lorenzo,
it would be best if you could provide a patch and file it in bugzilla,
so that the issue is fixed for everybody :-)
In general if you want to configure a special partition scanner you
should subclass the generated [LanguageName]Utilities.java class in the
editor project. The subclass should of course go into the src/ folder.
Then change the [LanguageName]EditorPlugin class so that it instantiates
the new subclass instead of the generated class.
In the manually created utility class you can overwrite the method:
@Override
public IPartitionTokenScanner getPartitionScanner() {
// TODO Auto-generated method stub
return super.getPartitionScanner();
}
Note, that this is how you can replace other built-in functionality as
well (e.g. content assist).
hope that helps,
Sven
Lorenzo Bettini schrieb:
> by taking a look at the generated antlr grammar, the STRING token takes
> care of escaping character \ (which is a really good thing :-)
>
> RULE_STRING :
>
> '"' ( '\\' ('b'|'t'|'n'|'f'|'r'|'\"'|'\''|'\\') | ~('\\'|'"') )* '"' |
> '\'' ( '\\' ('b'|'t'|'n'|'f'|'r'|'\"'|'\''|'\\') | ~('\\'|'\'') )*
> '\''
>
> ;
>
> However, the generated GeneratedPartitionScanner.java in the .editor
> plugin, does not consider the escape character:
>
> public class GeneratedPartitionScanner extends AbstractPartitionScanner {
>
> @Override
> public List<IPredicateRule> getRules() {
> List<IPredicateRule> rules = new ArrayList<IPredicateRule>();
>
> ...
> rules.add(new MultiLineRule("\"","\"", string));
> rules.add(new MultiLineRule("'","'", string));
> return rules;
> }
>
> in fact, in the generated editor the highlighting of a string of the shape
>
> "this is \"a test\""
>
> does not generate an error (right!) but it is not highlighted correctly.
>
> The generated partition scanner should consider the escape character:
>
> public class GeneratedPartitionScanner extends AbstractPartitionScanner {
>
> @Override
> public List<IPredicateRule> getRules() {
> List<IPredicateRule> rules = new ArrayList<IPredicateRule>();
>
> ...
> rules.add(new MultiLineRule("\"","\"", string, '\\'));
> rules.add(new MultiLineRule("'","'", string, '\\'));
> return rules;
> }
>
> where should I fix this?
> if I modify the generated partition scanner directly I assume it will be
> overwritten...
>
> thanks
> Lorenzo
>
|
|
|
Goto Forum:
Current Time: Sat Dec 21 17:22:22 GMT 2024
Powered by FUDForum. Page generated in 0.03610 seconds
|