Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Call functions from other files
Call functions from other files [message #1725711] Mon, 07 March 2016 08:46 Go to next message
Josselin Kerdraon is currently offline Josselin KerdraonFriend
Messages: 29
Registered: February 2016
Junior Member
Hi,

I'm developing a grammar where user will be able to declare functions in the editor or in other files. I would like this editor to be able to recognize when the user call a function developed in another file.

The idea I had for the grammar validation part was to copy function declarations in the editor's text, but hidden of this editor.

For example:

//Part hidden
def addition (var a, var b, var c){
        c=a+b;
}
//Part typed by the user in the editor
var a=1;
var b=2;
var c=0;
addition(a,b,c);


I tried to use the setVisibleRegion of my editor's viewer, but it doesn't work.

How could I do that ?

Regards
Re: Call functions from other files [message #1725723 is a reply to message #1725711] Mon, 07 March 2016 10:02 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14077
Registered: July 2009
Senior Member
hi,

i dont get that.
in xtext by default named things from one file is visible from other files.
so you want need this hidden thing at all


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de

[Updated on: Mon, 07 March 2016 10:09]

Report message to a moderator

Re: Call functions from other files [message #1725731 is a reply to message #1725723] Mon, 07 March 2016 10:29 Go to previous messageGo to next message
Josselin Kerdraon is currently offline Josselin KerdraonFriend
Messages: 29
Registered: February 2016
Junior Member
Hi,

So how do I import script written in other files to my editor (an implicit import ) ?
Re: Call functions from other files [message #1725736 is a reply to message #1725731] Mon, 07 March 2016 10:53 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14077
Registered: July 2009
Senior Member
By default you have to do nothing. How does your grammar and scoping look
like


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Call functions from other files [message #1725754 is a reply to message #1725736] Mon, 07 March 2016 12:45 Go to previous messageGo to next message
Josselin Kerdraon is currently offline Josselin KerdraonFriend
Messages: 29
Registered: February 2016
Junior Member
Well, currently I can't test other files because the data files manager is not working yet. So I just supposed that files created would not be detected in the editor.

Function part of my grammar looks like this:

CalcDeclaration  returns newFunction:
	'def' name=STR '('inParameters+=InVariable (',' inParameters+=InVariable )* (',' outParameters+=OutVariable)* ')' '{'
		instructions+=Instruction*
	'}'
;

	
FunctionCall:
	functionName=[newFunction|STR] '('(arguments+=[Assignable|STR] ',')*  arguments+=[Assignable|STR] ')' 
	;


My ScopeProvider is currently empty.
Re: Call functions from other files [message #1725759 is a reply to message #1725754] Mon, 07 March 2016 13:19 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14077
Registered: July 2009
Senior Member
this should work fine if both files are in the same project (in eclipse) or in the same resourceset standalone.

Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Call functions from other files [message #1725760 is a reply to message #1725759] Mon, 07 March 2016 13:27 Go to previous messageGo to next message
Josselin Kerdraon is currently offline Josselin KerdraonFriend
Messages: 29
Registered: February 2016
Junior Member
They are in the same project but not in the same eclipse plugin

I mean, this application will store files containing functions. This files will be managed by a plugin (and stored in a ftp server).
In this application there are GEF components used to display values. This values can be calculated programmatically with an editor using a language (with xtext). You think that these editors will be able to find automatically the functions written in the files ?

[Updated on: Mon, 07 March 2016 13:34]

Report message to a moderator

Re: Call functions from other files [message #1725764 is a reply to message #1725760] Mon, 07 March 2016 13:39 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14077
Registered: July 2009
Senior Member
if you adapt the scoping accordingly. and or create the resourceset properly (have no idea what you exactly do)

Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Call functions from other files [message #1725768 is a reply to message #1725764] Mon, 07 March 2016 14:02 Go to previous messageGo to next message
Josselin Kerdraon is currently offline Josselin KerdraonFriend
Messages: 29
Registered: February 2016
Junior Member
It's a big project so it's difficult to explain but:

A manager plugin provides files containing functions written with my grammar to be loaded.
My editor's plugin can access to this manager. So I want that, when I open an editor, files are read and function references are created. The goal is: when I write a function call in the editor, it's validated when the function is in one of this file.

I'm trying to see how to adapt scoping

[Updated on: Mon, 07 March 2016 14:02]

Report message to a moderator

Re: Call functions from other files [message #1725774 is a reply to message #1725768] Mon, 07 March 2016 14:45 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14077
Registered: July 2009
Senior Member
Du you use embedded editor?

Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Call functions from other files [message #1725777 is a reply to message #1725774] Mon, 07 March 2016 15:10 Go to previous messageGo to next message
Josselin Kerdraon is currently offline Josselin KerdraonFriend
Messages: 29
Registered: February 2016
Junior Member
Yes and I initialize it like this:

        EmbeddedEditorFactory factory = injector.getInstance(EmbeddedEditorFactory.class);
        final EmbeddedEditor handle = factory.newEditor(resourceProvider).showErrorAndWarningAnnotations().withParent(composite);

        final EmbeddedEditorModelAccess partialEditor = handle.createPartialEditor(true);

        ScriptStandaloneSetup.doSetup();
        if (script != null) {
            String s = script.toString().trim().replaceAll("[;]", ";\n").replaceAll("[{]", "{\n");
            handle.getDocument().set(script.toString());
            handle.getViewer().setVisibleRegion(0, script.toString().length());
        } else {
            handle.getDocument().set("\n");
            handle.getViewer().setVisibleRegion(0, 1);
        }

Re: Call functions from other files [message #1725780 is a reply to message #1725777] Mon, 07 March 2016 15:14 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14077
Registered: July 2009
Senior Member
then i think it is the best to have all in the same file.
you can tweak the visible part using

EmbeddedEditorModelAccess.setModel(XtextDocument document, String prefix, String editablePart, String suffix)


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Call functions from other files [message #1725790 is a reply to message #1725780] Mon, 07 March 2016 16:39 Go to previous message
Josselin Kerdraon is currently offline Josselin KerdraonFriend
Messages: 29
Registered: February 2016
Junior Member
I don't have a good version of Xtext (there is no setModel, just updateModel...). But it works perfectly by using updatePrefix. So my problem is fixed

Thanks for your help Christian Wink
Previous Topic:Create xmi file in runtime through saving
Next Topic:Different prefix for Special Character in RuleCall
Goto Forum:
  


Current Time: Sat Oct 23 16:01:31 GMT 2021

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

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

Back to the top