Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Boolean-Rule not used but causes Error in ANTlr
Boolean-Rule not used but causes Error in ANTlr [message #787677] Tue, 31 January 2012 21:31 Go to next message
Hendrik Renken is currently offline Hendrik RenkenFriend
Messages: 18
Registered: July 2009
Junior Member
Hello,

i'm having some troubles with a small grammar i've created. I'm using xtext 2.2.1

grammar de.lang.common

import "http://www.eclipse.org/emf/2002/Ecore" as ecore

generate common "http://www.lang.de/Common"

Model: name=QNAME;

QNAME:
	ID ('.' ID)*;

terminal ID:
	'^'?('a'..'z'|'A'..'Z'|'_') ('a'..'z'|'A'..'Z'|'_'|'0'..'9')*;
terminal BOOLEAN:
	'true'|'false';


When i try to compile this grammar, antlr says:
'The following token definitions can never be matched because prior tokens match the same input: RULE_BOOLEAN'

I don't know how to fix this. The Boolean-Rule isn't even used. This grammar will become a set of rules that i want to use throughout my other grammars and now i'm stuck, since it won't compile correctly.

If someone could point me into the right direction, maybe i do not understand the error message correctly...
That would be awesome.

Kind regards
Hendrik
Re: Boolean-Rule not used but causes Error in ANTlr [message #787693 is a reply to message #787677] Tue, 31 January 2012 21:56 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14716
Registered: July 2009
Senior Member
Hi,

never the less the id terminal rule hides the boolean terminal rule
=> you have to switch the order of the rules in the Xtext file

~Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Boolean-Rule not used but causes Error in ANTlr [message #787884 is a reply to message #787677] Wed, 01 February 2012 04:33 Go to previous messageGo to next message
Henrik Lindberg is currently offline Henrik LindbergFriend
Messages: 2509
Registered: July 2009
Senior Member
There really is no such thing as "unused terminals" - the lexer will
deliver the input as tokens - one per found terminal. If your grammar
does not use a particular terminal just means that there will be a
syntax error when the lexer matches and delivers this token.

BTW, handling keywords as terminals is typically a really bad idea. By
default, your keywords are treated a special way - if the lexer matches
input that is a keyword it will return the token for the keyword instead
of what it otherwise matched. For booleans, you probably want a datatype
that also transforms from the string form "true"/"false" and a boolean
value.

BooleanValue returns ecore::EBoolean: 'true' | 'false';

And you associate a transformer with the "BooleanValue" rule. Perhaps
something like this:
@ValueConverter(rule = "BooleanValue")
public IValueConverter<Boolean> BooleanValue() {
return new IValueConverter<Boolean>() {

public String toString(Boolean value) {
return value.toString();
}

public Boolean toValue(String string, INode node) {
if(Strings.isEmpty(string))
throw new ValueConverterException("Could not convert empty string
to boolean", node, null);
return new Boolean(string).equals(Boolean.TRUE)
? Boolean.TRUE
: Boolean.FALSE;
}

};
}

Regards
- henrik

On 2012-31-01 22:31, Hendrik Renken wrote:
> Hello,
>
> i'm having some troubles with a small grammar i've created. I'm using
> xtext 2.2.1
>
>
> grammar de.lang.common
>
> import "http://www.eclipse.org/emf/2002/Ecore" as ecore
>
> generate common "http://www.lang.de/Common"
>
> Model: name=QNAME;
>
> QNAME:
> ID ('.' ID)*;
>
> terminal ID:
> '^'?('a'..'z'|'A'..'Z'|'_') ('a'..'z'|'A'..'Z'|'_'|'0'..'9')*;
> terminal BOOLEAN:
> 'true'|'false';
>
>
> When i try to compile this grammar, antlr says:
> 'The following token definitions can never be matched because prior
> tokens match the same input: RULE_BOOLEAN'
>
> I don't know how to fix this. The Boolean-Rule isn't even used. This
> grammar will become a set of rules that i want to use throughout my
> other grammars and now i'm stuck, since it won't compile correctly.
>
> If someone could point me into the right direction, maybe i do not
> understand the error message correctly...
> That would be awesome.
>
> Kind regards
> Hendrik
Re: Boolean-Rule not used but causes Error in ANTlr [message #787968 is a reply to message #787884] Wed, 01 February 2012 07:28 Go to previous message
Hendrik Renken is currently offline Hendrik RenkenFriend
Messages: 18
Registered: July 2009
Junior Member
Ah. Thanks for the reply.

Didn't know there was an implied order on the rules.
Previous Topic:What i need to use for get entities-attributes in a variable?
Next Topic:Projectional Editor?
Goto Forum:
  


Current Time: Wed Sep 25 22:22:51 GMT 2024

Powered by FUDForum. Page generated in 0.04162 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top