Created
June 27, 2011 13:15
-
-
Save schakko/1048834 to your computer and use it in GitHub Desktop.
Simple DSL with Xtext
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
domaene de.ckl.blog | |
entity Gruppe { | |
attribute id: int not-null primary-key | |
attribute name: string | |
reference has-many: BenutzerInGruppe with-alias:"BenutzerInGruppen" | |
} | |
entity BenutzerInGruppe { | |
attribute id: int not-null primary-key | |
attribute gruppe_id: int not-null foreign-key:Gruppe.id | |
attribute benutzer_id: int not-null foreign-key:Benutzer.id | |
reference belongs-to-one: Benutzer mapped-by:benutzer_id | |
reference belongs-to-one: Gruppe mapped-by:gruppe_id | |
} | |
entity Freundschaft { | |
attribute id: int not-null primary-key | |
attribute benutzer_id_links: int not-null foreign-key:Benutzer.id | |
attribute benutzer_id_rechts: int not-null foreign-key:Benutzer.id | |
reference has-one: Benutzer with-alias:"BenutzerLinks" mapped-by:benutzer_id_links | |
reference has-one: Benutzer with-alias:"BenutzerRechts" mapped-by:benutzer_id_rechts | |
} | |
entity Benutzer { | |
attribute id: int not-null primary-key | |
attribute benutzername: string max-length:50 not-null | |
attribute vorname: string max-length:50 not-null | |
attribute nachname: string max-length:50 not-null | |
attribute direkter_vorgesetzter_id: int foreign-key:Benutzer.id | |
attribute aktiviert: bool default:false | |
attribute alter: int default:18 | |
reference has-one: Benutzer with-alias:"Vorgesetzter" mapped-by: direkter_vorgesetzter_id | |
reference has-many: Freundschaft with-alias:"Freundschaften" | |
reference has-many: Kommentar with-alias:"Kommentar" | |
reference belongs-to-many: BenutzerInGruppe | |
} | |
entity Blogeintrag { | |
attribute id: int not-null primary-key | |
attribute subject: string max-length:50 not-null | |
attribute body: string not-null | |
attribute benutzer_id: int not-null foreign-key:Benutzer.id | |
attribute status: enum:["PRIVAT" "OEFFENTLICH"] default:"PRIVAT" | |
reference belongs-to-one: Benutzer | |
reference has-many: Kommentar with-alias:"Kommentare" | |
} | |
entity Kommentar { | |
attribute id: int not-null primary-key | |
attribute gastname: string max-length:50 not-null | |
attribute body: string not-null | |
attribute benutzer_id: int foreign-key:Benutzer.id | |
attribute blogeintrag_id: int not-null foreign-key:Blogeintrag.id | |
reference belongs-to-one: Benutzer with-alias:"RegistrierterBenutzer" mapped-by:benutzer_id | |
reference belongs-to-one: Blogeintrag mapped-by:blogeintrag_id | |
} |
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 de.ckl.Xtext with org.eclipse.xtext.common.Terminals | |
generate entityTest "http://www.ckl.de/Xtext" | |
DomainModel: | |
'domaene' domaene=QualifiedName | |
(elements+=Entity)*; | |
QualifiedName: | |
ID ('.' ID)*; | |
Entity: | |
'entity' name=ID '{' | |
(entityElements+=Element)* | |
'}'; | |
Element: | |
element=(Attribute | Reference); | |
DataType: | |
dataType=(IntDataType | StringDataType | BooleanDataType | EnumDataType); | |
IntDataType: | |
intDataType='int' (dataDefault='default:' default=INT)? (dataMin='min:' min=INT)? (dataMax='max:' max=INT)? | |
; | |
StringDataType: | |
stringDataType='string' (dataDefault='default:' default=STRING)? (dataMaxLength='max-length:' maxLength=INT)? | |
(dataMinLength='min-length:' minLength=INT)?; | |
BooleanDataType: | |
booleanDataType='bool' (dataDefault='default:' default=('true' | 'false' | '0' | '1'))?; | |
EnumDataType: | |
enumDataType='enum:' '[' (enums+=STRING)* ']' (dataDefault='default:' default=STRING)?; | |
Attribute: | |
attribute='attribute' name=ID ':' dataType=DataType ((foreignPrimaryKeyDecision=ForeignPrimaryKeyDecision)? & | |
(notNullAttribute='not-null')? & (uniqueAttribute='unique')?); | |
Reference: | |
reference='reference' referenceType=ReferenceType ':' refEntity=[Entity] ((withAlias=WithAliasType)? & | |
(mappedBy=MappedByType)?); | |
ReferenceType: | |
referenceType=('has-one' | 'has-many' | 'belongs-to-one' | 'belongs-to-many'); | |
WithAliasType: | |
withAliasType='with-alias:' alias=STRING; | |
MappedByType: | |
mappedByType='mapped-by:' (mappedBy=[Attribute]); | |
ForeignPrimaryKeyDecision: | |
foreignPrimaryKeyDecision=('primary-key') | ForeignKeyType; | |
ForeignKeyType: | |
foreignKeyType='foreign-key:' (foreignKeyEntity=[Entity] '.' foreignKeyAttribute=[Attribute]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment