| /** |
| * |
| * Copyright (c) 2011, 2016 - Loetz GmbH&Co.KG (69115 Heidelberg, Germany) |
| * |
| * All rights reserved. This program and the accompanying materials |
| * are made available under the terms of the Eclipse Public License v1.0 |
| * which accompanies this distribution, and is available at |
| * http://www.eclipse.org/legal/epl-v10.html |
| * |
| * Contributors: |
| * Christophe Loetz (Loetz GmbH&Co.KG) - initial implementation |
| * |
| */ |
| grammar org.eclipse.osbp.xtext.entitymock.EntityMockDSL with org.eclipse.osbp.xtext.oxtype.OXtype |
| |
| import "http://osbp.eclipse.org/xtext/entitymock/EntityMockDSL" |
| |
| import "http://osbp.eclipse.org/dsl/common/types/v1" as types |
| import "http://osbp.eclipse.org/dsl/entity/v1" as entity |
| import "http://osbp.eclipse.org/xtext/datainterchange/DataDSL" as datainterchange |
| import "http://www.eclipse.org/emf/2002/Ecore" as ecore |
| |
| |
| EntityMockModel returns EntityMockModel: |
| importSection=XImportSection? |
| packages+=EntityMockPackage*; |
| |
| EntityMockPackage: |
| {EntityMockPackage} 'package' name=QualifiedName |
| ('{' |
| (mocks+=EntityMock*) |
| '}')?; |
| |
| EntityMock: |
| {EntityMock} 'mock' name=ID (description?='describedBy' descriptionValue=STRING)? |
| ('{' |
| (('priority' runPriority=INT)? & |
| (datainterchanges=RunningDataInterchanges)? & |
| (resources=EntityMockResources)? & |
| (objects=EntityMockObjects)? & |
| (entities=EntityMockEntities)) |
| '}')?; |
| |
| RunningDataInterchanges returns RunningDataInterchanges: |
| {RunningDataInterchanges} 'datainterchanges' '{' |
| (datainterchanges+=RunningDataInterchange)* |
| '}'; |
| |
| RunningDataInterchange returns RunningDataInterchange: |
| {RunningDataInterchange} 'datainterchange' datainterchangeRef=[datainterchange::DataInterchange] 'file' fileURL=STRING; |
| |
| EntityMockResources returns EntityMockResources: |
| {EntityMockResources} 'resources' '{' |
| (resources+=EntityMockResource)* |
| '}'; |
| |
| EntityMockResource returns EntityMockResource: |
| 'resource' name=ID '{' |
| ('attributes' '(' (attributes+=EntityMockResourceAttribute ','?)* ')')? |
| 'items' '{' (datarows+=EntityMockResourceDataRow)* '}' |
| '}'; |
| |
| EntityMockResourceAttribute: |
| {EntityMockResourceAttribute} name=ID; |
| |
| EntityMockResourceDataRow: |
| {EntityMockResourceDataRow} name=ID ('(' (values+=STRING ','? )* ')')?; |
| |
| EntityMockObjects returns EntityMockObjects: |
| {EntityMockObjects} 'objects' '{' |
| (objects+=EntityMockObject)* |
| '}'; |
| |
| EntityMockObject returns EntityMockObject: |
| 'object' name=ID '{' |
| (enumerations+=EntityMockObjectEnum)* |
| (attributes+=IEntityMockObjectAttribute)* |
| (calculations+=EntityMockObjectFunction)* |
| '}'; |
| |
| EntityMockObjectEnum returns EntityMockObjectEnum: |
| 'var' name=ID 'byEnum' usingResource=[types::LEnum]; |
| |
| IEntityMockObjectUsable: |
| EntityMockObjectFunction | EntityMockObjectEnum | EntityMockObjectPlainValue | EntityMockObjectArrayValue | EntityMockObjectEmbed | EntityMockObjectFill; |
| |
| IEntityMockObjectAttribute: |
| EntityMockObjectResourceValue | EntityMockObjectPlainValue | EntityMockObjectArrayValue | EntityMockObjectEmbed | EntityMockObjectFill; |
| |
| EntityMockObjectPlainValue: |
| 'var' name=ID '(' (values+=STRING ','? )* ')'; |
| |
| EntityMockObjectResourceValue: |
| 'var' name=ID 'with' resourceEnum=[EntityMockObjectEnum] ('.' resourceAttribute=[EntityMockResourceAttribute])?; |
| |
| EntityMockObjectArrayValue: |
| 'var' name=ID 'switchOn' enumeration=[EntityMockObjectEnum] '{' (items+=EntityMockObjectItemValue)* '}'; |
| |
| EntityMockObjectItemValue: |
| 'when' datarow=[types::LEnumLiteral] '(' (values+=STRING ','? )* ')'; |
| |
| EntityMockObjectEmbed returns EntityMockObjectEmbed: |
| {EntityMockObjectEmbed} 'embed' name=ID 'definedAs' object=[EntityMockObject]; |
| |
| EntityMockObjectFunction: |
| 'var' name=ID 'calculateAs' oftype=JvmParameterizedTypeReference |
| 'basedOn' '(' (params+=EntityMockObjectFunctionParameter (',' params+=EntityMockObjectFunctionParameter)* )? ')' |
| body=XBlockExpression; |
| |
| EntityMockObjectFunctionParameter: |
| parameterType=JvmTypeReference name=[IEntityMockObjectUsable]; |
| |
| EntityMockObjectFill: |
| 'var' name=ID 'randomize' fillerType=PropertyFillerType; |
| |
| |
| PropertyFillerType returns PropertyFillerType: |
| PropertyFillerDateFuture | PropertyFillerDatePast |
| | PropertyFillerDateRange |
| | PropertyFillerBoolean |
| | PropertyFillerSignedDoubleRange | PropertyFillerSignedDoubleRandom |
| | PropertyFillerSignedIntegerRange | PropertyFillerSignedIntegerRandom |
| | PropertyFillerTextRandom |
| | PropertyFillerTextParagraphs | PropertyFillerTextSentences | PropertyFillerTextWords |
| | PropertyFillerUnsignedDoubleRange | PropertyFillerUnsignedDoubleRandom |
| | PropertyFillerUnsignedIntegerRange | PropertyFillerUnsignedIntegerRandom |
| ; |
| |
| PropertyFillerDateFuture returns PropertyFillerDateFuture: |
| 'future' dateFutureYears=INT 'years'; |
| |
| PropertyFillerDatePast returns PropertyFillerDatePast: |
| 'past' datePastYears=INT 'years'; |
| |
| PropertyFillerBoolean returns PropertyFillerBoolean: |
| {PropertyFillerBoolean} 'boolean'; |
| |
| PropertyFillerDateRange returns PropertyFillerDateRange: |
| 'dateRange' 'from' dateBeginYears=SINT 'until' dateEndYears=SINT 'years'; |
| |
| PropertyFillerSignedDoubleRange returns PropertyFillerSignedDoubleRange: |
| 'numberRange' 'from' |
| ((beginRange=SignedNumber | beginRangeRef=[entity::LEntityAttribute])? 'until' (endRange=SignedNumber|endRangeRef=[entity::LEntityAttribute]))? |
| 'with' decimals=INT 'decimals' |
| ('roundTo' rounded=UnsignedNumber)?; |
| |
| PropertyFillerSignedDoubleRandom returns PropertyFillerSignedDoubleRandom: |
| 'numberPick' '(' (items+=SignedNumber)+ ')'; |
| |
| PropertyFillerSignedIntegerRange returns PropertyFillerSignedIntegerRange: |
| {PropertyFillerSignedIntegerRange} 'integerRange' 'from' |
| ((beginRange=SINT | beginRangeRef=[entity::LEntityAttribute])? 'until' (endRange=SINT|endRangeRef=[entity::LEntityAttribute]))? |
| ('roundTo' rounded=INT)?; |
| |
| PropertyFillerSignedIntegerRandom returns PropertyFillerSignedIntegerRandom: |
| 'integerPick' '(' (items+=SINT)+ ')'; |
| |
| PropertyFillerTextRandom returns PropertyFillerTextRandom: |
| 'textPick' '(' (items+=STRING)+ ')'; |
| |
| PropertyFillerTextParagraphs returns PropertyFillerTextParagraphs: |
| {PropertyFillerTextParagraphs} 'paragraphs' (count=INT)?; |
| |
| PropertyFillerTextSentences returns PropertyFillerTextSentences: |
| {PropertyFillerTextSentences} 'sentences' (count=INT)?; |
| |
| PropertyFillerTextWords returns PropertyFillerTextWords: |
| {PropertyFillerTextWords} 'words' (count=INT)?; |
| |
| PropertyFillerUnsignedDoubleRange returns PropertyFillerUnsignedDoubleRange: |
| 'unsignedNumberRange' 'from' |
| ((beginRange=UnsignedNumber | beginRangeRef=[entity::LEntityAttribute])? 'until' (endRange=UnsignedNumber|endRangeRef=[entity::LEntityAttribute]))? |
| 'with' decimals=INT 'decimals' |
| ('roundTo' rounded=UnsignedNumber)?; |
| |
| PropertyFillerUnsignedDoubleRandom returns PropertyFillerUnsignedDoubleRandom: |
| 'unsignedNumberPick' '(' (items+=UnsignedNumber)+ ')'; |
| |
| PropertyFillerUnsignedIntegerRange returns PropertyFillerUnsignedIntegerRange: |
| {PropertyFillerUnsignedIntegerRange} 'unsignedIntegerRange' 'from' |
| ((beginRange=INT | beginRangeRef=[entity::LEntityAttribute])? 'until' (endRange=INT|endRangeRef=[entity::LEntityAttribute]))? |
| ('roundTo' rounded=INT)?; |
| |
| PropertyFillerUnsignedIntegerRandom returns PropertyFillerUnsignedIntegerRandom: |
| 'unsignedIntegerPick' '(' (items+=INT)+ ')'; |
| |
| |
| |
| EntityMockEntities returns EntityMockEntities: |
| {EntityMockEntities} 'entities' '{' |
| (entities+=EntityMockEntity)* |
| '}'; |
| |
| EntityMockEntity returns EntityMockEntity: |
| 'mocking' name=ID 'entity' entityRef=[entity::LEntity] |
| (('rows' minRows=INT 'to' maxRows=INT '{' |
| (templates+=EntityMockTemplate)* |
| (attributes+=IEntityMockAttribute)* |
| (calculations+=EntityMockEntityFunction)* |
| '}') |
| | |
| ('resource' byResource=[EntityMockResource] '{' |
| ((byResourceAttributes+=EntityMockByResourceAttribute)* & |
| (createBlobMapping?='createBlobMapping')?) |
| '}') |
| | |
| ('iterate' iterator=[entity::LEntityAttribute] |
| 'with' iterate=IIterate '{' |
| (templates+=EntityMockTemplate)* |
| (attributes+=IEntityMockAttribute)* |
| (calculations+=EntityMockEntityFunction)* |
| '}') |
| ) |
| ; |
| |
| IIterate: |
| IntegerIterate | DateIterate; |
| |
| IntegerIterate: |
| 'integerFrom' from=SINT 'until' until=SINT 'step' step=INT; |
| |
| DateIterate: |
| 'dateFrom' from=Date 'until' until=Date 'every' stepCount=INT stepType=EDateStepType; |
| |
| Date: |
| (yesterday?='yesterday' ) | (today?='today' ) | (tomorrow?='tomorrow') | (year=INT '-' month=INT '-' day=INT); |
| |
| enum EDateStepType: |
| DAYS='days' | WEEKS='weeks' | MONTHS='months' | YEARS='years'; |
| |
| EntityMockByResourceAttribute: |
| {EntityMockByResourceAttribute} 'var' attributeRef=[entity::LEntityAttribute] 'as' resourceAttribute=[EntityMockResourceAttribute]; |
| |
| EntityMockTemplate: |
| 'template' name=ID 'byObject' object=[EntityMockObject]; |
| |
| IEntityMockEntityUsable: |
| IEntityMockAttribute | EntityMockEntityFunction; |
| |
| IEntityMockAttribute: |
| EntityMockAttributeByObject | EntityMockAttributeFiller | EntityMockAttributeByReference; |
| |
| EntityMockEntityFunction: |
| 'var' attributeRef=[entity::LEntityAttribute] |
| 'calculateOn' '(' (params+=EntityMockEntityFunctionParameter (',' params+=EntityMockEntityFunctionParameter)* )? ')' |
| body=XBlockExpression; |
| |
| EntityMockEntityFunctionParameter: |
| attributeRef=[entity::LEntityAttribute]|nestedAttribute=EntityMockEntityNestedAttribute; |
| |
| EntityMockEntityNestedAttribute: |
| reference=[entity::LEntityReference]'.'attribute=[entity::LEntityAttribute]; |
| |
| EntityMockReferencedObjectAttribute: |
| {EntityMockReferencedObjectAttribute} template=[EntityMockTemplate] ('.'? embedded+=[EntityMockObjectEmbed])* '.' attribute=[IEntityMockObjectUsable]; |
| |
| EntityMockAttributeByObject: |
| 'var' attributeRef=[entity::LEntityAttribute] |
| ('as' reference=EntityMockReferencedObjectAttribute) |
| | |
| ('using' resourceEnum=[EntityMockObjectEnum] '.' resourceAttribute=[EntityMockResourceAttribute] ) |
| ; |
| |
| EntityMockAttributeFiller: |
| 'var' attributeRef=[entity::LEntityAttribute] 'randomize' fillerType=PropertyFillerType; |
| |
| EntityMockAttributeByReference: |
| 'ref' attributeRef=[entity::LEntityReference] 'to' ('existingEntities' | mockedEntity=[EntityMockEntity]) ('optionalFor' optionalFor=INT 'percent')?; |
| |
| SignedNumber returns ecore::EDouble: |
| ('-')? UnsignedNumber; |
| |
| UnsignedNumber returns ecore::EDouble: |
| INT ('.' (INT))?; |
| |
| SINT returns ecore::EInt: |
| ('-')? INT; |