|
|
|
|
|
|
|
|
Re: [ report "" [message #789766 is a reply to message #789654] |
Fri, 03 February 2012 11:27 |
Henrik Lindberg Messages: 2509 Registered: July 2009 |
Senior Member |
|
|
On 2012-03-02 9:31, Sebastian Burg wrote:
> I just didnt have the time to boil it down, as i am happy to have a
> running system right now to show the client.
>
> The problem is, the grammar is really deterministic at the given point.
> The first word is a terminal word. So i dont see how it should refer to
> another path in the grammar.
> i.e.
> expression:
> ASSERT ex=ID AT fo=bar | ASSUME ex=ID value=SomeString;
> terminal ASSERT: 'assert';
> terminal ASSUME: 'assume';
> terminal AT: '@';
>
> as it is now, if there i enter assume, sometimes i get assert xyz @.
>
Not surprising, nothing is produced that makes the *result* differ, the
fact that an 'assert' or an 'assume' was seen is lost and you get an
instance of 'expression'. You are not showing the grammar for "fo=bar"
so impossible to tell you exactly what is going on.
You need something in the created object that keeps the information. You
can use a boolean flag, assign the keyword, or use two different classes
(this is what typically used).
// using boolean flag
expression: isAssert ?= 'assert' 'at' ... ;
// assigning the keyword
expression : type = ASSERT AT ... | type = ASSUME ... ;
// using classes
expression: AssertExpression | AssumeExpression ;
AssertExpression : 'assert' '@' ... ;
AssumeExpression : 'assign' ... ;
Another thing to possibly change is using the Xtext keyword support as
using terminals for keywords is usually not a very good idea.
Use either:
expression: 'assert' '@' fo = bar | 'assume' ex= .... ;
or
expression: ASSERT AT ...
ASSERT: 'assert';
AT: '@';
....
Doing so, they will be recognized as keywords.
> Could it be a cache problem?
>
no
> I tried new example to file with a bug, but yet havent been able to
> reproduce the problem. As i said, didnt have the time yet. I will try
> today after the presentation.
The problem is in your grammar.
Hope that helps.
Regards
- henrik
|
|
|
Re: [ report "" [message #800895 is a reply to message #789766] |
Fri, 17 February 2012 16:49 |
Sebastian Burg Messages: 9 Registered: November 2011 |
Junior Member |
|
|
Hi,
i now had time to rebuild the problem i had. And even on a small scale it occures.
The Grammar is derived from the example:grammar org.xtext.example.mydsl.MyDsl with org.eclipse.xtext.common.Terminals
generate myDsl "http://www.xtext.org/example/mydsl/MyDsl"
Model:
greetings+=Greeting*;
Greeting:
'Hello' Outname=VName '!';
VName:
( 'vorname' Intname=ID)
| ('nachname' '+'Intname=ID'+')
;
I have a custom ToString Method, which is generated into the VNameImpl.java and it looks like this:
@SuppressWarnings("restriction")
public class ToString {
private static Serializer SERIALIZER = null;
private static Serializer getSerializer() {
if (SERIALIZER == null) { // lazy creation
SERIALIZER = Guice.createInjector(new de.fzi.AssertEditorRuntimeModule()).getInstance(Serializer.class);
}
return SERIALIZER;
}
public static String valueOf(EObject eobj) {
if (eobj==null) {
return "";
}
try {
return getSerializer().serialize(eobj);
} catch (Exception ex) { // fall back:
ex.printStackTrace();
System.out.println("Error ToString"+ex.getMessage()+ " "+ex.getStackTrace());
return eobj.getClass().getSimpleName()+'@'+eobj.hashCode();
}
}
}
the Xtend for the Generation is pretty simple
class MyDslGenerator implements IGenerator {
override void doGenerate(Resource resource, IFileSystemAccess fsa
for (e : resource.allContents.toIterable.filter(typeof(Greeting)))
{
fsa.generateFile(e.outname.intname+".out", compile(e))
}
}
def compile(Greeting p)
{
'''
«p.outname»
'''
}
}
Now if i open the eclipse with this Plugin and enter a text like this:
Hello nachname + something + !
Everything is fine. something.out is generated with the expected text "nachname + something +"
if i then change the file to
Hello vorname something !
something.out does NOT change.
i then wrote
Hello vorname something2 !
int the file, something2.out is generated and contains
nachname + something2 +
which is obviously wrong, it should contain
vorname something2
I can't find a reason why this is the case.... like i stated before "it takes the wrong turn"
Please help me.... should i submit a bug report?
I have attached my whole workspace for this project.
[Updated on: Fri, 17 February 2012 17:08] Report message to a moderator
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.05426 seconds