Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
grammar for Xtext 1.0's DomainModel example, enhanced with "path expressions"
/*
* Grammar taken from the Xtext 1.0.x Domainmodel example
* and enhanced with path expressions: see .
*/
grammar nl.dslmeinte.xtext.examples.domainmodel.DomainModel with org.eclipse.xtext.common.Terminals
generate domainModel "http://www.dslmeinte.nl/xtext/examples/DomainModel"
DomainModel:
elements+=AbstractElement*;
AbstractElement:
PackageDeclaration | Type | Import | PathDefinition;
Import:
'import' importedNamespace=QualifiedNameWithWildCard;
PackageDeclaration:
'package' name=QualifiedName '{'
elements+=AbstractElement*
'}';
Type:
Entity | DataType;
DataType:
'datatype' name=ID;
Entity:
'entity' name=ID ('extends' superType=[Entity|QualifiedName])? '{'
features+=Feature*
'}';
Feature:
StructuralFeature | Operation;
StructuralFeature:
Attribute | Reference;
Attribute:
name=ID ':' type=TypeRef;
// validation: type must reference a DataType
Reference:
'ref' name=ID ':' type=TypeRef ('opposite' opposite=[Reference])?;
// validation: type must reference an Entity
Operation:
visibility=Visibility? 'op' name=ID '(' (params+=Parameter (',' params+=Parameter)*)? ')' ':' type=TypeRef;
Parameter:
name=ID type=TypeRef;
TypedElement: // (convenience super type)
Feature | Parameter;
TypeRef:
referenced=[Type|QualifiedName] multi?='*'?;
enum Visibility:
public | private | protected;
QualifiedNameWithWildCard:
QualifiedName '.*'?;
QualifiedName:
ID ('.' ID)*;
// addition for paths:
PathDefinition:
'path' name=ID ':' head=PathHead;
PathHead:
entity=[Entity] tail=PathTail;
PathTail:
'/' feature=[StructuralFeature] (tail=PathTail)?;
PathElement: // convenience super type
PathHead | PathTail
;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.