Skip to main content



      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 16:31 Go to next message
Eclipse UserFriend
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 16:56 Go to previous messageGo to next message
Eclipse UserFriend
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
Re: Boolean-Rule not used but causes Error in ANTlr [message #787884 is a reply to message #787677] Tue, 31 January 2012 23:33 Go to previous messageGo to next message
Eclipse UserFriend
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 02:28 Go to previous message
Eclipse UserFriend
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: Sat Jul 05 00:22:32 EDT 2025

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

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

Back to the top