Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » [XBase] Corss-referencing function definitions
[XBase] Corss-referencing function definitions [message #1395735] Mon, 07 July 2014 10:12 Go to next message
Neeraj Bhusare is currently offline Neeraj BhusareFriend
Messages: 177
Registered: July 2009
Location: Canada
Senior Member
Hi,

I have created a simple DSL [0] for defining functions (See [1] for example). Also, defined mapping to the Java model [2]. Do I need to override some method in the XBaseScopeProvider to enable cross-referencing of functions [3] ?

I have looked at few examples [4], however I haven't found any clue so far. Any suggestions/tips ?

[0] https://github.com/nbhusare/XBase-test/blob/master/org.xtext.example.function/src/org/xtext/example/function/FunctionDsl.xtext

[1] function getBooksInLibrary (Library library) : List<Book> {
return library.books
}

[2] https://github.com/nbhusare/XBase-test/blob/master/org.xtext.example.function/src/org/xtext/example/function/jvmmodel/FunctionDslJvmModelInferrer.xtend

[3] function getBook (Library library, String bookName) : Book {

for(Book book : getBooksInLibrary(library)) { // Cross-referencing getBooksInLibrary()
if (book.name.equals(bookName)) {
return book;
}
}
return null
}

[4]
http://www.eclipse.org/Xtext/7languagesDoc.html

Thanks in advance.


Twitter : @NeerajBhusare
Blog : https://nbhusare.github.io/
Best regards, Neeraj
Re: [XBase] Corss-referencing function definitions [message #1395957 is a reply to message #1395735] Mon, 07 July 2014 17:07 Go to previous messageGo to next message
Lorenzo Bettini is currently offline Lorenzo BettiniFriend
Messages: 1812
Registered: July 2009
Location: Firenze, Italy
Senior Member
On 07/07/2014 12:12, Neeraj Bhusare wrote:
> Hi,
>
> I have created a simple DSL [0] for defining functions (See [1] for
> example). Also, defined mapping to the Java model [2]. Do I need to
> override some method in the XBaseScopeProvider to enable
> cross-referencing of functions [3] ?
> I have looked at few examples [4], however I haven't found any clue so
> far. Any suggestions/tips ?
>
> [0]
> https://github.com/nbhusare/XBase-test/blob/master/org.xtext.example.function/src/org/xtext/example/function/FunctionDsl.xtext
>
>
> [1] function getBooksInLibrary (Library library) : List<Book> {
> return library.books
> }
> [2]
> https://github.com/nbhusare/XBase-test/blob/master/org.xtext.example.function/src/org/xtext/example/function/jvmmodel/FunctionDslJvmModelInferrer.xtend
>
>
> [3] function getBook (Library library, String bookName) : Book {
>
> for(Book book : getBooksInLibrary(library)) { // Cross-referencing
> getBooksInLibrary() if (book.name.equals(bookName)) {
> return book; } } return null }
> [4]
> http://www.eclipse.org/Xtext/7languagesDoc.html
>
> Thanks in advance.
>

Hi

if you infer things correctly and consistently in the jvm model inferrer
you don't need to tweak the xbase scope provider... are you asking
because something is not working in your case?

cheers
Lorenzo

--
Lorenzo Bettini, PhD in Computer Science, DI, Univ. Torino
HOME: http://www.lorenzobettini.it
Xtext Book:
http://www.packtpub.com/implementing-domain-specific-languages-with-xtext-and-xtend/book


Re: [XBase] Corss-referencing function definitions [message #1396290 is a reply to message #1395957] Tue, 08 July 2014 05:14 Go to previous messageGo to next message
Neeraj Bhusare is currently offline Neeraj BhusareFriend
Messages: 177
Registered: July 2009
Location: Canada
Senior Member
Hi Lorenzo,

Thanks for responding. In the function below, the call to "getBooksInLibrary(library)" doesn't seem to work. Similar to getBook, getBooksInLibrary is a function definition.

In the model inferrer [2], I have mapped to a Java class, and the function is mapped to a Java function. This allows me to do something like new getBooksInLibrary().getBooksInLibrary(library), however, this is not what I need.

In short, the method getBooksInLibrary() should show up when I perform content-assist in the method getBook.

function getBook (Library library, String bookName) : Book {
for(Book book : getBooksInLibrary(library)) { // Cross-referencing getBooksInLibrary()
if (book.name.equals(bookName)) {
return book;
}
}
return null
}


Twitter : @NeerajBhusare
Blog : https://nbhusare.github.io/
Best regards, Neeraj

[Updated on: Tue, 08 July 2014 05:29]

Report message to a moderator

Re: [XBase] Corss-referencing function definitions [message #1396378 is a reply to message #1396290] Tue, 08 July 2014 08:08 Go to previous messageGo to next message
Lorenzo Bettini is currently offline Lorenzo BettiniFriend
Messages: 1812
Registered: July 2009
Location: Firenze, Italy
Senior Member
On 08/07/2014 07:14, Neeraj Bhusare wrote:
> Hi Lorenzo,
>
> Thanks for responding. In the function below, the call to
> "getBooksInLibrary(library)" doesn't seem to work. Similar to getBook,
> getBooksInLibrary is a function definition.
> In the model inferrer [2], I have mapped to a Java class, and the
> function is mapped to a Java function. I believe I have done it correctly.
>
> function getBook (Library library, String bookName) : Book {
> for(Book book : getBooksInLibrary(library)) { // Cross-referencing
> getBooksInLibrary() if (book.name.equals(bookName)) {
> return book; } } return null }

mh... but are Library and Book types visible in your test program? Are
they imported?

--
Lorenzo Bettini, PhD in Computer Science, DI, Univ. Torino
HOME: http://www.lorenzobettini.it
Xtext Book:
http://www.packtpub.com/implementing-domain-specific-languages-with-xtext-and-xtend/book


Re: [XBase] Corss-referencing function definitions [message #1396433 is a reply to message #1396378] Tue, 08 July 2014 09:34 Go to previous messageGo to next message
Neeraj Bhusare is currently offline Neeraj BhusareFriend
Messages: 177
Registered: July 2009
Location: Canada
Senior Member
Yes, the Library and Book types are imported and are visible inside the function definition. To add, these types are defined using the Entity Dsl.

https://github.com/nbhusare/XBase-test/blob/master/org.xtext.example.entity/src/org/xtext/example/entity/EntityDsl.xtext
https://github.com/nbhusare/XBase-test/blob/master/org.xtext.example.entity/src/org/xtext/example/entity/jvmmodel/EntityDslJvmModelInferrer.xtend




Twitter : @NeerajBhusare
Blog : https://nbhusare.github.io/
Best regards, Neeraj
Re: [XBase] Corss-referencing function definitions [message #1397774 is a reply to message #1396290] Thu, 10 July 2014 06:28 Go to previous message
Lorenzo Bettini is currently offline Lorenzo BettiniFriend
Messages: 1812
Registered: July 2009
Location: Firenze, Italy
Senior Member
On 08/07/2014 07:14, Neeraj Bhusare wrote:
> Hi Lorenzo,
>
> Thanks for responding. In the function below, the call to
> "getBooksInLibrary(library)" doesn't seem to work. Similar to getBook,
> getBooksInLibrary is a function definition.
> In the model inferrer [2], I have mapped to a Java class, and the
> function is mapped to a Java function. I believe I have done it correctly.
>
> function getBook (Library library, String bookName) : Book {
> for(Book book : getBooksInLibrary(library)) { // Cross-referencing
> getBooksInLibrary() if (book.name.equals(bookName)) {
> return book; } } return null }

Hi

I've just noted that in your function dsl

https://github.com/nbhusare/XBase-test/blob/master/org.xtext.example.function/src/org/xtext/example/function/FunctionDsl.xtext

you can define a single function in a FunctionModel

each function is inferred as a method inside an inferred class, thus
from a function you can't simply access another function (because that
corresponds to a method in another class); you should create an instance
of the inferred class...

so you probably need to customize the scoping...

you might also have to rethink your design... first of all, since these
functions should be callable without an object you might want to infer
them as static methods. After that it could probably be enough to make
all the inferred classes available as implicit imports.

cheers
Lorenzo

--
Lorenzo Bettini, PhD in Computer Science, DI, Univ. Torino
HOME: http://www.lorenzobettini.it
Xtext Book:
http://www.packtpub.com/implementing-domain-specific-languages-with-xtext-and-xtend/book


Previous Topic:Xtext Editor / CellEditor in e4 RCP
Next Topic:Is there a way to infer a non-JVM dsl model
Goto Forum:
  


Current Time: Thu Apr 18 09:35:20 GMT 2024

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

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

Back to the top