org.openxma.dsl.dom.DomDsl.xtext Maven / Gradle / Ivy
grammar org.openxma.dsl.dom.DomDsl with org.openxma.dsl.core.CoreDsl
hidden(WS, ML_COMMENT, SL_COMMENT,REGION_START,REGION_END)
import 'http://www.openxma.org/dsl/core/CoreDsl' as core
generate dom 'http://www.openxma.org/dsl/dom/DomDsl'
Model returns core::Model:
{core::Model}
('namespace' name=QualifiedName)?
(imports+=Import)*
(elements+=ModelElement)*;
ModelElement returns core::ModelElement :
ApplicationSession |
Service |
ComplexType |
Dao |
Mapper;
Type returns core::Type:
ComplexType;
ComplexType:
Entity |
DataView |
ValueObject;
Service:
'service' name=ID ('uses' dependencies+=[Dependant|QualifiedName] (',' dependencies+=[Dependant|QualifiedName])* )? '{'
(operations+=Operation | delegateOperations+=DelegateOperation)*
'}';
Dependant:
Service |
Dao |
Entity ;
Property:
'property' type=[core::SimpleType|QualifiedName] name=ID ('=' defaultValue=STRING)?;
Operation :
'operation' (type=[core::Type|QualifiedName] (many?='[]')?)? name=ID '(' (parameters+=Parameter ("," parameters+=Parameter)*)? ')' ('=' expression=STRING)?;
Parameter :
type=[core::Type|QualifiedName](many?='[]')? name=ID;
DelegateOperation : {DelegateOperation}
(view=[DataView] (many?='[]')? )? repository=[Dao]'.'(operation=[DaoOperation]|(crudOperationType=CrudOperationType ('('viewParameter=[DataView|QualifiedName]')')?)) ('as' name=ID)?
('filter' '=' filter=Expression)?
;
DaoOperation:
QueryOperation |
Operation;
ValueObject:
'valueobject' name=ID '{'
attributes+=Attribute*
'}';
DataView:
'dataview' name=ID ('extends' superType=[DataView|QualifiedName])? '{'
(attributes+=Attribute | featureReferences+=FeatureReference)*
'}';
FeatureReference:
source=[Entity] ('.'(attribute=[Attribute]('<'view=[DataView|QualifiedName]'>')? ('as' name=ID)?|all?='all')|all?='.*') (properties+=AttributeProperty)*
;
Mapper:
'mapper' name=ID 'maps' left=[ComplexType] (biDirectional?='<->'|toLeft?='<-'|toRight?='->') right=[ComplexType] '{'
(propertyMappings+=PropertyMapping)*
'}'
;
PropertyMapping:
left=[Attribute] (biDirectional?='<->'|toLeft?='<-'|toRight?='->') right=[Attribute]
;
Entity:
'entity' name=ID ('extends' superType=[Entity|QualifiedName])? '{'
(attributes+=Attribute | attributeGroups+=AttributeGroup)*
(conditionsBlock=ConditionsBlock)?
'}';
Attribute: {Attribute}
(identifier?='id'|version?='version'|composition?='composition')?
type=DataTypeAndTypeParameter (many?='[]')?
name=ID ('=' (incrementerReference=IncrementerReference|defaultValue=STRING))?
('oppositeof' opposite=[Attribute])?
(attributProperties+=AttributeProperty)*
('orderby' sortOrder = [AttributeGroup])?
;
AttributeFlag:
ExpressionFlag |
DerivedFlag |
TransientFlag;
ExpressionFlag:
RequiredFlag |
ReadOnlyFlag |
AvailableFlag
;
RequiredFlag:
'required' '=' expression=EqualityExpr;
ReadOnlyFlag:
'readonly' '=' expression=EqualityExpr;
AvailableFlag:
'available' '=' expression=EqualityExpr;
DerivedFlag:
'derived' '=' expression=BoolLiteral;
TransientFlag:
'transient' '=' expression=BoolLiteral;
AttributeProperty:
AttributeFlag |
AttributeValidationProperty |
AttributeTextProperty;
AttributeValidationProperty:
('constraints' '=' constraints+=Constraint ("," constraints+=Constraint)*)|
('format' '=' format=ValidatorReference);
AttributeTextProperty:
('title' '=' labelText=STRING)|
('description' '=' tooltipText=STRING)|
('unit' '=' (unitText=STRING | unitAttribute=[Attribute]))|
('hstore' '=' hstoreColumn=STRING);
AttributeGroup:
(key?='key'|unique?='unique'|filter?='filter'|sortorder?='sortorder') name=ID '(' attributes+=AttributeSortOrder (',' (attributes+=AttributeSortOrder))* ')';
AttributeSortOrder:
attribute=[Attribute] (asc?='asc'|desc?='desc')?
;
DaoFeature:
Column | ManyToOne | OneToOne | ManyToMany| OneToMany;
Dao:
'repository' name=ID 'for' entity=[Entity|QualifiedName] '{'
('table' '=' tableName=STRING)?
('discriminator' '=' discriminator=STRING)?
('qualifier' '=' qualifier=STRING)?
(operations+=Operation |
queryOperation+=QueryOperation)*
(dataBaseConstraints += DataBaseConstraint |
columns += Column |
manyToOneAssociations += ManyToOne |
oneToOneAssociations += OneToOne |
oneToManyAssociations += OneToMany |
manyToManyAssociations+= ManyToMany)*
'}';
QueryOperation:
'operation' (type=[core::Type|QualifiedName] (many?='[]')?)? name=ID '(' (queryParameters+=QueryParameter ("," queryParameters+=QueryParameter)*)? ')' ':' statement=QlStatement
;
QueryParameter:
Parameter |
attribute=[Attribute]
;
Column:
'column' attribute=[Attribute] ('<->' columnName=STRING)?
('usertype' '=' userType=DataTypeAndTypeParameter)?
('sqltype' '=' columnType=[core::Type|QualifiedName])?
('{' (columns+=Column)+ '}')?
;
ManyToOne:
'many-to-one' attribute=[Attribute] ('<->' columnName=STRING)?
('usertype' '=' userType=[core::Type|QualifiedName])?
('sqltype' '=' sqlType=[core::SqlType])?
('{' (columns+=Column)+ '}')?
;
OneToOne:
'one-to-one' attribute=[Attribute]
;
OneToMany:
'one-to-many' attribute=[Attribute] ('<->' columnName=STRING)?
('{' (columns+=Column)+ '}')?
;
ManyToMany:
'many-to-many' attribute=[Attribute] '<->' tableName=STRING ("." columnName=STRING)?
;
/**
* DataBaseConstraint used for efficient and consistent finder and ddl generation
* Generated artefacts: Service,ServiceImpl,Dao,DaoImpl,Hbm,Ddl
*/
DataBaseConstraint:
type=DataBaseConstraintType name=ID '(' (attributes+=[Attribute]) (',' (attributes+=[Attribute]))* ')';
enum CrudOperationType:
CREATE='create'|READ='read'|UPDATE='update'|DELETE='delete'|ALL='crud';
enum DataBaseConstraintType:
INDEX='index'| UNIQUE='unique' | NATURAL='natural'| PRIMARY='primary';
ReferenceableByXmadslVariable returns core::ReferenceableByXmadslVariable:
Property|StatusFlag|Attribute|IElementWithNoName;
ApplicationSession:
'context' name=ID '{'
(properties+=Property)*
(functions+=SessionFunction )*
(conditionsBlock=ConditionsBlock)?
'}'
;
SessionFunction returns core::Function :
'function' resultType=[core::SimpleType|QualifiedName] name=ID '(' parameterType=[core::SimpleType|QualifiedName] parameterName=ID ')'
;
QlStatement:
InsertStatement |
SelectStatement |
UpdateStatement |
DeleteStatement |
CallableStatement;
CallableStatement:
'call' (functionCall?='function')? name=QualifiedName '(' (inParameter+=CallInputParameter (',' inParameter+=CallInputParameter)*)? ')'
('return' outParameter+=CallOutputParameter (',' outParameter+=CallOutputParameter)*)?
;
CallInputParameter: {CallInputParameter}
parameter=[QueryParameter] ('.'attribute=[Attribute])? ('as' name=ID)?
;
CallOutputParameter: {CallOutputParameter}
(name=ID 'as'?)? attribute=[Attribute]? ('.' nestedAttribute=[Attribute])?
;
InsertStatement:
'insert' 'into' entity=[Entity|QualifiedName] '(' expression+=PrimaryExpression ( ',' expression+=PrimaryExpression )* ')' selectStatement=SelectStatement
;
DeleteStatement:
'delete' ('from')? entity=[Entity|QualifiedName] ('as')? name=ID
('where' where=Expression)?
;
UpdateStatement:
'update' (versioned?='versioned')? ('from')? entity=[Entity|QualifiedName] ('as')? name=ID
'set' assignment+=PropertyAssignment (',' assignment+=PropertyAssignment)*
('where' where=Expression)?
;
PropertyAssignment:
property=PropertyValue '=' expression=ConcatenationExpression
;
SelectStatement:
('select' (SelectProperties | SelectClass | SelectObject) )?
('from' from+=FromRange (join+=Join |',' from+=FromRange)*)?
('where' where=Expression)?
('group' 'by' groupBy+=Expression (',' groupBy+=Expression)* ('having' having=Expression)?)?
('order' 'by' orderBy+=SortOrderElement (',' orderBy+=SortOrderElement)*)?;
SortOrderElement:
expression=Expression (sortOrder=AscendingOrDescending)?;
SelectProperties:
(distinct?='distinct')? properties+=AliasedExpression (',' properties+=AliasedExpression)*;
SelectClass:
'new' class=QualifiedName '(' arguments+=AliasedExpression (',' arguments+=AliasedExpression)* ')';
SelectObject:
'object' '(' name=ID ')';
FromRange:
FromClass |
InClass |
InCollection |
InCollectionElements;
FromClass:
entity=[Entity|QualifiedName] ('as')? name=ID (popertyFetch?=PropertyFetch)?;
InClass:
name=ID 'in' 'class' class=QualifiedName;
InCollection:
'in' '(' path=QualifiedName ')' alias=ID;
InCollectionElements:
name=ID 'in' 'elements' '(' reference=QualifiedName ')';
Join:
(type=JoinType)? 'join' (fetch?='fetch')? entity=[JoinEntity] '.' reference=[Attribute] ('as')? name=ID (propertyFetch?=PropertyFetch)? ('with' expression=Expression)?;
JoinEntity:
FromClass |
Join;
AliasedExpression returns Expression:
Expression ({AliasedExpression.expression=current} 'as' name=ID)?;
Expression returns Expression:
LogicalOrExpression;
LogicalOrExpression returns Expression:
LogicalAndExpression ({BinaryExpression.left=current} operator='or' right=LogicalAndExpression)*;
LogicalAndExpression returns Expression:
PrefixExpression ({BinaryExpression.left=current} operator='and' right=PrefixExpression)*;
PrefixExpression returns Expression:
{NotExpression} 'not' expression=PrefixExpression |
EqualityExpression;
EqualityExpression returns Expression:
RelationalExpression
({BinaryExpression.left=current} operator=('=' | 'is' | IsNot | '!=' | '<>') right=RelationalExpression)*;
RelationalExpression returns Expression:
ConcatenationExpression
(({BinaryExpression.left=current} operator=('<' | '>' | '<=' | '>=') right=AdditiveExpression)* |
({InExpression.expression=current} (not?='not')? operator='in' in=(CollectionFunction | ParenthesizedExpression | SubQuery)) |
({BetweenExpression.expression=current} (not?='not')? operator='between' left=ConcatenationExpression 'and' right=ConcatenationExpression) |
({LikeExpression.expression=current} (not?='not')? operator='like' like=ConcatenationExpression ('escape' escape=ConcatenationExpression)?) |
({MemberOfExpression.expression=current} (not?='not')? operator='member' ('of')? memberOf=QualifiedName));
ConcatenationExpression returns Expression:
AdditiveExpression ({BinaryExpression.left=current} operator='||' right=AdditiveExpression)*;
AdditiveExpression returns Expression:
MultiplyExpression ({BinaryExpression.left=current} operator=('+' | '-') right=MultiplyExpression)*;
MultiplyExpression returns Expression:
UnaryExpression ({BinaryExpression.left=current} operator=('*' | '/' | '%') right=UnaryExpression)*;
UnaryExpression returns Expression:
{UnaryExpression} operator=('-' | '+') expression=UnaryExpression |
PrimaryExpression |
CaseExpression |
QuantifiedExpression;
PrimaryExpression returns Expression:
PropertyValue |
TrimFunction |
CastFunction |
AggregateFunction |
CollectionFunction |
FunctionCall |
ParenthesizedExpression |
SubQuery |
LiteralValue |
QueryParameterValue;
PropertyValue:
name=ID ('.' (segments+=ID)? ('['index+=Expression ']')? )* (classProperty?='class')?;
FunctionCall:
function=ID '(' arguments+=Expression ( ',' arguments+=Expression)* ')'
;
TrimFunction:
function='trim' '(' (mode=('trailing' | 'leading' | 'both'))? (character=StringLiteralValue 'from')? from=Expression ')';
CastFunction:
function='cast' '(' from=Expression 'as' name=ID ')' |
function='extract' '(' name=ID 'from' from=Expression ')';
AggregateFunction:
function=('sum' | 'avg' | 'max' | 'min') '(' aggregateExpression=AdditiveExpression ')' |
function='count' '(' (all?='*' | ((distinct?='distinct' | all?='all')? (from=QualifiedName | collection=CollectionFunction))) ')';
QueryParameterReference:
Parameter |
Attribute |
IElementWithNoName;
QueryParameterValue:
':' parameter=[QueryParameterReference]('.'attribute=[Attribute])?;
QuantifiedExpression:
quantifier=('some' | 'exists' | 'all' | 'any') (expression=(CollectionFunction|SubQuery) | name=ID);
CaseExpression:
'case' (whenClause+=WhenClause)+ ('else' elseExpression=UnaryExpression)? 'end' |
'case' expression=UnaryExpression (altWhenClause+=AltWhenClause)+ ('else' elseExpression=UnaryExpression)? 'end';
WhenClause:
('when' whenExpression=Expression 'then' thenExpression=UnaryExpression);
AltWhenClause:
('when' whenExpression=UnaryExpression 'then' thenExpression=UnaryExpression);
CollectionFunction:
function=('elements' | 'indices') '(' property=PropertyValue ')';
SubQuery:
'(' queries+=SelectStatement ('union' queries+=SelectStatement)* ')';
ParenthesizedExpression:
'(' expressions+=Expression (',' expressions+=Expression)* ')';
LiteralValue:
BooleanLiteralValue |
RealLiteralValue |
IntegerLiteralValue |
NullLiteralValue |
EmptyLiteralValue |
StringLiteralValue;
StringLiteralValue:
{StringLiteralValue}
value=STRING;
IntegerLiteralValue:
{IntegerLiteralValue}
value=IntValue;
RealLiteralValue:
{RealLiteralValue}
value=RealValue;
BooleanLiteralValue:
{BooleanLiteralValue} 'false'|isTrue?='true';
NullLiteralValue:
{NullLiteralValue} 'null';
EmptyLiteralValue:
{EmptyLiteralValue} 'empty';
RealValue:
REAL;
IntValue:
INT | HEX;
IsNot:
'is' 'not';
PropertyFetch:
'fetch' 'all' 'properties';
AscendingOrDescending:
('asc' | 'desc');
JoinType:
(('left' | 'right') 'outer'?) | 'full' | 'inner';
REAL hidden():
INT? '.' (EXP_INT | INT);
// Dummy to avoid name be pulled up
IElementWithNoName:
noName=ID;
PresentableFeature:
(FeatureReference|Attribute) (name=ID)?
;
terminal EXP_INT:
INT ('e' | 'E') ('-' | '+') INT;
terminal HEX:
'0' ('x' | 'X') (('0'..'9') | ('a'..'f') | ('A'..'F'))+;
terminal REGION_START : '#region' !('\n'|'\r')* ('\r'? '\n')? ;
terminal REGION_END : '#endregion' ;