Skip to main content

Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Scoping problem across multiple files
Scoping problem across multiple files [message #1665922] Wed, 11 March 2015 13:03 Go to next message
Ian Warwick is currently offline Ian WarwickFriend
Messages: 44
Registered: April 2012
I am working on a second generation of a grammar that uses the sqlite syntax as well as extra constructs to define migrations, and this can be done across multiple files

for instance

database com.example.ExampleDB

migration 1 {
    create table books (
        id integer,
        title text

database com.example.ExampleDB

migration 2 {
    alter table books add column author text;

database com.example.ExampleDB

migration 3 {
    alter table books rename to manuals;

database com.example.ExampleDB

migration 4 {
    create view stuff as
        select id, title, author from manuals;

This issue I am facing is at migration 4, we select from manuals, which was previously called books, in order to calculate the scope for select columns in migration 4 manuals I need to work back through the migrations to grab all columns from books and manuals, I hope this makes sense.

The problem is the global scope cannot see the migration blocks, so I can't think of how I can get hold of migrations in my scope provide in order to calculate what can be seen since migrations define changes, means that reference names could change.

Would be great if someone could point me in the right direction.


One way I thought of solving this is to modify the grammar to have named migrations rather than numbered, ie:_

	'migration' name=ID 'from' from=[MickeyBlock|QualifiedName] '{' (statements+=DDLStatement ';')* '}';


migrate initial_migration {
    create table books (
        id integer,
        title text

migrate authors_migration from initial_migration {
    alter table books add column author text;

then that would link the migrations together and scope easily across files without having to manually scope migrations.

but a compromise on the syntax also means more typing.

If I can get my numbered migrations in every scope, then I could go with the first approach, but I fear that might mean force loading all models for every scope calculation?



[Updated on: Tue, 17 March 2015 19:32]

Report message to a moderator

Re: Scoping problem across multiple files [message #1681843 is a reply to message #1665922] Tue, 17 March 2015 13:38 Go to previous message
Ian Warwick is currently offline Ian WarwickFriend
Messages: 44
Registered: April 2012
Hey xtext people.

I am still trying to get scope on the migration blocks in the grammar I described.

I tried this:

		var dummy = MickeyLangFactory.eINSTANCE.createMigrationBlock();
		var scope = delegateGetScope(dummy, MickeyLangPackage.Literals.MIGRATION_BLOCK__FROM);
		val name = QualifiedName.create(model.databaseName)


Which is basically a hack, because in my scope I do not have access to these specific blocks so I try to fake a migration block (which points to a previous migration by cross reference on unique name) but it crashes when doing delegateGetScope(...)

Please see the model files here

I my grammar files that do not declare migrations should cross reference to a snapshot of the database (all migrations calculated):

Specifically the file which defines zero migrations:
database com.example.mickeydbexample.TakeawaysDB

create temp view all_restaurants as
		t._id as _id, as takeaway_name,
		t.description as takeaway_description, as takeaway_city,
		t.cuisines as takeaway_cuisines,
		t.rating as takeaway_rating
	from restaurants as t


I want the statements to effectively be able to look into the migrations to calculate whats available at a certain database snapshot point.

There must be an easy way to get access or load all resources within a scope? does it mean loading all resources on every build?

I think if I can get hold of the migrations from every scope point I can calculate what is visible but without them, I have no idea of what the current state of the database is so unable to provide decent editor assistance and cross referencing Sad

I hope my question makes sense, I did try a few things but still not come up with a good solution, any help would be massively appreciated Smile
Previous Topic:Warning for unused declarations
Next Topic:[Xtext 2.8.0] "Storable Resources" documentation?
Goto Forum:

Current Time: Fri May 07 01:36:13 GMT 2021

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

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

Back to the top