diff options
Diffstat (limited to 'extraplugins/alf09/src/org/eclipse/papyrus/alf/Alf.xtext')
-rw-r--r-- | extraplugins/alf09/src/org/eclipse/papyrus/alf/Alf.xtext | 640 |
1 files changed, 640 insertions, 0 deletions
diff --git a/extraplugins/alf09/src/org/eclipse/papyrus/alf/Alf.xtext b/extraplugins/alf09/src/org/eclipse/papyrus/alf/Alf.xtext new file mode 100644 index 00000000000..614ce459b29 --- /dev/null +++ b/extraplugins/alf09/src/org/eclipse/papyrus/alf/Alf.xtext @@ -0,0 +1,640 @@ +/***************************************************************************** + * Copyright (c) 2011 CEA LIST. + * + * + * 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: + * CEA LIST - Initial API and implementation + * + *****************************************************************************/ + +grammar org.eclipse.papyrus.alf.Alf with org.eclipse.xtext.common.Terminals + +generate alf "http://www.eclipse.org/papyrus/alf/Alf" + +/* + Test rule +*/ +Test : + ('testExpression' expression += Expression)* + ('testAssignmentExpression' assignExpression += AssignmentCompletion)* + ('testStatement' statements += Statement)* + ('testBlock' block = Block); + //('testStatementSequence' statement += StatementSequence)* ; + +/********************************* +* PrimitiveLiterals +**********************************/ + +LITERAL: + BOOLEAN_LITERAL | + NUMBER_LITERAL | + STRING_LITERAL +; + +BOOLEAN_LITERAL : + value = BooleanValue ; // (suffix = SuffixExpression) ? ; + +enum BooleanValue : + TRUE = 'true' | + FALSE = 'false' ; + +NUMBER_LITERAL : + INTEGER_LITERAL | UNLIMITED_LITERAL ; + +INTEGER_LITERAL : + value = IntegerValue ; // (suffix = SuffixExpression) ? ; + +UNLIMITED_LITERAL : + value = '*' ; // (suffix = SuffixExpression) ? ; + +terminal IntegerValue : + ('0' | '1'..'9' (('_')? '0'..'9')*) | //DECIMAL + (('0b' | '0B') '0'..'1' (('_')? '0'..'1')*) | // BINARY + (('0x'|'0X') ('0'..'9'|'a'..'f'|'A'..'F') (('_')? ('0'..'9'|'a'..'f'|'A'..'F'))*) | // HEX + ('0' ('_')? '0'..'7' (('_')? '0'..'7')*) // OCT +; + +STRING_LITERAL : + value = STRING ; // (suffix = SuffixExpression) ?; + +NameExpression : + (((prefixOp = ('++'|'--') (path=QualifiedNamePath)? id = ID)) + | + ((path=QualifiedNamePath)? id = ID + (invocationCompletion = Tuple + | sequenceConstructionCompletion = SequenceConstructionOrAccessCompletion + | postfixOp = ('++'|'--'))?)) (suffix = SuffixExpression) ? + ; + +QualifiedNamePath : + (namespace+=UnqualifiedName'::')+ +; + +UnqualifiedName : + name = ID (templateBinding = TemplateBinding)? +; + +TemplateBinding : + '<'bindings+=NamedTemplateBinding (',' bindings +=NamedTemplateBinding)*'>' +; + +NamedTemplateBinding : + formal = ID '=>' actual = QualifiedNameWithBinding +; + +QualifiedNameWithBinding : + id = ID (binding=TemplateBinding)? ('::' remaining=QualifiedNameWithBinding)?; + +Tuple : + {Tuple}'('(tupleElements += TupleElement (',' tupleElements+=TupleElement)*)?')' +; + +TupleElement : + argument = Expression +; + +/************** + * Expressions + **************/ + +Expression : + ConditionalTestExpression +; + +ConditionalTestExpression : + exp=ConditionalOrExpression ('?' whenTrue=ConditionalTestExpression ':' whenFalse=ConditionalTestExpression)? +; + +ConditionalOrExpression : + exp+=ConditionalAndExpression ('||' exp+=ConditionalAndExpression)* +; + +ConditionalAndExpression : + exp+=InclusiveOrExpression ('&&' exp+=InclusiveOrExpression)* +; + +InclusiveOrExpression : + exp+=ExclusiveOrExpression ('|' exp+=ExclusiveOrExpression)* +; + +ExclusiveOrExpression : + exp+=AndExpression ('^' exp+=AndExpression)* +; + +AndExpression : + exp+=EqualityExpression ('&' exp+=EqualityExpression)* +; + +EqualityExpression : + exp+=ClassificationExpression (op+=('==' | '!=') exp+=ClassificationExpression)* +; + +//enum EqualityOperator : +// EQUALS = '==' | +// NOT_EQUALS = '!=' +//; + +ClassificationExpression : + exp=RelationalExpression (op=('instanceof' | 'hastype') typeName=NameExpression)? +; + +//enum ClassificationOperator : +// INSTANCEOF = 'instanceof' | +// HASTYPE = 'hastype' +//; + +RelationalExpression : + left=ShiftExpression (op=('<' | '>' | '<=' | '>=') right=ShiftExpression)? +; + +//RelationalOperator : +// LOWER = '<' | +// UPPER = '>' | +// LOWER_EQUALS = '<=' | +// UPPER_EQUALS = '>=' +//; + +ShiftExpression : + exp+=AdditiveExpression (op=('<<' | '>>' | '>>>') exp+=AdditiveExpression)? +; + +//enum ShiftOperator : +// LSHIFT = '<<' | +// RSHIFT = '>>' | +// URSHIFT = '>>>' +//; + +AdditiveExpression : + exp+=MultiplicativeExpression (op+=('+' | '-') exp+=MultiplicativeExpression)* +; + +//enum AdditiveOp : +// PLUS = '+' | +// MINUS = '-' +//; + +MultiplicativeExpression : + exp+=UnaryExpression (op+=('*' | '/' | '%') exp+=UnaryExpression)* +; + +//enum MultiplicativeOp : +// MULT = '*' | +// DIV = '/' | +// MOD = '%' +//; + +UnaryExpression: + (op=('!'|'-'|'+'|'$'|'~'))? + exp=PrimaryExpression ; + +//PrimaryExpression : +// prefix = ValueSpecification (suffix = SuffixExpression)? +//; + +PrimaryExpression : + prefix = ValueSpecification +; + +SuffixExpression : + OperationCallExpression | + PropertyCallExpression | + LinkOperationExpression | + SequenceOperationExpression | + SequenceReductionExpression | + SequenceExpansionExpression | + ClassExtentExpression +; + +OperationCallExpression : + '.' operationName = ID tuple = Tuple (suffix = SuffixExpression)? +; + +// OperationCallExpressionWithoutDot : +// operationName = ID tuple = Tuple (suffix = SuffixExpression)? +// ; + +PropertyCallExpression : + '.' propertyName = ID ('[' index=Expression ']')? (suffix = SuffixExpression)? +; + +LinkOperationExpression : + '.' kind = LinkOperationKind tuple = LinkOperationTuple +; + +LinkOperationTuple : + '('linkOperationTupleElement += LinkOperationTupleElement (',' linkOperationTupleElement += LinkOperationTupleElement)*')' +; + +//LinkOperationTupleElement : +// objectOrRole = ID (('['roleIndex = Expression ']')? '=>' object = ID)? +//; + +LinkOperationTupleElement : + role = ID ('['roleIndex = Expression ']')? '=>' object = Expression +; + +enum LinkOperationKind : + CREATE = 'createLink' | + DESTROY = 'destroyLink' | + CLEAR = 'clearAssoc' +; + +SequenceOperationExpression : + //'->' operationName = ID tuple = Tuple (suffix = SuffixExpression) ? + '->' operationName = QualifiedNameWithBinding tuple = Tuple (suffix = SuffixExpression) ? +; + +SequenceReductionExpression : + '->' 'reduce' (isOrdered ?= 'ordered')? behavior = QualifiedNameWithBinding (suffix = SuffixExpression) ? +; + +SequenceExpansionExpression : + SelectOrRejectOperation | + CollectOrIterateOperation | + ForAllOrExistsOrOneOperation | + IsUniqueOperation +; + +SelectOrRejectOperation : + '->' op = SelectOrRejectOperator name = ID '('expr=Expression')' (suffix = SuffixExpression) ? +; + +enum SelectOrRejectOperator : + SELECT = 'select' | + REJECT = 'reject' +; + +CollectOrIterateOperation : + '->' op = CollectOrIterateOperator name = ID '('expr=Expression')' (suffix = SuffixExpression) ? +; + +enum CollectOrIterateOperator : + COLLECT = 'collect' | + ITERATE = 'iterate' +; + +ForAllOrExistsOrOneOperation : + '->' op = ForAllOrExistsOrOneOperator name = ID '('expr=Expression')' (suffix = SuffixExpression) ? +; + +enum ForAllOrExistsOrOneOperator : + FORALL = 'forAll' | + EXISTS = 'exists' | + ONE = 'one' +; + +IsUniqueOperation : + '->' 'isUnique' name = ID '('expr=Expression')' (suffix = SuffixExpression) ? +; + +ValueSpecification : + NameExpression | + LITERAL | + ThisExpression | + SuperInvocationExpression | + InstanceCreationExpression | + ParenthesizedExpression | + NullExpression + ; + +NonLiteralValueSpecification : + NameExpression | + ParenthesizedExpression | + InstanceCreationExpression | + ThisExpression | + SuperInvocationExpression +; + +ParenthesizedExpression : + '('expOrTypeCast = Expression')' ((casted = NonLiteralValueSpecification) | (suffix = SuffixExpression))? +; + +NullExpression : + {NullExpression} 'null' +; + +ThisExpression : + {ThisExpression}'this' (suffix = SuffixExpression)? +; + +// SuperInvocationExpression : +// //{SuperInvocationExpression} 'super' ('.' qualifiedNameRoot = ID '::' qualifiedNameRemaining = NameExpression)? //(suffix = SuffixExpression) ? +// 'super' ('.' className = ID '::' operationCallWithoutDot = OperationCallExpressionWithoutDot | operationCall = OperationCallExpression) +//; + +SuperInvocationExpression : + //{SuperInvocationExpression} 'super' ('.' qualifiedNameRoot = ID '::' qualifiedNameRemaining = NameExpression)? //(suffix = SuffixExpression) ? + //'super' ('.' className = ID '::' operationCallWithoutDot = OperationCallExpressionWithoutDot | operationCall = OperationCallExpression) + //'super' ((tuple = Tuple) | + // ('.' (path = QualifiedNamePath) operation = ID tuple = Tuple)) + 'super' ((tuple = Tuple) | + ('.' operationName = QualifiedNameWithBinding tuple = Tuple)) +; + +//InstanceCreationExpression : + //'new' constructor=QualifiedNameWithBinding + // (tuple = Tuple | sequenceConstuctionCompletion = SequenceConstructionCompletion) (suffix = SuffixExpression) ? + //'new' constructor=QualifiedNameWithBinding + // tuple = Tuple (suffix = SuffixExpression) ? +//; + +InstanceCreationExpression : + //'new' constructor=QualifiedNameWithBinding + // (tuple = Tuple | sequenceConstuctionCompletion = SequenceConstructionCompletion) (suffix = SuffixExpression) ? + 'new' constructor=QualifiedNameWithBinding + tuple = InstanceCreationTuple (suffix = SuffixExpression) ? +; + +InstanceCreationTuple : + {InstanceCreationTuple}'('(instanceCreationTupleElement += InstanceCreationTupleElement (',' instanceCreationTupleElement += InstanceCreationTupleElement)*)?')' +; + +//LinkOperationTupleElement : +// objectOrRole = ID (('['roleIndex = Expression ']')? '=>' object = ID)? +//; + +InstanceCreationTupleElement : + role = ID '=>' object = Expression +; + +SequenceConstructionOrAccessCompletion : + (multiplicityIndicator ?= '[' ((accessCompletion = AccessCompletion) | sequenceCompletion = PartialSequenceConstructionCompletion)) | + (expression = SequenceConstructionExpression) +; + +AccessCompletion : + accessIndex = Expression ']' +; + +PartialSequenceConstructionCompletion : + ']' expression = SequenceConstructionExpression +; + +//SequenceConstructionCompletion : +// (multiplicityIndicator ?= '['']')? expression = SequenceConstructionExpression +//; + +SequenceConstructionExpression : + '{'sequenceElement+=SequenceElement + ((',' sequenceElement+=SequenceElement)* | ('..' rangeUpper=Expression)) + '}' +; + +SequenceElement : + Expression | SequenceConstructionExpression +; + +ClassExtentExpression : + {ClassExtentExpression} '.' 'allInstances' '(' ')' +; + +/***************** + * Statements + ****************/ + +Block : + '{' {Block}(sequence = StatementSequence)? '}' +; + +StatementSequence : + (statements += DocumentedStatement)+ +; + +DocumentedStatement : + (comment = (ML_COMMENT | SL_COMMENT))? statement = Statement +; + +InlineStatement : + '/*@' 'inline' '('langageName = ID')' body = STRING '*/' +; + +AnnotatedStatement : + '//@' annotation = Annotation //block = Block + statement = Statement +; + +Statement : + (AnnotatedStatement | + InlineStatement | + BlockStatement | + EmptyStatement | + LocalNameDeclarationStatement | + IfStatement | + SwitchStatement | + WhileStatement | + DoStatement | + ForStatement | + BreakStatement | + ReturnStatement | + AcceptStatement | + ClassifyStatement | + InvocationOrAssignementOrDeclarationStatement | + SuperInvocationStatement | + ThisInvocationStatement | + InstanceCreationInvocationStatement) +; + +Annotation : + kind = AnnotationKind ('('args += ID (',' args += ID)* ')')? +; + +enum AnnotationKind : + ISOLATED = 'isolated' | + DETERMINED = 'determined' | + ASSURED = 'assured' | + PARALLEL = 'parallel' +; + + + +BlockStatement : + block = Block +; + +EmptyStatement : + {EmptyStatement} ';' +; + +LocalNameDeclarationStatement : + 'let' varName = ID ':' + type = QualifiedNameWithBinding + (multiplicityIndicator?='[' ']')? + //'=' init = Expression ';' + '=' init = SequenceElement ';' +; + +IfStatement : + 'if' sequentialClausses = SequentialClauses ( finalClause = FinalClause )? ; + +SequentialClauses : + conccurentClauses += ConcurrentClauses + ( 'else' 'if' conccurentClauses += ConcurrentClauses )* ; + +ConcurrentClauses : + nonFinalClause += NonFinalClause + ( 'or' 'if' nonFinalClause += NonFinalClause )* ; + +NonFinalClause : + '(' condition = Expression ')' block = Block ; + +FinalClause : + 'else' block = Block ; + + +SwitchStatement : + 'switch' '(' expression = Expression ')' '{' + ( switchClause += SwitchClause )* + ( defaultClause = SwitchDefaultClause )? + '}' ; + +SwitchClause : + switchCase += SwitchCase ( switchCase += SwitchCase )* statementSequence = NonEmptyStatementSequence ; + +SwitchCase : + 'case' expression = Expression ':' ; + +SwitchDefaultClause : + 'default' ':' statementSequence = NonEmptyStatementSequence ; + +NonEmptyStatementSequence : + ( statement += DocumentedStatement )+ ; + +/* WHILE STATEMENTS */ +WhileStatement : + 'while' '(' condition = Expression ')' block = Block ; + +/* DO STATEMENTS */ +DoStatement : + 'do' block = Block 'while' '(' condition = Expression ')' ';' ; + +/* FOR STATEMENTS */ +ForStatement : + 'for' '(' control = ForControl ')' block = Block ; + +ForControl : + loopVariableDefinition += LoopVariableDefinition( ',' loopVariableDefinition += LoopVariableDefinition )* ; + +LoopVariableDefinition : + (name = ID 'in' expression1 = Expression ( '..' expression2 = Expression )?) + | (type = QualifiedNameWithBinding name = ID ':' expression = Expression) ; + +/* BREAK STATEMENTS */ +BreakStatement : + {BreakStatement}'break' ';' ; + +/* RETURN STATEMENTS */ +ReturnStatement : + 'return' expression = Expression ';' ; + +/* ACCEPT STATEMENTS */ +AcceptStatement : + clause = AcceptClause + ( simpleAccept = SimpleAcceptStatementCompletion + | compoundAccept = CompoundAcceptStatementCompletion ) ; + +SimpleAcceptStatementCompletion : + {SimpleAcceptStatementCompletion}';' ; + +CompoundAcceptStatementCompletion : + block = Block ( 'or' acceptBlock += AcceptBlock )* ; + +AcceptBlock : + clause = AcceptClause block = Block ; + +AcceptClause : + 'accept' '(' ( name = ID ':' )? qualifiedNameList = QualifiedNameList ')' ; + +/* CLASSIFY STATEMENTS */ +ClassifyStatement : + 'classify' expression = Expression clause = ClassificationClause ';' ; + +ClassificationClause : + classifyFromClause = ClassificationFromClause ( classifyToClause = ClassificationToClause )? + | ( reclassyAllClause = ReclassifyAllClause )? classifyToClause = ClassificationToClause ; + +ClassificationFromClause : + 'from' qualifiedNameList = QualifiedNameList ; + +ClassificationToClause : + 'to' qualifiedNameList = QualifiedNameList ; + +ReclassifyAllClause : + {ReclassifyAllClause}'from' '*' ; + +QualifiedNameList : + qualifiedName += QualifiedNameWithBinding ( ',' qualifiedName += QualifiedNameWithBinding )* ; + +InvocationOrAssignementOrDeclarationStatement : + typePart_OR_assignedPart_OR_invocationPart = NameExpression + //(suffixCompletion = SuffixCompletion)? + ((variableDeclarationCompletion = VariableDeclarationCompletion) | + (assignmentCompletion = AssignmentCompletion))? ';' +; + +SuperInvocationStatement : + _super = SuperInvocationExpression ';'//(suffix = SuffixCompletion)? ';' +; + +ThisInvocationStatement : + //_this = ThisExpression suffix = SuffixCompletion (assignmentCompletion = AssignmentCompletion)? ';' + _this = ThisExpression (assignmentCompletion = AssignmentCompletion)? ';' +; + +InstanceCreationInvocationStatement : + _new = InstanceCreationExpression ';' //(suffix = SuffixCompletion)? ';' +; + +//SuffixCompletion : +// suffix = SuffixExpression +//; + +VariableDeclarationCompletion : + (multiplicityIndicator ?= '[' ']')? variableName = ID initValue = AssignmentCompletion +; + +AssignmentCompletion : + op=AssignmentOperator rightHandSide = SequenceElement + //op=('=' | '+=' | '-=' | '*=' | '%=' | '/=' | '&=' | + // '|=' | '^=' | '<<=' | '>>=' | '>>>=') rightHandSide = Expression +; + +enum AssignmentOperator : + ASSIGN = '=' | + PLUSASSIGN = '+=' | + MINUSASSIGN = '-=' | + MULTASSIGN = '*=' | + MODASSIGN = '%=' | + DIVASSIGN = '/=' | + ANDASSIGN = '&=' | + ORASSIGN = '|=' | + XORASSIGN = '^=' | + LSHIFTASSIGN = '<<=' | + RSHIFTASSIGN = '>>=' | + URSHIFTASSIGN = '>>>=' +; + +/**************** +* Terminals +*****************/ + +//terminal DOUBLE_COLON : '::' ; + +terminal ID : ('a'..'z'|'A'..'Z'|'_') ('a'..'z'|'A'..'Z'|'_'|'0'..'9')* | ('\'' -> '\'') ; +terminal STRING : '"' ( '\\' ('b'|'t'|'n'|'f'|'r'|'"'|"'"|'\\') | !('\\'|'"') )* '"' ; +terminal ML_COMMENT : '/*' !('@') -> '*/'; +terminal SL_COMMENT : '//' !('\n'|'\r'|'@')* ('\r'? '\n')?; + +//terminal IDENTIFIER : ID ; +//terminal IDENTIFIER : ('a'..'z'|'A'..'Z'|'_') ('a'..'z'|'A'..'Z'|'_'|'0'..'9')* | ('\'' -> '\'') ; + +//terminal DOCUMENTATION_COMMENT : '/*' -> '*/' ; + +//terminal ML_COMMENT : '/°' -> '°/'; +//terminal SL_COMMENT : '°°' !('\n'|'\r')* ('\r'? '\n')?; + +//terminal WS : (' '|'\t'|'\r'|'\n')+;
\ No newline at end of file |