| /** |
| * <copyright> |
| * |
| * Copyright (c) 2013 Willink Transformation Ltd., University of York and others. |
| * 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: |
| * Adolfo Sanchez-Barbudo Herrera (University of York) - initial API and implementation |
| * |
| * </copyright> |
| */ |
| grammar org.eclipse.qvto.examples.xtext.qvtoperational.QVTOperational with org.eclipse.qvto.examples.xtext.imperativeocl.ImperativeOCL |
| |
| // generate qvtoperationalcs "http://www.eclipse.org/qvt/pivot/1.0/QVTOperationalCS" |
| //import "http://www.eclipse.org/qvt/pivot/1.0/QVTOperationalCS" |
| import "platform:/resource/org.eclipse.qvto.examples.xtext.qvtoperational/model/QVTOperationalCS.ecore" |
| |
| import "http://www.eclipse.org/emf/2002/Ecore" as ecore |
| //import "http://www.eclipse.org/ocl/3.1.0/BaseCST" as base |
| //import "http://www.eclipse.org/ocl/3.1.0/EssentialOCLCST" as essentialocl |
| //import "http://www.eclipse.org/qvt/pivot/1.0/ImperativeOCLCS" as imperativeocl |
| |
| import "platform:/resource/org.eclipse.ocl.xtext.base/model/BaseCS.ecore" as base |
| import "platform:/resource/org.eclipse.ocl.xtext.essentialocl/model/EssentialOCLCS.ecore" as essentialocl |
| import "platform:/resource/org.eclipse.qvto.examples.xtext.imperativeocl/model/ImperativeOCLCS.ecore" as imperativeocl |
| |
| TopLevelCS : ^import+=ImportCS* |
| // unit+=UnitElementCS* FIXME |
| (ownedPackages+= UnitPacakgeCS)* |
| unit+=TransformationCS // FIXME temporal workaround |
| //(ownedType+=ModelTypeCS)* |
| ; |
| |
| enum ClassifierKind : DATATYPE='datatype' | PRIMITIVE='primitive' | EXCEPTION='exception' | CLASS='class'; |
| enum FeatureKey : COMPOSES='composes' | REFERRENCES='references' | READONLY='readonly' | DERIVED='derived' | STATIC='static'; |
| enum InitOp : EQUALS='=' | COLON_EQUALS=':=' | COLON_COLON_EQUALS='::='; |
| enum MetamodelKind : METAMODEL= 'metamodel' | PACKAGE='package'; |
| enum DirectionKindCS : in='in'| out='out' | inout='inout'; |
| //enum ParamDirection : IN='in' | INOUT='inout' | OUT='out'; |
| |
| Qualifier returns ecore::EString : 'blackbox' & 'abstract' & 'static'; |
| |
| FeatureQualifier returns ecore::EString : 'composes' & 'references' & 'readonly' & 'derived' & 'static'; |
| |
| // ****** Imports ****** |
| ImportCS returns QVToImportCS : |
| ('import' unit=UnitCS ';') |
| | ('from' unit=UnitCS 'import' ((importedUnitElement+=Identifier (',' importedUnitElement+=Identifier)*) | all?='*') ';') |
| ; |
| |
| UnitCS : |
| segment+=Identifier ('.' segment+=Identifier)* |
| ; |
| |
| |
| // ****** definitions in a compilation unit ******* |
| UnitPacakgeCS returns base::PackageCS: |
| MetamodelCS |
| ; |
| |
| |
| UnitTypeCS returns base::TypeCS: |
| ModelTypeCS |
| ; |
| // ****** General rules ****** |
| //CompleteSignatureCS: SimpleSignatureCS (':' (param+=ParameterCS (',' param+=ParameterCS)*))?; |
| // |
| SimpleSignatureCS: {SimpleSignatureCS} |
| '(' (parameter+=ParameterDeclarationCS (',' parameter+=ParameterDeclarationCS)*)? ')' |
| ; |
| |
| |
| ParameterDeclarationCS : |
| (direction= DirectionKindCS)? |
| name=UnrestrictedName // FIXME Spec grammar says that you can have just a typeSpec |
| (':' ownedType=TypedMultiplicityRefCS)? |
| initPart=InitPartCS? |
| ; |
| |
| // TODO also remove the corresponding CS metamodel element |
| //OperationSimpleSignatureCS : {OperationSimpleSignatureCS} |
| // '(' (parameter+= OperationParameterDeclarationCS (',' parameter+= OperationParameterDeclarationCS)*)? ')' |
| //; |
| |
| OperationParameterDeclarationCS : |
| direction=DirectionKindCS? |
| name=UnrestrictedName // FIXME Spec grammar says that you can have just a typeSpec |
| (':' ownedType=TypeSpecCS)? |
| initPart=InitPartCS? |
| ; |
| |
| |
| |
| InitPartCS: |
| initOp=InitOp expression= ExpCS |
| ; |
| |
| TypeSpecCS : |
| ownedType= TypedRefCS ('@' extentLocation=UnrestrictedName)? |
| ; |
| |
| // General rules END |
| |
| |
| // ****** Syntax for defining explicitly metamodel contents ****** |
| |
| MetamodelCS returns MetamodelCS: // MetamodelKind provides extra semantic, we need to retain the kind |
| metamodelKind=MetamodelKind |
| name = UnrestrictedName |
| '{' (ownedClasses+=ClassCS | |
| ownedClasses+=EnumerationCS | // FIXME QVTo grammar distincts classifier from enumeration |
| ownedAnnotations+= TagCS)* |
| '}' |
| ';'? |
| ; |
| |
| ClassCS returns base::ClassCS: |
| (DataTypeCS | ExceptionCS | QVToClassCS) |
| ';'? |
| ; |
| |
| DataTypeCS returns base::DataTypeCS: |
| ('datatype' | {PrimitiveTypeCS} 'primitive') |
| name=UnrestrictedName |
| ; |
| |
| ExceptionCS returns base::StructuredClassCS: // FIXME so far, exception is another class |
| 'exception' |
| name = UnrestrictedName |
| ('extends' (ownedSuperTypes+=TypedRefCS (',' ownedSuperTypes+=TypedRefCS)*))? |
| ; |
| |
| QVToClassCS returns QVToClassCS: |
| intermediate ?= 'intermediate' ? |
| // qualifier += Qualifier* |
| 'class' |
| name=UnrestrictedName |
| ('extends' (ownedSuperTypes += TypedRefCS (',' ownedSuperTypes+=TypedRefCS)*))? |
| ('{' ((ownedProperties += ClassifierPropertyCS | ownedOperations+=ClassifierOperationCS | ownedAnnotations+= TagCS) ';' )+ |
| '}' )? |
| ; |
| |
| TypeRefCS returns base::TypeRefCS: |
| TypedRefCS // | WildcardTypeRefCS |
| // FIXME deviation from OCLInEcore. No templates parameter, yet |
| ; |
| |
| TypedRefCS returns base::TypedRefCS: |
| TypeLiteralCS | TypedTypeRefCS |
| ; |
| |
| TypedMultiplicityRefCS returns base::TypedRefCS: |
| TypedRefCS (ownedMultiplicity=MultiplicityCS)? |
| ; |
| |
| TypedTypeRefCS returns base::TypedTypeRefCS: |
| ownedPathName=PathNameCS // (ownedTemplateBinding=TemplateBindingCS)? |
| // FIXME deviation from OCLInEcore. No templates parameter, yet |
| ; |
| |
| |
| |
| ClassifierPropertyCS returns ClassifierPropertyCS: |
| stereotypes = StereotypeQualifierCS? |
| qualifiers+= FeatureQualifier* |
| name=UnrestrictedName ':' ownedType=TypedMultiplicityRefCS |
| (default=SINGLE_QUOTED_STRING) ? // FIXME QVTO syntax define a more complex InitPartCS |
| ('opposites' '~'? opposite=Identifier)? // FIXME |
| ; |
| |
| StereotypeQualifierCS returns StereotypeQualifierCS: |
| '<<' (stereotype+=Identifier (',' stereotype+=Identifier)*) '>>' |
| ; |
| |
| MultiplicityCS returns base::MultiplicityBoundsCS: '[' (lowerBound=LOWER '...')? upperBound=UPPER ']'; |
| |
| ClassifierOperationCS returns QVToOperationCS: |
| stereotypes = StereotypeQualifierCS? |
| qualifiers+= FeatureQualifier* |
| name=UnrestrictedName |
| '(' (ownedParameters+= OperationParameterDeclarationCS (',' ownedParameters+=OperationParameterDeclarationCS)*)? ')' |
| (':' ownedType=TypedMultiplicityRefCS)? |
| ; |
| |
| // FIXME Deviation from official grammar |
| EnumerationCS returns base::EnumerationCS: |
| 'enum' |
| name=Identifier |
| ( ('{' (ownedLiterals+=EnumerationLiteralCS (',' ownedLiterals+=EnumerationLiteralCS)*) '}' )) |
| ';'? |
| ; |
| |
| EnumerationLiteralCS returns base::EnumerationLiteralCS: |
| name=UnrestrictedName |
| ; |
| |
| TagCS returns TagCS: |
| 'tag' name=(UnrestrictedName|SINGLE_QUOTED_STRING)? |
| pathName=PathNameCS ('=' expression=ExpCS)? ';' |
| ; |
| |
| |
| // typedefs |
| // TypedefCS: 'typedef' name=Identifier '=' typespec=TypeExpCS ('[' condition=ExpCS ']')? ';'; |
| |
| // ****** Transformations, mappings, etc ****** |
| |
| TransformationCS: |
| TransformationDeclCS | TransformationDefCS |
| ; |
| |
| TransformationDeclCS returns TransformationCS: |
| TransformationHeaderCS ';' |
| ; |
| |
| TransformationDefCS returns TransformationCS: |
| TransformationHeaderCS '{' |
| // (ownedClasses+= ModuleTypeCS)* FIXME Transformation is not a package anymore |
| (ownedProperties+= ModulePropertyCS)* |
| (ownedOperations+= ModuleOperationCS)* |
| |
| '}' |
| ; |
| |
| TransformationHeaderCS returns TransformationCS: |
| 'transformation' name=UnrestrictedName |
| ; |
| |
| ModelTypeCS: |
| 'modeltype' name=UnrestrictedName complianceKindCS=StringLiteralExpCS 'uses' (packageRefs+= PackageRefCS) |
| ; |
| |
| PackageRefCS: |
| uriCS= StringLiteralExpCS |
| | pathNameCS=PathNameCS (uriCS=StringLiteralExpCS) |
| ; |
| |
| ModulePropertyCS returns base::StructuralFeatureCS: |
| ClassifierPropertyCS |
| ; |
| |
| ModuleOperationCS returns base::OperationCS: |
| MappingOperationCS |
| ; |
| |
| ModuleTypeCS returns base::ClassCS: |
| ModelTypeCS |
| ; |
| |
| MappingOperationCS: |
| MappingDeclarationCS | MappingDefinitionCS |
| ; |
| |
| MappingDeclarationCS returns MappingOperationCS: |
| MappingOperationHeaderCS ';' |
| ; |
| |
| MappingDefinitionCS returns MappingOperationCS: |
| MappingOperationHeaderCS '{' |
| |
| '}' |
| ; |
| |
| MappingOperationHeaderCS returns MappingOperationCS: |
| "mapping" name=UnrestrictedName |
| '(' (ownedParameters+= OperationParameterDeclarationCS (',' ownedParameters+= OperationParameterDeclarationCS)*)? ')' |
| // signature= OperationSimpleSignatureCS |
| ; |