Skip to main content



      Home
Home » Modeling » TMF (Xtext) » Bug parsing Xtext file
Bug parsing Xtext file [message #989381] Wed, 05 December 2012 17:48 Go to next message
Eclipse UserFriend
Here is my xtext file to parse PROLOG programs:

grammar org.archstudio.prolog.xtext.Prolog with org.eclipse.xtext.common.Terminals

generate prolog "http://www.archstudio.org/prolog/xtext/Prolog"

Program:
	(clauses+=Clause)* (query=Query)?;

Clause:
	(predicates+=Predicate) (':-' predicates+=Predicate (',' predicates+=Predicate)*)? '.';

Query:
	'?-' predicates+=Predicate (',' predicates+=Predicate)* '.';

Predicate:
	functor=Functor '(' terms+=Predicate (',' terms+=Predicate)* ')'
	| terms+=Term functor=Functor terms+=Predicate;

Term:
	(atom=ATOM) | (number=NUMBER) | ('\'' string=STRING '\'') | (variable=VARIABLE)
	| (list?='[' (terms+=Predicate (',' terms+=Predicate)* ('|' rest=Predicate)?)? ']');

Functor:
	name=(OPERATOR | ATOM);

terminal OPERATOR:
	'==' | '\\=' | '.';

terminal NUMBER:
	'-'? ('0'..'9')+;

terminal ATOM:
	'a'..'z' ('0'..'9' | 'a'..'z' | 'A'..'Z' | '_')*;

terminal VARIABLE:
	('A'..'Z' | '_') ('0'..'9' | 'a'..'z' | 'A'..'Z' | '_')*;

terminal STRING:
	'a'..'z' | 'A'..'Z' |
	'_' | '0'..'9' | '+' | '-' | '*' | '/' | '\\' | '^' | '~' | ':' | '.' | '?' | '@' | '#' | '$' | '&';


When I try to Generate Xtext Artifacts, it ends with an error of:


error(208): ../org.archstudio.prolog.xtext/src-gen/org/archstudio/prolog/xtext/parser/antlr/internal/InternalProlog.g:682:1: The following token definitions can never be matched because prior tokens match the same input: RULE_INT


The problem is that I'm not using the INT rule, so it shouldn't complain about it (right?).


Is this a bug, is there a workaround?


Thank you,
-- Scott
  • Attachment: Prolog.xtext
    (Size: 1.08KB, Downloaded 146 times)
Re: Bug parsing Xtext file [message #989575 is a reply to message #989381] Thu, 06 December 2012 14:42 Go to previous messageGo to next message
Eclipse UserFriend
When you created your grammar, xtext imported (by default) some terminals. Your terminals do conflict with these terminals, that's why you get the error message.

The import is done by
with org.eclipse.xtext.common.Terminals

To see which terminals are defined in this grammar consult the manual or just hit F3 when your cursor is over the import.

To get rid of your error just remove the "with ...".
Note that you have to import the basic ecore types when you're no longer referencing the base grammar. This is done by:
import "http://www.eclipse.org/emf/2002/Ecore" as ecore


Felix

[Updated on: Fri, 07 December 2012 02:23] by Moderator

Re: Bug parsing Xtext file [message #989611 is a reply to message #989575] Thu, 06 December 2012 17:59 Go to previous message
Eclipse UserFriend
That did it. Thank you!
-- Scott
Previous Topic:Reusing validation in GMF editor
Next Topic:Problem while cross-referencing. Solution review
Goto Forum:
  


Current Time: Wed Jul 23 17:23:43 EDT 2025

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

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

Back to the top