blob: bb0eeef4591fe7634cbf05c54397e8bdec461068 [file] [log] [blame]
/*******************************************************************************
* Copyright (c) 2010,2011 E.D.Willink 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:
* E.D.Willink - initial API and implementation
* E.D.Willink (Obeo) - Bug 416287 - tuple-valued constraints
*******************************************************************************/
grammar org.eclipse.ocl.xtext.oclinecore.OCLinEcore with org.eclipse.ocl.xtext.essentialocl.EssentialOCL
import "http://www.eclipse.org/emf/2002/Ecore" as ecore
import "http://www.eclipse.org/ocl/2015/BaseCS" as base
import "http://www.eclipse.org/ocl/2015/EssentialOCLCS" as essentialocl
import "http://www.eclipse.org/ocl/2015/Pivot" as pivot
import "http://www.eclipse.org/ocl/2015/OCLinEcoreCS"
//generate oclinEcore2 "http://www.eclipse.org/ocl/examples/xtext/oclinecore/OCLinEcore"
TopLevelCS :
{TopLevelCS} ('module' UnrestrictedName)?
(ownedLibraries+=LibraryCS)*
(ownedImports+=ImportCS)*
(ownedPackages+=PackageCS)*
;
terminal UNQUOTED_STRING: // Never forward parsed; just provides a placeholder
'£$%^£$%^' // for reverse serialisation of embedded OCL
;
INTEGER returns ecore::EInt:
INT
;
SIGNED returns ecore::EInt:
'-'? INT
;
EnumerationLiteralName returns ecore::EString:
EssentialOCLUnrestrictedName
| 'abstract'
| 'attribute'
| 'body'
| 'callable'
| 'class'
| 'composes'
| 'datatype'
| 'definition'
| 'derivation'
| 'derived'
| 'enum'
| 'extends'
| 'id'
| 'import'
| 'initial'
| 'interface'
| 'key'
| 'library'
| 'module'
| 'operation'
| 'ordered'
| 'package'
| 'postcondition'
| 'precondition'
| 'primitive'
| 'property'
| 'readonly'
| 'reference'
| 'resolve'
| 'static'
| 'super'
| 'throws'
| 'transient'
| 'unique'
| 'unsettable'
| 'volatile'
;
InvariantConstraintCS returns OCLinEcoreConstraintCS:
(isCallable?='callable')? stereotype='invariant' (name=UnrestrictedName ('(' ownedMessageSpecification=SpecificationCS ')')?)?
((':' ownedSpecification=SpecificationCS? ';') | ';')
;
PostconditionConstraintCS returns OCLinEcoreConstraintCS:
stereotype='postcondition' (name=UnrestrictedName ('(' ownedMessageSpecification=SpecificationCS ')')?)? ':' ownedSpecification=SpecificationCS? ';'
;
PreconditionConstraintCS returns OCLinEcoreConstraintCS:
stereotype='precondition' (name=UnrestrictedName ('(' ownedMessageSpecification=SpecificationCS ')')?)? ':' ownedSpecification=SpecificationCS? ';'
;
AnnotationCS returns base::AnnotationCS:
{base::AnnotationCS} 'annotation' name=(UnrestrictedName|SINGLE_QUOTED_STRING)?
('(' ownedDetails+=DetailCS (',' ownedDetails+=DetailCS)* ')')?
(('{' (ownedAnnotations+=AnnotationElementCS
| ownedContents+=ModelElementCS
| ownedReferences+=ModelElementRefCS
)+'}')
|';'
)
;
AnnotationElementCS returns base::AnnotationElementCS:
AnnotationCS | DocumentationCS | SysMLCS
;
AttributeCS returns base::AttributeCS:
(isStatic?='static'? & isDefinition?='definition'?)
'attribute' name=UnrestrictedName
(':' ownedType=TypedMultiplicityRefCS)?
('=' default=SINGLE_QUOTED_STRING)?
('{'((isDerived?='derived' | '!derived') ','?)? &
((isId?='id' | '!id') ','?)? &
((isOrdered?='ordered' | '!ordered') ','?)? &
((isReadonly?='readonly' | '!readonly') ','?)? &
((isTransient?='transient' | '!transient') ','?)? &
((isNotUnique?='!unique' | 'unique') ','?)? &
((isUnsettable?='unsettable' | '!unsettable') ','?)? &
((isVolatile?='volatile' | '!volatile') ','?)?
'}')?
( ('{' (ownedAnnotations+=AnnotationElementCS
| ('derivation' UnrestrictedName? ':' ownedDefaultExpressions+=SpecificationCS? ';')
| ('initial' UnrestrictedName? ':' ownedDefaultExpressions+=SpecificationCS? ';') )* '}')
| ';'
)
;
ClassCS returns base::ClassCS:
StructuredClassCS | DataTypeCS | EnumerationCS
;
DataTypeCS returns base::DataTypeCS:
isPrimitive ?= 'primitive'? 'datatype' name=UnrestrictedName
(ownedSignature=TemplateSignatureCS)?
(':' instanceClassName=SINGLE_QUOTED_STRING)?
('{' (isSerializable?='serializable' | '!serializable')? '}')?
( ('{' (ownedAnnotations+=AnnotationElementCS
| ownedConstraints+=InvariantConstraintCS)* '}')
| ';'
)
;
DetailCS returns base::DetailCS:
name=(UnrestrictedName|SINGLE_QUOTED_STRING) '=' values+=(SINGLE_QUOTED_STRING|ML_SINGLE_QUOTED_STRING)*
;
DocumentationCS returns base::DocumentationCS:
{base::DocumentationCS} 'documentation' value=SINGLE_QUOTED_STRING?
('(' ownedDetails+=DetailCS (',' ownedDetails+=DetailCS)* ')')?
';'
;
EnumerationCS returns base::EnumerationCS:
'enum' name=UnrestrictedName
(ownedSignature=TemplateSignatureCS)?
(':' instanceClassName=SINGLE_QUOTED_STRING)?
('{' (isSerializable?='serializable' | '!serializable')? '}')?
( ('{' (ownedAnnotations+=AnnotationElementCS
| ownedLiterals+=EnumerationLiteralCS
| ownedConstraints+=InvariantConstraintCS)* '}')
| ';'
)
;
EnumerationLiteralCS returns base::EnumerationLiteralCS:
(('literal' name=UnrestrictedName) | name=EnumerationLiteralName) ('=' value=SIGNED)?
(('{' ownedAnnotations+=AnnotationElementCS* '}')
|';'
)
;
ImportCS returns base::ImportCS:
'import' (name=UnrestrictedName ':')? ownedPathName=URIPathNameCS (isAll?='::*')? ';'
;
LibraryCS returns base::LibraryCS:
'library' (name=UnrestrictedName ':')? referredPackage=[pivot::Package|URI] ';'
;
ModelElementCS returns base::ModelElementCS:
ClassCS | EnumerationLiteralCS | OperationCS | PackageCS | StructuralFeatureCS
;
ModelElementRefCS returns base::ModelElementRefCS:
'reference' ownedPathName=PathNameCS ';'
;
OperationCS returns base::OperationCS:
(isStatic?='static'? & isDefinition?='definition'?)
'operation' (ownedSignature=TemplateSignatureCS)? name=UnrestrictedName
'(' (ownedParameters+=ParameterCS (',' ownedParameters+=ParameterCS)*)? ')'
(':' ownedType=TypedMultiplicityRefCS)?
('throws' ownedExceptions+=TypedRefCS (',' ownedExceptions+=TypedRefCS)*)?
('{'((isDerived?='derived' | '!derived') ','?)? &
((isOrdered?='ordered' | '!ordered') ','?)? &
((isNotUnique?='!unique' | 'unique') ','?)?
'}')?
( ('{' (ownedAnnotations+=AnnotationElementCS
| ownedPreconditions+=PreconditionConstraintCS
| ('body' UnrestrictedName? ':' ownedBodyExpressions+=SpecificationCS? ';')
| ownedPostconditions+=PostconditionConstraintCS)* '}')
| ';'
)
;
PackageCS returns base::PackageCS:
'package' name=UnrestrictedName
(':' nsPrefix=UnrestrictedName)? ('=' nsURI=URI)?
(('{'
(ownedAnnotations+=AnnotationElementCS | ownedPackages+=PackageCS | ownedClasses+=ClassCS)*
'}')
|';'
)
;
ParameterCS returns base::ParameterCS:
name=UnrestrictedName
(':' ownedType=TypedMultiplicityRefCS)?
('{'((isOrdered?='ordered' | '!ordered') ','?)? &
((isNotUnique?='!unique' | 'unique') ','?)?
'}')?
('{' ownedAnnotations+=AnnotationElementCS* '}')?
;
ReferenceCS returns base::ReferenceCS:
(isStatic?='static'? & isDefinition?='definition'?)
'property' name=UnrestrictedName
('#' referredOpposite=[pivot::Property|UnrestrictedName])?
(':' ownedType=TypedMultiplicityRefCS)?
('=' default=SINGLE_QUOTED_STRING)?
('{'((isComposes?='composes' | '!composes') ','?)? &
((isDerived?='derived' | '!derived') ','?)? &
((isOrdered?='ordered' | '!ordered') ','?)? &
((isReadonly?='readonly' | '!readonly') ','?)? &
((isResolve?='resolve' | '!resolve') ','?)? &
((isTransient?='transient' | '!transient') ','?)? &
((isNotUnique?='!unique' | 'unique') ','?)? &
((isUnsettable?='unsettable' | '!unsettable') ','?)? &
((isVolatile?='volatile' | '!volatile') ','?)?
'}')?
( ('{' (ownedAnnotations+=AnnotationElementCS
| ('key' referredKeys+=[pivot::Property|UnrestrictedName] (',' referredKeys+=[pivot::Property|UnrestrictedName])* ';')
| ('derivation' UnrestrictedName? ':' ownedDefaultExpressions+=SpecificationCS? ';')
| ('initial' UnrestrictedName? ':' ownedDefaultExpressions+=SpecificationCS? ';') )* '}')
| ';'
)
;
SpecificationCS returns essentialocl::ExpSpecificationCS:
ownedExpression=ExpCS | exprString=UNQUOTED_STRING
;
StructuredClassCS returns base::StructuredClassCS:
isAbstract?='abstract'?
'class' name=UnrestrictedName
(ownedSignature=TemplateSignatureCS)?
('extends' ownedSuperTypes+=TypedRefCS (',' ownedSuperTypes+=TypedRefCS)*)?
(':' instanceClassName=SINGLE_QUOTED_STRING)?
('{' isInterface?='interface'?
'}')?
( ('{' (ownedAnnotations+=AnnotationElementCS
| ownedOperations+=OperationCS
| ownedProperties+=StructuralFeatureCS
| ownedConstraints+=InvariantConstraintCS)* '}')
| ';'
)
;
StructuralFeatureCS returns base::StructuralFeatureCS:
AttributeCS | ReferenceCS
;
SysMLCS returns SysMLCS:
{SysMLCS} 'sysml' ((ownedDetails+=DetailCS ';') | ('{' (ownedDetails+=DetailCS ';')* '}'))
;
TypeIdentifier:
UnrestrictedName
| PrimitiveTypeIdentifier
;
TypedMultiplicityRefCS returns base::TypedRefCS:
TypedRefCS (ownedMultiplicity=MultiplicityCS)?
;
//---------------------------------------------------------------------------------
// Base overrides
//---------------------------------------------------------------------------------
TemplateBindingCS returns base::TemplateBindingCS:
('(' ownedSubstitutions+=TemplateParameterSubstitutionCS (',' ownedSubstitutions+=TemplateParameterSubstitutionCS)* ')')
| ('<' ownedSubstitutions+=TemplateParameterSubstitutionCS (',' ownedSubstitutions+=TemplateParameterSubstitutionCS)* '>')
;
TemplateSignatureCS returns base::TemplateSignatureCS:
('(' ownedParameters+=TypeParameterCS (',' ownedParameters+=TypeParameterCS)* ')')
| ('<' ownedParameters+=TypeParameterCS (',' ownedParameters+=TypeParameterCS)* '>')
;
TypedRefCS returns base::TypedRefCS:
TypeLiteralCS | TypedTypeRefCS
;
UnrestrictedName returns ecore::EString:
EnumerationLiteralName
| 'annotation'
| 'documentation'
| 'invariant'
| 'literal'
| 'serializable'
| 'sysml'
;