Skip to main content



      Home
Home » Modeling » TMF (Xtext) » idea for xbase crib sheet.(here is my attempt at a draft (as a beginner))
idea for xbase crib sheet. [message #935129] Sat, 06 October 2012 14:21
Eclipse UserFriend
I have been reading the documentation (http://www.eclipse.org/Xtext/documentation.html#_17) to try to understand how to use xbase and I am finding it quite hard going. My problem is that lots of entities are introduced, such as: JvmTypeReference, QualifiedName, XBlockExpression and so on. Although I can look these up in the source code I don't really have a mental picture to slot these into. I think it would help if I had some form of crib sheet to give me the big picture. I have tried to work out the tables below. Am I on the right track? Are these the elements that people creating a language/DSL would need to know about? Would it be possible to put something like this into your documentation?

When we get to the generator (compiler) my understanding gets even more murky and I have not got very far with that yet.
What do IQualifiedNameProvider, TypeReferenceSerializer and so on do?
How do I reference a type that is defined in the same file?

I think what would help is a block diagram with the main components on it and arrows between them showing how information gets passed between them and how things get build.

I know you have provided a lot of good examples and I guess users are expected to take the example closest to their application and adapt it. Even so I think it would help to have a better overall picture to help understand the concepts when they arise.

Martin
--------------------------------------------------------------------------------------

Grammar
-------
We first create a model using the grammar. Grammar file for a given project starts like this:

grammar org.myDomain.myProject.myLanguage.Domainmodel with org.eclipse.xtext.xbase.Xbase
generate domainmodel "http: / / www.eclipse.myDomain/myProject/myLanguage/Domainmodel"

We can then refer to Java Library (Jvm prefix) and XBase (X prefix) constructs in the grammar. I have listed some of these in the following tables:

from org.eclipse.xtext.?
----------------------------------
see: github.com/eclipse/?

AbstractElement
JvmIdentifiableElement
JvmFormalParameter
JvmConstructor
JvmType

org.eclipse.xtext.xbase.Xtype
-----------------------------
from github.com/eclipse/xtext/blob/master/plugins/org.eclipse.xtext.xbase/src/org/eclipse/xtext/xbase/Xtype.xtext
Grammar rule
and Interfaces Implementing Classes:
---------- --------------------
JvmTypeReference
example:

XFunctionTypeRef
example:

JvmParameterizedTypeReference
example:

JvmArgumentTypeReference
example:

JvmWildcardTypeReference
example:

JvmTypeParameter
example:

JvmUpperBound :
example: extends myclass

QualifiedName
example: myclass.myfunction


org.eclipse.xtext.xbase.Xbase
-----------------------------
from github.com/eclipse/xtext/blob/master/plugins/org.eclipse.xtext.xbase/src/org/eclipse/xtext/xbase/Xbase.xtext
Grammar rule
and Interfaces Implementing Classes:
---------- --------------------
XExpression XExpressionImpl
example: any valid statement, expression or value

XAssignment XAssignmentImpl
XAssignmentImplCustom
example: a=3

XBinaryOperation XBinaryOperationImpl
XBinaryOperationImplCustom
example: a && b

XBlockExpression XBlockExpressionImpl
example: {a=3;}

XBooleanLiteral XBooleanLiteralImpl
example: true

XCastedExpression XCastedExpressionImpl
example: 2 as int

XClosure XClosureImpl
example: [a | b]

XConstructorCall XConstructorCallImpl
XConstructorCallImplCustom
example: new mytype

XDoWhileExpression XDoWhileExpressionImpl
example: do x=x+1 while (x<10)

XFeatureCall XFeatureCallImpl
XFeatureCallImplCustom
example:

XForLoopExpression XForLoopExpressionImpl
example: for(value:values) myblock

XIfExpression XIfExpressionImpl
example: if(x==2)myblock

XMemberFeatureCall XMemberFeatureCallImpl
XMemberFeatureCallImplCustom
example:

XNullLiteral XNullLiteralImpl
example: null

XReturnExpression XReturnExpressionImpl
example: return 3

XStringLiteral XStringLiteralImpl
example: "my text"

XSwitchExpression XSwitchExpressionImpl
XSwitchExpressionImplCustom
example: switch(a) (case 2:x=3)

XThrowExpression XThrowExpressionImpl
example: throw 9

XTryCatchFinallyExpression XTryCatchFinallyExpressionImpl
example: try {} catch () finally

XTypeLiteral XTypeLiteralImpl
example: typeof(int)

XUnaryOperation XUnaryOperationImpl
XUnaryOperationImplCustom
example: !a

XVariableDeclaration XVariableDeclarationImpl
XVariableDeclarationImplCustom
example: var int a=4

XWhileExpression XWhileExpressionImpl
example: while (a<10){a=a+1}

from org.eclipse.xtext.?
----------------------------------
see: github.com/eclipse/?

XIntLiteral XIntLiteralImpl
example:

XInstanceOfExpression XInstanceOfExpressionImpl
example:

SpecialBlockExpression SpecialBlockExpressionImpl
example:

XAbstractFeatureCall XAbstractFeatureCallImpl
XAbstractFeatureCallImplCustom
example:

XAbstractWhileExpression XAbstractWhileExpressionImpl
example:

from org.eclipse.xtext.xbase.annotations.XbaseWithAnnotations
----------------------------------
see: git.eclipse.org/c/tmf/org.eclipse.xtext.git/plain/plugins/org.eclipse.xtext.xbase/src/org/eclipse/xtext/xbase/annotations/XbaseWithAnnotations.xtext

XAnnotation XAnnotationImpl
example:

XAnnotationElementValueBinaryOperation XAnnotationElementValueBinaryOperationImpl
example:

XAnnotationValueArray XAnnotationValueArrayImpl
example:

from org.eclipse.xtext.?
----------------------------------
see: github.com/eclipse/?

RichString RichStringImpl
example:

RichStringForLoop RichStringForLoopImpl
example:

RichStringIf RichStringIfImpl
example:

RichStringLiteral RichStringLiteralImpl
example:

Generator
---------
Now that we have used the grammar to create a model we now need to generate (compile) code from the model. The generator file starts like this:

class DomainmodelGenerator implements IGenerator {
@Inject extension IQualifiedNameProvider
@Inject extension TypeReferenceSerializer
Previous Topic:Compilation test for multiple sources
Next Topic:formatter doesn't remove empty lines
Goto Forum:
  


Current Time: Mon Jul 07 21:05:48 EDT 2025

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

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

Back to the top