Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Grammar Mixins
Grammar Mixins [message #1007459] Tue, 05 February 2013 22:39 Go to next message
junior developer is currently offline junior developerFriend
Messages: 354
Registered: January 2013
Senior Member
Hello all ,
I work grammar inheritance and ı take an error I think this error about path (egisterGeneratedEPackage ,registerGenModelFile)but I dont solved it Sad I try this example from xtext documentation.Add a plug-in dependency in the MANIFEST.MF.(add required path in the GenerateUsages.MWE2).I generated language artifacts I do not take an error when debuging.I take ANTLR error , so that I do not create useges extension.Error is in the InternalUsagesParser class(UI package).How solve this problem? ,please help me .

Error:The method getRuleAAccess() from the type UsagesGrammarAccess refers to the missing type RuleAElements- The type org.xtext.example.definitions.services.DefinitionsGrammarAccess$RuleAElements cannot be resolved. It is indirectly referenced from required .class files
--------------------------------------------------------------------------------
My supergrammar:
grammar org.xtext.example.definitions.Definitions with
org.eclipse.xtext.common.Terminals

generate definitions "http://www.xtext.org/example/definitions/Definitions"

RuleA : "a" stuff=RuleB;
RuleB : "{" name=ID "}";
------------------------------------------------------------------------------------
My subgrammar :
grammar org.xtext.example.usages.Usages with org.xtext.example.definitions.Definitions

generate usages "http://www.xtext.org/example/usages/Usages"

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

Model : (ruleAs+=RuleA)*;

RuleB : '[' name=ID ']'; //overriding
----------------------------------------------------------------------
Re: Grammar Mixins [message #1007975 is a reply to message #1007459] Fri, 08 February 2013 07:17 Go to previous messageGo to next message
Sebastian Zarnekow is currently offline Sebastian ZarnekowFriend
Messages: 3118
Registered: July 2009
Senior Member
Hi,

please make sure that the runtime plugin for the definitions language
exports all its packages, esp. the package
org.xtext.example.definitions.services

Regards,
Sebastian
--
Looking for professional support for Xtext, Xtend or Eclipse Modeling?
Go visit: http://xtext.itemis.com

Am 05.02.13 23:39, schrieb junior developer:
> Hello all ,
> I work grammar inheritance and ı take an error I think this error about
> path (egisterGeneratedEPackage ,registerGenModelFile)but I dont solved
> it :( I try this example from xtext documentation.Add a plug-in
> dependency in the MANIFEST.MF.(add required path in the
> GenerateUsages.MWE2).I generated language artifacts I do not take an
> error when debuging.I take ANTLR error , so that I do not create useges
> extension.Error is in the InternalUsagesParser class(UI package).How
> solve this problem? ,please help me .
>
> Error:The method getRuleAAccess() from the type UsagesGrammarAccess
> refers to the missing type RuleAElements- The type
> org.xtext.example.definitions.services.DefinitionsGrammarAccess$RuleAElements
> cannot be resolved. It is indirectly referenced from required .class files
> --------------------------------------------------------------------------------
>
> My supergrammar:
> grammar org.xtext.example.definitions.Definitions with
> org.eclipse.xtext.common.Terminals
>
> generate definitions "http://www.xtext.org/example/definitions/Definitions"
>
> RuleA : "a" stuff=RuleB;
> RuleB : "{" name=ID "}";
> ------------------------------------------------------------------------------------
>
> My subgrammar :
> grammar org.xtext.example.usages.Usages with
> org.xtext.example.definitions.Definitions
>
> generate usages "http://www.xtext.org/example/usages/Usages"
> import "http://www.eclipse.org/emf/2002/Ecore" as ecore
>
> Model : (ruleAs+=RuleA)*;
>
> RuleB : '[' name=ID ']'; //overriding
> ----------------------------------------------------------------------
>
Re: Grammar Mixins [message #1008129 is a reply to message #1007975] Sun, 10 February 2013 12:28 Go to previous messageGo to next message
junior developer is currently offline junior developerFriend
Messages: 354
Registered: January 2013
Senior Member
Hi Sebastian,

When I generate the language code, I receive previously mentioned error for InternalUsagesParser class in org.xtext.example.usages.ui.contentassist.antlr.internal package. The error occures in the grammarAccess.getRuleAAccess() function call of the automatically generated ruleRuleA() function. Interestingly the project works without any problem. I write programs in the editor and I don't take any error, e.g. I can use overriding rule.
Could you possibly introduce me a solution to resolve this error?

Best regards

[Updated on: Sun, 10 February 2013 12:31]

Report message to a moderator

Re: Grammar Mixins [message #1008130 is a reply to message #1008129] Sun, 10 February 2013 14:14 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14738
Registered: July 2009
Senior Member
Hi,

simply adding a dep (manifest.mf) from subgrammar.ui to supergrammar.ui doesnt work


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Day Job: https://www.everest-systems.com
Re: Grammar Mixins [message #1008211 is a reply to message #1008130] Mon, 11 February 2013 13:41 Go to previous messageGo to next message
junior developer is currently offline junior developerFriend
Messages: 354
Registered: January 2013
Senior Member
Hi Christian,
My problem is solved.My other problem is abouth Automatic Validation error and warning changes.I can write my own mistakes rather than automatic generated syntax errors.Such as,instead of mismatched input '<EOF>' expecting 'something' ,I can write own error definition automatic validation error and warning.How can I do it ?Is it possible to accomplish this?

Best Regards
Re: Grammar Mixins [message #1008252 is a reply to message #1008211] Mon, 11 February 2013 18:29 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14738
Registered: July 2009
Senior Member
HI,

the hook for that is org.eclipse.xtext.parser.antlr.SyntaxErrorMessageProvider


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Day Job: https://www.everest-systems.com
Re: Grammar Mixins [message #1008658 is a reply to message #1008252] Wed, 13 February 2013 13:17 Go to previous messageGo to next message
junior developer is currently offline junior developerFriend
Messages: 354
Registered: January 2013
Senior Member
Hi Christian,
I works on Automatic Validation customize.Which package is used for create SyntaxErrorMessageProviderCustom xtend class ?
I create SyntaxErrorMessageProviderCustom xtend class that is extended from SyntaxErrorMessageProvider, under the org.xtext.example.mydsl package and register it in the MyDslRuntimeModule.java
public Class<? extends SyntaxErrorMessageProvider > bindIEObjectHoverProvider() {
return SyntaxErrorMessageProviderCustom.class;
}
But My grammar extension did not occur at the run time .I'm so confused. I wonder ,create java class under the org.xtext.example.mydsl.ui package and create interface such as Hover in your blog( http://christiandietrich.wordpress.com/2011/07/16/hover-support-in-xtext-2-0-tutorial/ ).I hope my problem is clear.

Best Regards
Re: Grammar Mixins [message #1008672 is a reply to message #1008658] Wed, 13 February 2013 14:24 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14738
Registered: July 2009
Senior Member
Hi,

i dont get your point. the package doesnt matter, the binding counts

public Class<? extends org.eclipse.xtext.parser.antlr.ISyntaxErrorMessageProvider> bindISyntaxErrorMessageProvider() {
return MySyntaxErrorMessageProvider.class;
}

you may bind it in the runtimemodule or in the ui module only depending on your needs


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Day Job: https://www.everest-systems.com
Re: Grammar Mixins [message #1008699 is a reply to message #1008672] Wed, 13 February 2013 16:01 Go to previous messageGo to next message
junior developer is currently offline junior developerFriend
Messages: 354
Registered: January 2013
Senior Member
Hi Christian,

Thank you very much ,run my program

I create Xtend class below :

package org.xtext.example.mydsl.ui

import org.eclipse.xtext.parser.antlr.SyntaxErrorMessageProvider
import org.eclipse.xtext.IGrammarAccess
import javax.inject.Inject
import org.eclipse.xtext.parser.antlr.ISyntaxErrorMessageProvider$IParserErrorContext
import org.eclipse.xtext.nodemodel.SyntaxErrorMessage
import org.eclipse.xtext.GrammarUtil
class MyDslSyntaxErrorMessageProvider extends SyntaxErrorMessageProvider{

public static val String USED_RESERVED_KEYWORD = "USED_RESERVED_KEYWORD"
@Inject IGrammarAccess grammarAccess
override getSyntaxErrorMessage(IParserErrorContext context) {
val unexpectedText = context?.recognitionException?.token?.text
if (GrammarUtil::getAllKeywords(grammarAccess.getGrammar()).contains(unexpectedText)) {
println(context.defaultMessage)

return new SyntaxErrorMessage('''

"«unexpectedText»" is a reserved keyword which is not allowed as Identifier.

"^«unexpectedText»".''',

USED_RESERVED_KEYWORD)

}

super.getSyntaxErrorMessage(context)

}


}

------------------------------------------------------------

And then I bind it MyDslUiModule.java ,solved my problem

public Class<? extends ISyntaxErrorMessageProvider> bindISyntaxErrorMessageProvider() {
return MyDslSyntaxErrorMessageProvider.class;
}


the code runs but I done it with xtend class . I wonder if I do it with java code .I want to create java class .I do not find enough example with java code.

Best Regards


Re: Grammar Mixins [message #1008702 is a reply to message #1008699] Wed, 13 February 2013 16:07 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14738
Registered: July 2009
Senior Member
Hi I still do not understand your problem and what it does have to do
with Xtend

--
Need training, onsite consulting or any other kind of help for Xtext?
Go visit http://xtext.itemis.com or send a mail to xtext at itemis dot de


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Day Job: https://www.everest-systems.com
Re: Grammar Mixins [message #1009455 is a reply to message #1008702] Fri, 15 February 2013 07:09 Go to previous messageGo to next message
junior developer is currently offline junior developerFriend
Messages: 354
Registered: January 2013
Senior Member
Hi Christian,

I want to doing Automatic Validation customize with java class.In the previous example ,I use xtend class and I write not pure java code.But I want to write pure java in the same example(above).I do not find enough example from the net.Such as http://henrik-eclipse.blogspot.com/2010/05/implementing-date-support-with-quickfix.html.
Re: Grammar Mixins [message #1009459 is a reply to message #1009455] Fri, 15 February 2013 07:19 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14738
Registered: July 2009
Senior Member
Hi I still don't get your problem

@Check
public void check whatever(MyType my type){}

???

or dont you know how to write the SyntaxErrorMessageProvider in java.
if so what exactly is the problem?

--
Need training, onsite consulting or any other kind of help for Xtext?
Go visit http://xtext.itemis.com or send a mail to xtext at itemis dot de


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Day Job: https://www.everest-systems.com

[Updated on: Fri, 15 February 2013 07:55]

Report message to a moderator

Re: Grammar Mixins [message #1009555 is a reply to message #1009459] Fri, 15 February 2013 10:05 Go to previous messageGo to next message
junior developer is currently offline junior developerFriend
Messages: 354
Registered: January 2013
Senior Member
Hi Christian ,
Like the function in the code above, I'd like to write it in Java. My problem in this case is, that don't found enough examples how to write it in Java syntax. I want to write an automatic validation code like in the custom validation code. Can you help me out with that in Java or can you give me some hints?

Best Regards
Re: Grammar Mixins [message #1009609 is a reply to message #1009555] Fri, 15 February 2013 11:32 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14738
Registered: July 2009
Senior Member
HI,

sorry i do not get it? i cannot teach you how to write java

import org.eclipse.xtext.GrammarUtil;
import org.eclipse.xtext.IGrammarAccess;
import org.eclipse.xtext.nodemodel.SyntaxErrorMessage;
import org.eclipse.xtext.parser.antlr.SyntaxErrorMessageProvider;

import com.google.inject.Inject;

public class MyDslSyntaxErrorMessageProvider extends SyntaxErrorMessageProvider {

	public static final String USED_RESERVED_KEYWORD = "USED_RESERVED_KEYWORD";
	@Inject
	IGrammarAccess grammarAccess;

	@Override
	public SyntaxErrorMessage getSyntaxErrorMessage(IParserErrorContext context) {
		if (context.getRecognitionException() != null
				&& context.getRecognitionException().token != null) {
			String unexpectedText = context.getRecognitionException().token
					.getText();
			if (GrammarUtil.getAllKeywords(grammarAccess.getGrammar())
					.contains(unexpectedText)) {
				return new SyntaxErrorMessage(
						unexpectedText
								+ "  is a reserved keyword which is not allowed as Identifier",
						USED_RESERVED_KEYWORD);
			}
		}
		return super.getSyntaxErrorMessage(context);
	}

}


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Day Job: https://www.everest-systems.com
Re: Grammar Mixins [message #1010069 is a reply to message #1009609] Sat, 16 February 2013 12:44 Go to previous messageGo to next message
junior developer is currently offline junior developerFriend
Messages: 354
Registered: January 2013
Senior Member
Hi Christian,
Thank you for your help.I understand java syntax.I prefer to java code for Automatic Validation
Re: Grammar Mixins [message #1010074 is a reply to message #1010069] Sat, 16 February 2013 13:00 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14738
Registered: July 2009
Senior Member
I still do not understand what your actual question is?

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Day Job: https://www.everest-systems.com
Re: Grammar Mixins [message #1010716 is a reply to message #1010074] Mon, 18 February 2013 05:01 Go to previous messageGo to next message
junior developer is currently offline junior developerFriend
Messages: 354
Registered: January 2013
Senior Member
Hi Christian,
My problem is to change default automatic validation error and warning messages and looking for a general solution how to do that.
I've got an example written in xtend-class (see below). I want to extend this code. For different or existing automatic validation error and warning messages I want to add custom messages. For example, I get for Cross-reference an error message ** Couldn't resolve reference to Name 'something' ** which is an automatic validation error, so I want to add or overide with my own code to get my error message something like that ** You cannot call 'something' **. Which functions do I need to realize that and where should I add this to existing keywords. I didn't have found enough sources to get this run, can you give me a hint how to realise it?

package org.xtext.example.mydsl1.ui;
import org.eclipse.xtext.GrammarUtil;
import org.eclipse.xtext.IGrammarAccess;
import org.eclipse.xtext.nodemodel.SyntaxErrorMessage;
import org.eclipse.xtext.parser.antlr.SyntaxErrorMessageProvider;

import com.google.inject.Inject;

public class MyDsl1SyntaxErrorMessageProvider extends SyntaxErrorMessageProvider {

	
	public static final String USED_RESERVED_KEYWORD = "USED_RESERVED_KEYWORD";
	@Inject
	IGrammarAccess grammarAccess;
	
/* I want to change Cross Reference Default Error Message:Couldn't resolve reference to Name 'something'... in my own custom message  */
	@Override
	public SyntaxErrorMessage getSyntaxErrorMessage(IParserErrorContext context) {
		if (context.getRecognitionException() != null && context.getRecognitionException().token != null) {
			String unexpectedText = context.getRecognitionException().token.getText();
			if(GrammarUtil.getAllKeywords(grammarAccess.getGrammar()).contains(unexpectedText)) {
	return new SyntaxErrorMessage( "is a reserved keyword which is not allowed as Identifier",USED_RESERVED_KEYWORD);//changed Automatic validation (mismatched input //'Hello' expecting RULE_ID)
			}
		}
		return super.getSyntaxErrorMessage(context);
	}
	}

[Updated on: Mon, 18 February 2013 07:41]

Report message to a moderator

Re: Grammar Mixins [message #1010761 is a reply to message #1010716] Mon, 18 February 2013 07:42 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14738
Registered: July 2009
Senior Member
As said before: you have to do if else in the syntax error message
provider .

--
Need training, onsite consulting or any other kind of help for Xtext?
Go visit http://xtext.itemis.com or send a mail to xtext at itemis dot de


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Day Job: https://www.everest-systems.com
Re: Grammar Mixins [message #1011068 is a reply to message #1010761] Mon, 18 February 2013 19:40 Go to previous messageGo to next message
junior developer is currently offline junior developerFriend
Messages: 354
Registered: January 2013
Senior Member
Hi Christian,
I did with else if. Thank you very much. Beside that I couldn't override the semantic error messages. I couldn't change with the SyntaxErrorMessageProvider class the "Couldn't resolve reference" default automatic validation message in the code below. Do I use the wrong class for that or do I need a different class to successful?


public class MyDsl1SyntaxErrorMessageProvider extends SyntaxErrorMessageProvider {

//public static final String USED_RESERVED_KEYWORD = "USED_RESERVED_KEYWORD";
//public static String INCOMPLETE_UNORDERED_GROUP = "INCOMPLETE_UNORDERED_GROUP";
@Inject
IGrammarAccess grammarAccess;

@Override
public SyntaxErrorMessage getSyntaxErrorMessage(IParserErrorContext context) {

if (context.getRecognitionException() != null && context.getRecognitionException().token != null) {

String unexpectedText = context.getRecognitionException().token.getText();

if (context.getDefaultMessage().startsWith("missing ")){
return new SyntaxErrorMessage( "missing error ",null);

}
else if(context.getDefaultMessage().startsWith("extraneous input ")){
return new SyntaxErrorMessage( "ID incorrect ",null);
}

else if(context.getDefaultMessage().startsWith("Couldn't resolve reference")) //for cross references
{
return new SyntaxErrorMessage( "incorrect reference variable ",null);//Default error is not change with this error

}
}

return super.getSyntaxErrorMessage(context);

}

}
Best Regards
Re: Grammar Mixins [message #1011081 is a reply to message #1011068] Mon, 18 February 2013 20:17 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14738
Registered: July 2009
Senior Member
Hi,

i strony recommend you to use the debugger to see what is in the context in certain situations


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Day Job: https://www.everest-systems.com
Re: Grammar Mixins [message #1011104 is a reply to message #1011081] Mon, 18 February 2013 21:30 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14738
Registered: July 2009
Senior Member
P.S: regarding the linking error you may hook into org.eclipse.xtext.linking.impl.LinkingDiagnosticMessageProvider

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Day Job: https://www.everest-systems.com
Re: Grammar Mixins [message #1744557 is a reply to message #1008211] Wed, 28 September 2016 09:11 Go to previous message
Martin Westerkamp is currently offline Martin WesterkampFriend
Messages: 9
Registered: September 2016
Junior Member
junior developer wrote on Mon, 11 February 2013 13:41
My problem is solved.


Could you please let us know how you solved the problem? I'm struggling with the same issue right now.

EDIT: I just figured out the solution. The plug-in of the super language needs to be added to the manifest.mf file of the .ide project of the sub language.

[Updated on: Wed, 28 September 2016 09:30]

Report message to a moderator

Previous Topic:xtext rules starts at new line
Next Topic:Embedded Xtext editor slects all text after using updateModel
Goto Forum:
  


Current Time: Mon Dec 30 16:33:57 GMT 2024

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

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

Back to the top