| /** |
| * <copyright> |
| * |
| * Copyright (c) 2012 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 v2.0 |
| * which accompanies this distribution, and is available at |
| * http://www.eclipse.org/legal/epl-v20.html |
| * |
| * Contributors: |
| * E.D.Willink - initial API and implementation |
| * |
| * </copyright> |
| * |
| * $Id$ |
| */ |
| grammar org.eclipse.qvto.examples.xtext.imperativeocl.ImperativeOCL with org.eclipse.ocl.xtext.essentialocl.EssentialOCL |
| |
| //generate imperativeoclcs "http://www.eclipse.org/qvt/pivot/1.0/ImperativeOCLCS" |
| //import "http://www.eclipse.org/qvt/pivot/1.0/ImperativeOCLCS" |
| import "platform:/resource/org.eclipse.qvto.examples.xtext.imperativeocl/model/ImperativeOCLCS.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 "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 |
| |
| GrammmarCS returns essentialocl::ExpCS: ImperativeOCLExpCS; |
| |
| enum SeverityKindCS: error='error' | warning='warning' | fatal='fatal'; |
| enum InitOpCS : Equals='=' | ColonEquals=':=' | ColonColonEquals='::='; |
| enum AssignOpCS : Single=':=' | MultiWithReset='::=' | MultiWithoutReset='+='; |
| |
| //ImperativeOCLReservedKeyword: |
| // 'default' |
| // | 'elif' |
| // | RESOLVE_KIND |
| // | RESOLVE_IN_KIND; |
| // |
| //ImperativeOCLPrefixOperator: |
| // '#' | '##' | '*'; |
| // |
| //ImperativeOCLInfixOperator: |
| // ASSIGN_OP | 'default' | '=='; |
| // |
| //ImperativeOCLNavigationOperator: |
| // '!->'; |
| |
| //PrefixOperator: |
| // EssentialOCLPrefixOperator | QVToPrefixOperator; |
| // |
| //InfixOperator: |
| // EssentialOCLInfixOperator | QVToInfixOperator; |
| // |
| //NavigationOperator: |
| // EssentialOCLNavigationOperator | QVToNavigationOperator; |
| |
| ImperativeOCLExpCS returns essentialocl::ExpCS: ExpCS; |
| |
| // ********* ImperativeOCL Types ********* |
| |
| // TypeLiteralCS redefined to include the new List and Dict types |
| // FIXME refactor its definition in EssentialOCL to allow extension |
| TypeLiteralCS returns base::TypedRefCS: |
| PrimitiveTypeCS |
| | CollectionTypeCS |
| | MapTypeCS |
| | TupleTypeCS |
| | ListTypeCS |
| | DictTypeCS; |
| |
| ListTypeCS : |
| 'List' '(' ownedTypeRef=TypeExpCS ')' |
| ; |
| |
| |
| DictTypeCS : |
| 'Dict' '(' ownedKeyTypeRef=TypeExpCS ',' ownedValueTypeRef=TypeExpCS ')' |
| ; |
| |
| // Typedef is deprecated |
| |
| // ********* ImperativeOCL Expressions ********* |
| // PrimaryExpCS redefined to include the new List and Dict literal expressions |
| // FIXME refactor its definition in EssentialOCL to allow extension |
| PrimaryExpCS returns essentialocl::ExpCS: // These rules are ordered most rejectable first |
| NestedExpCS |
| | IfExpCS |
| | SelfExpCS |
| | PrimitiveLiteralExpCS |
| | TupleLiteralExpCS |
| | MapLiteralExpCS |
| | CollectionLiteralExpCS |
| | LambdaLiteralExpCS |
| | ImperativeExpCS |
| | NameExpCS |
| ; |
| |
| ImperativeExpCS returns essentialocl::ExpCS : |
| ExpressionBlockCS |
| | AssertExpCS |
| | BreakExpCS |
| | ContinueExpCS |
| | InstantiationExpCS |
| | LogExpCS |
| | RaiseExpCS |
| | VarsInitializationCS |
| | ListLiteralExpCS |
| | DictLiteralExpCS |
| | TypeLiteralExpCS |
| | ReturnExpCS |
| | ComputeExpCS |
| | ForExpCS |
| | WhileExpCS |
| | ImperativeIterateExpCS |
| | SwitchExpCS |
| | AssignExpCS |
| | TryExpCS |
| ; |
| |
| AssertExpCS: |
| 'assert' (severity=SeverityKindCS)? ownedAssertion=ExpCS ('with' ownedLog=LogExpCS)? |
| ; |
| AssignExpCS: |
| ownedLeft=NameExpCS assignOp=AssignOpCS ownedValue=ExpCS ('default' ownedDefault=ExpCS)? |
| ; |
| |
| BreakExpCS: |
| {BreakExpCS} |
| 'break' |
| ; |
| |
| CatchExpCS: |
| 'except' '(' (varName=UnrestrictedName ':')? ownedExceptionRefs+=TypeExpCS (',' ownedExceptionRefs+=TypeExpCS )* ')' '{' |
| (ownedExps+=ExpCS)* |
| '}' |
| ; |
| ComputeExpCS : |
| 'compute' '(' ownedResultVar = VarDeclarationCS ')' '{' |
| ownedExps += ExpressionStatementCS |
| '}' |
| ; |
| ContinueExpCS: |
| {ContinueExpCS} |
| 'continue' |
| ; |
| |
| DictLiteralExpCS : |
| 'Dict' '{' {DictLiteralExpCS} |
| (ownedParts+=DictLiteralPartCS |
| (',' ownedParts+=DictLiteralPartCS)*)? |
| '}' |
| ; |
| |
| DictLiteralPartCS : |
| ownedKey = PrimitiveLiteralExpCS '=' ownedValue = ExpCS |
| ; |
| |
| ExpressionBlockCS : |
| {ExpressionBlockCS} |
| 'do'? |
| '{' ownedExps += ExpressionStatementCS* '}' |
| ; |
| |
| ExpressionStatementCS returns essentialocl::ExpCS: |
| ExpCS ';'? |
| ; |
| |
| ExtentRefCS: |
| ownedPathName = PathNameCS |
| ; |
| // FIXME align with NameExpCS |
| ForExpCS: |
| ('forEach' | isOne?='forOne') '(' (ownedTarget=VarDeclarationCS ';')? ownedIterator=VarDeclarationNoInitCS ('|' ownedCondition=ExpCS)? ')' |
| ownedBody=ExpCS |
| ; |
| |
| // FIXME align with NameExpCS |
| ImperativeIterateExpCS : |
| (name='xcollect' '(' (ownedIterator=VarDeclarationNoInitCS '|')? ownedBody=ExpCS ')') |
| | (name=('xselect' | 'xselectOne') '(' (ownedIterator=VarDeclarationNoInitCS '|')? ownedCondition=ExpCS ')') |
| | (name=('xcollectselect' | 'xcollectselectOne') '(' (ownedIterator=VarDeclarationNoInitCS ';')? ownedTarget=VarDeclarationCS ':=' ownedBody=ExpCS '|' ownedCondition=ExpCS ')') |
| ; |
| |
| // FIXME if a new parameter can specify modelExtent, then it should probably belong to QVTOperational package rather than ImperativeOCL |
| InstantiationExpCS: |
| 'new' ownedClassRef=TypeExpCS ('@' ownedExtentRef=TypeNameExpCS )? '(' (ownedArguments+=ExpCS (',' ownedArguments+=ExpCS )*)? ')' |
| ; |
| |
| ListLiteralExpCS : |
| 'List' '{' {ListLiteralExpCS} |
| (ownedParts+=CollectionLiteralPartCS |
| (',' ownedParts+=CollectionLiteralPartCS)*)? |
| '}' |
| ; |
| |
| // FIXME align with NameExpCS |
| // FIXME severity -> enum |
| // Improve spec: result.log("message", severity) when condition |
| LogExpCS : |
| 'log' '(' ownedMessage=StringLiteralExpCS (',' ownedElement=ExpCS )? (',' severity = SeverityKindCS )? ')' ('when' ownedCondition=ExpCS)? |
| ; |
| |
| RaiseExpCS: |
| 'raise' ownedExceptionRef=TypeExpCS '(' ownedArguments+=ExpCS (',' ownedArguments+=ExpCS)* ')' |
| // FIXME OMG: should support several arguments |
| ; |
| |
| ReturnExpCS : |
| 'return' {ReturnExpCS} (ownedValue = ExpCS)? |
| ; |
| |
| StringLiteral: |
| SINGLE_QUOTED_STRING | DOUBLE_QUOTED_STRING |
| ; |
| |
| // FIXME OMG issue: list->swith(i) {...} syntax ????? |
| // FIXME SwitchExpCS should probably be a CallExp |
| SwitchExpCS: |
| (ifSyntax?='if' ownedAltParts+= SwitchAltCS |
| ('elif' ownedAltParts+=SwitchAltCS)* |
| ('else' ownedElsePart=ExpCS)? |
| ('endif')? |
| ) |
| | ('switch' ('(' ownedIterator=VarDeclarationNoInitCS ')')? '{' |
| ('case' ownedAltParts+= SwitchAltCS )+ |
| ('else' ownedElsePart=ExpCS)? |
| '}' |
| ) |
| ; |
| |
| SwitchAltCS: |
| '(' ownedCondition=ExpCS ')' ownedBody=ExpCS |
| ; |
| |
| TryExpCS : |
| {TryExpCS} |
| 'try' '{' |
| (ownedExps+=ExpCS)* |
| '}' (ownedCatchs+=CatchExpCS)+ |
| // FIXME in the AS there should be at least one CatchExp |
| ; |
| |
| // FIXME there should be additional disambiguation between NameExpCS and UnlinkExp |
| // UnlinkExpCS returns essentialocl::NameExpCS: |
| |
| VarDeclarationCS : |
| name=UnrestrictedName (':' ownedType=TypeExpCS)? ((initOp=InitOpCS) ownedInitExpression=ExpCS)? |
| ; |
| |
| VarDeclarationNoInitCS returns VarDeclarationCS: |
| name=UnrestrictedName (':' ownedType=TypeExpCS)? |
| ; |
| |
| VarsInitializationCS: |
| 'var' ownedVarDeclarations+=VarDeclarationCS (',' ownedVarDeclarations+=VarDeclarationCS)* |
| ; |
| |
| WhileExpCS: |
| 'while' '(' (ownedResultVar= VarDeclarationCS ';')? ownedCondition=ExpCS ')' '{' |
| ownedExps+=ExpressionStatementCS* |
| '}' |
| ; |
| |