grammar for Xtext 1.0's DomainModel example, enhanced with "path expressions"
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* 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