Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » extending XBase for an interpreted component definition(Solved most of issues. Best practice questions remain on Scope Resolution and Inference)
extending XBase for an interpreted component definition [message #856022] Wed, 25 April 2012 09:49
John Blue is currently offline John BlueFriend
Messages: 7
Registered: April 2012
Location: San Francisco
Junior Member

I've extended my language from XBase, and now trying to customize scope resolution so I can interprete it to get instances of my "Components".

Here is a sample of what I want to be be able to express:

1. module myModule
2. componentType test configuration com.acme.Book
3. val subject= "xtext"
4. var description = subject.toUpperCase + " Book"
5. component test myComponent {
6.	 author = "John"
7.	 title =    subject 
8.	 name  = subject + "rocks!"
9.}


The idea is that Component's definition is described by the Configuration of the component type which is a JVMType.

I modeled the component definition as AssignmentBlock which is subtype of XBlockExpression.

In the scope provider I overrode createLocalVarScope such that the AssignmentBlock sets the contextType (componentType's configuration class) as "THIS". And I had to explicitly setup the parentScope for the module and collect its XVariableDeclarations as EObjectDescriptions.

Although this worked, dose not seem like it is the right approach, since the AssignmentBlock may be many levels deep in the containment in real application.

Best Practice Questions:
1. Passing Variables top-down: Is there a better way passing the Module variables to the scope of AssignmentBlock?
3. What to Infer? In real life, Component or ComponentType will be mapped to existing java classes, so no code gen is necessary. Variables that are defined at the Module level will be kept by a possibly generated or interpreted Java bean. As such: I only "infer" Module to a JvmType in the inferer, should I be infering Component or ComponentType as well?
4. Is getContextType override in ScopeProvider appropriate?

5. Remaining issue on operators: "+" on lines 4 and 8 are not recognized. Any hints as to why it may be failing?

---------------------------------
Supporting files files are attached for your reference.

Here is the full grammar:

grammar zorg.dummy.Dummy with org.eclipse.xtext.xbase.Xbase
...
Module:
	'module' name=QualifiedName
	(elements += XExpressionInsideBlock | elements += ComponentType )*;

ComponentType:
	'componentType' name = ID  
	('configuration' configuration = JvmTypeReference)? ;

Component returns xbase::XExpression:
	{Component} 'component' type=[ComponentType|QualifiedName] 
	name=ValidID assignments = AssignmentBlock;

AssignmentBlock returns xbase::XBlockExpression:
	{AssignmentBlock} '{'
    	(expressions+=XAssignment ';'?)* '}' ;

XPrimaryExpression returns xbase::XExpression:
	XConstructorCall |   
	XBlockExpression |
	XSwitchExpression |
	XFeatureCall |
	XLiteral |
	XIfExpression |      
	XForLoopExpression | 
	XWhileExpression |   
	XDoWhileExpression | 
	XThrowExpression |
	XReturnExpression |  
	XTryCatchFinallyExpression |
	XParenthesizedExpression | 
	Component
;

[Updated on: Thu, 26 April 2012 06:50]

Report message to a moderator

Previous Topic:making unique instances
Next Topic:Marker accumulation without an Xtext builder
Goto Forum:
  


Current Time: Sat Jul 11 18:56:10 GMT 2020

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

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

Back to the top