Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » [ report ""
[ report "" [message #788345] Wed, 01 February 2012 12:30 Go to next message
Sebastian Burg is currently offline Sebastian Burg
Messages: 9
Registered: November 2011
Junior Member
Hi,

i am using the Serializer to serialize my Result in the Generator. But now it occurs, that i seem to lose some Tokens.

From the Input: assume always test
Derives this: assert test [ report ""

When i Input only: assume always
It derives: assert always [ report ""

My Grammar itself seem to be ok. Its too big to post, but assume and always are terminals, and test is a value of ID

Any Ideas?!
Re: [ report "" [message #788395 is a reply to message #788345] Wed, 01 February 2012 13:54 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian Dietrich
Messages: 5843
Registered: July 2009
Senior Member
Hi,

without an reproducable grammar it is hard to help
are you sure your grammar isnt looing information somewhere?

~Christian
Re: [ report "" [message #788966 is a reply to message #788345] Thu, 02 February 2012 07:53 Go to previous messageGo to next message
Sebastian Burg is currently offline Sebastian Burg
Messages: 9
Registered: November 2011
Junior Member
Hi,

i looked at the grammar and fixed some Parts, but there are some things, which still dont seem right, but i will try to send a bug report on this.

I think there is a problem with the serializer, because even the generation is inconsistent when generated multiple times without changing anything.

Thanks anyway
Re: [ report "" [message #789115 is a reply to message #788966] Thu, 02 February 2012 11:06 Go to previous messageGo to next message
Henrik Lindberg is currently offline Henrik Lindberg
Messages: 2492
Registered: July 2009
Senior Member
On 2012-02-02 13:53, Sebastian Burg wrote:
> I think there is a problem with the serializer, because even the
> generation is inconsistent when generated multiple times without
> changing anything.

This can happen when you do not have enough resources when generating
from the grammar. Make sure you have plenty of memory available, and
increase the timeout. This gives you more consistent results.

However, if the grammar takes a really long time to generate, and
behaves this way, it is likely that you have many ambiguities and issues
in the grammar.

Regards
- henrik
Re: [ report "" [message #789196 is a reply to message #789115] Thu, 02 February 2012 13:16 Go to previous messageGo to next message
Sebastian Burg is currently offline Sebastian Burg
Messages: 9
Registered: November 2011
Junior Member
Hello,

i reduced the Grammar now, after a few other problems i can compile the reduced part now.
But, how do i set the timeout when running the Generator from an Eclipse Application?

I gave the Editor enough memory i think, 512MB should do, it doesnt seem as if he has any problems. The Generation is very fast. But still inconsistent, and sadly very wrong.

Re: [ report "" [message #789258 is a reply to message #789196] Thu, 02 February 2012 14:42 Go to previous messageGo to next message
Andreas Graf is currently offline Andreas Graf
Messages: 149
Registered: July 2009
Senior Member
I am using the serializer in a non-trivial context and it seems to work quite OK. It really would be interesting to discuss your grammar - actually if you intend to file a bug as you indicated you should boil it down to a minimal reproducable example anyway.

As pointed out be Christian, it could easily be your grammar. E.g., I had non-deterministic serialization in an example below:

Operation: name=ID '(' arguments+=Argument+ (',' arguments+=Argument)* ')'

It parses my input fine but the serialization sometimes emits ',' and sometime not.
It took me a while to spot the problem Smile

Andreas
Re: [ report "" [message #789274 is a reply to message #789258] Thu, 02 February 2012 15:00 Go to previous messageGo to next message
Ed Willink is currently offline Ed Willink
Messages: 3840
Registered: July 2009
Senior Member
Hi Andreas

Interesting example; takes a moment to spot the problem even with the clue.

But surely it should not be an unpredictable result.

I would expect the implementation to be
- greedy on the first argument
- but possibly greedy on the last
- and just possibly ambiguous with an error message

whichever of the above is implemented could be documented and would not
give unpredictable results.

Regards

Ed Willink

On 02/02/2012 19:42, Andreas Graf wrote:
> I am using the serializer in a non-trivial context and it seems to
> work quite OK. It really would be interesting to discuss your grammar
> - actually if you intend to file a bug as you indicated you should
> boil it down to a minimal reproducable example anyway.
>
> As pointed out be Christian, it could easily be your grammar. E.g., I
> had non-deterministic serialization in an example below:
>
> Operation: name=ID '(' arguments+=Argument+ (',' arguments+=Argument)*
> ')'
>
> It parses my input fine but the serialization sometimes emits ',' and
> sometime not.
> It took me a while to spot the problem :)
>
> Andreas
>
Re: [ report "" [message #789654 is a reply to message #789274] Fri, 03 February 2012 03:31 Go to previous messageGo to next message
Sebastian Burg is currently offline Sebastian Burg
Messages: 9
Registered: November 2011
Junior Member
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 @.

Could it be a cache problem?

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.
Re: [ report "" [message #789766 is a reply to message #789654] Fri, 03 February 2012 06:27 Go to previous messageGo to next message
Henrik Lindberg is currently offline Henrik Lindberg
Messages: 2492
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 11:49 Go to previous messageGo to next message
Sebastian Burg is currently offline 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 12:08]

Report message to a moderator

Re: [ report "" [message #800948 is a reply to message #800895] Fri, 17 February 2012 13:31 Go to previous messageGo to next message
Henrik Lindberg is currently offline Henrik Lindberg
Messages: 2492
Registered: July 2009
Senior Member
On 2012-17-02 17:49, Sebastian Burg wrote:
>

?

- henrik
Re: [ report "" [message #801022 is a reply to message #800948] Fri, 17 February 2012 15:38 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian Dietrich
Messages: 5843
Registered: July 2009
Senior Member
Hi,

looks strange to me. in doubt: filing a bug is better than not filing it Wink

~Christian
Re: [ report "" [message #802686 is a reply to message #801022] Mon, 20 February 2012 04:53 Go to previous message
Sebastian Burg is currently offline Sebastian Burg
Messages: 9
Registered: November 2011
Junior Member
Submitted this as Bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=372007
Previous Topic:Exception when testing language
Next Topic:Catch Unquoted String
Goto Forum:
  


Current Time: Wed Apr 16 23:58:30 EDT 2014

Powered by FUDForum. Page generated in 0.07181 seconds