Grammar Mixins [message #1007459] |
Tue, 05 February 2013 22:39  |
Eclipse User |
|
|
|
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 #1007975 is a reply to message #1007459] |
Fri, 08 February 2013 07:17   |
Eclipse User |
|
|
|
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   |
Eclipse User |
|
|
|
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] by Moderator Report message to a moderator
|
|
|
|
Re: Grammar Mixins [message #1008211 is a reply to message #1008130] |
Mon, 11 February 2013 13:41   |
Eclipse User |
|
|
|
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 #1008658 is a reply to message #1008252] |
Wed, 13 February 2013 13:17   |
Eclipse User |
|
|
|
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   |
Eclipse User |
|
|
|
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
|
|
|
Re: Grammar Mixins [message #1008699 is a reply to message #1008672] |
Wed, 13 February 2013 16:01   |
Eclipse User |
|
|
|
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 #1009459 is a reply to message #1009455] |
Fri, 15 February 2013 07:19   |
Eclipse User |
|
|
|
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
[Updated on: Fri, 15 February 2013 07:55] by Moderator Report message to a moderator
|
|
|
Re: Grammar Mixins [message #1009555 is a reply to message #1009459] |
Fri, 15 February 2013 10:05   |
Eclipse User |
|
|
|
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   |
Eclipse User |
|
|
|
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);
}
}
|
|
|
|
|
Re: Grammar Mixins [message #1010716 is a reply to message #1010074] |
Mon, 18 February 2013 05:01   |
Eclipse User |
|
|
|
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] by Moderator Report message to a moderator
|
|
|
|
Re: Grammar Mixins [message #1011068 is a reply to message #1010761] |
Mon, 18 February 2013 19:40   |
Eclipse User |
|
|
|
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 #1744557 is a reply to message #1008211] |
Wed, 28 September 2016 09:11  |
Eclipse User |
|
|
|
junior developer wrote on Mon, 11 February 2013 13:41My 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] by Moderator Report message to a moderator
|
|
|
Powered by
FUDForum. Page generated in 0.03948 seconds