| /***************************************************************************** |
| * Copyright (c) 2010 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.marte.vsl.VSL with org.eclipse.xtext.common.Terminals |
| |
| import "http://www.eclipse.org/uml2/5.0.0/UML" as uml |
| import "http://www.eclipse.org/emf/2002/Ecore" as ecore |
| |
| generate vSL "http://www.eclipse.org/papyrus/marte/vsl/VSL" |
| |
| Expression : |
| exp=AndOrXorExpression ; |
| |
| AndOrXorExpression : |
| exp+=EqualityExpression (op+=('and' | 'or' | 'xor') exp+=EqualityExpression)* ; |
| |
| EqualityExpression : |
| exp+=RelationalExpression (op+=('==' | '<>') exp+=RelationalExpression)* ; |
| |
| RelationalExpression : |
| exp+=ConditionalExpression (op+=('<' | '>' | '<=' | '>=') exp+=ConditionalExpression)* ; |
| |
| ConditionalExpression : |
| exp+=AdditiveExpression (op+='?' exp+=AdditiveExpression ':' exp+=AdditiveExpression)? ; |
| |
| AdditiveExpression : |
| exp+=MultiplicativeExpression (op+=('+' | '-') exp+=MultiplicativeExpression)* ; |
| |
| MultiplicativeExpression : |
| exp+=UnaryExpression (op+=('*' | '/' | 'mod') exp+=UnaryExpression)* ; |
| |
| UnaryExpression: |
| (op=('not'|'-'|'+')) unary=UnaryExpression | exp=PrimaryExpression ; |
| |
| PrimaryExpression : |
| prefix=ValueSpecification ('.' suffix=SuffixExpression)?; |
| |
| ValueSpecification: |
| Literal |
| | NameOrChoiceOrBehaviorCall |
| | Interval |
| | CollectionOrTuple |
| | Tuple |
| | TimeExpression |
| | VariableDeclaration |
| | '(' Expression ')' |
| ; |
| |
| SuffixExpression : |
| PropertyCallExpression | OperationCallExpression ; |
| |
| PropertyCallExpression : |
| property=[uml::Property] ('.' suffix=SuffixExpression)? ; |
| |
| OperationCallExpression : |
| operation=[uml::Operation]'('(arguments=ListOfValues)?')' ('.' suffix=SuffixExpression)? ; |
| |
| Literal: |
| NumberLiteralRule |
| | DateTimeLiteralRule |
| | BooleanLiteralRule |
| | NullLiteralRule |
| | DefaultLiteralRule |
| | StringLiteralRule ; |
| |
| NameOrChoiceOrBehaviorCall : |
| // can resolve to : |
| // - EnumSpecification, |
| // - VariableCallExpression |
| // - PropertyCallExpression |
| // - ChoiceExpression |
| (path=QualifiedName)? id=[uml::NamedElement] ('('(arguments = ListOfValues)?')')? ; |
| |
| QualifiedName : |
| path=[uml::Namespace]'::' (remaining=QualifiedName)? ; |
| |
| Interval : |
| (']'|isLowerIncluded='[') lower = Expression '..' upper = Expression (isUpperIncluded=']'|'[') ; |
| |
| CollectionOrTuple : |
| '{' listOfValues=ListOfValues '}'; |
| |
| Tuple : |
| '{' listOfValueNamePairs=ListOfValueNamePairs '}'; |
| |
| ListOfValues : |
| values+=Expression (',' values+=Expression )* ; |
| |
| ListOfValueNamePairs : |
| valueNamePairs+=ValueNamePair (',' valueNamePairs+=ValueNamePair)* ; |
| |
| ValueNamePair : |
| property = [uml::Property] '=' value=Expression ; |
| |
| TimeExpression : |
| InstantObsExpression | |
| DurationObsExpression | |
| JitterExp ; |
| |
| InstantObsExpression : |
| '@' id=InstantObsName ('('index=Expression')')? ('when' '('condition=Expression')' )?; |
| |
| InstantObsName : |
| (path=QualifiedName)? instantId=[uml::TimeObservation] ; |
| |
| DurationObsExpression : |
| '&' id=DurationObsName ('('index=Expression')')? ('when' '('condition=Expression')' )?; |
| |
| DurationObsName : |
| (path=QualifiedName)? durationId=[uml::DurationObservation] ; |
| |
| JitterExp : |
| 'jitter('firstInstant=InstantObsExpression ('-' secondInstant=InstantObsExpression)? ')' ; |
| |
| VariableDeclaration : |
| (variableDeclaration=VariableDirectionKind)? |
| '$' name=ID ( |
| (':' type=DataTypeName ('=' '('initValue = Expression')')? ) | |
| ('=' '('initValue = Expression')') |
| ) ; |
| |
| VariableDirectionKind : |
| 'in'|'out'|'inout' ; |
| |
| DataTypeName : |
| (path=QualifiedName)? type=[uml::DataType] ; |
| |
| ////////////////////////////////////////////////////////////////////////////////////////////////////// |
| //LITERAL |
| ////////////////////////////////////////////////////////////////////////////////////////////////////// |
| |
| NumberLiteralRule : |
| IntegerLiteralRule |
| | UnlimitedLiteralRule |
| | RealLiteralRule ; |
| |
| IntegerLiteralRule : |
| value = IntegerLiteral ; |
| terminal IntegerLiteral : |
| ('+'|'-')? |
| ( |
| ('0'..'9')+ | |
| '0x' ('0'..'9' | 'A'..'F' | 'a'..'f')+ | |
| '0b' ('0'..'1')+ |
| ) ; |
| |
| //UnlimitedLiteralRule : |
| // value = UnlimitedLiteral ; |
| //terminal UnlimitedLiteral : |
| // '*' ; |
| |
| UnlimitedLiteralRule : |
| value = '*' ; |
| |
| RealLiteralRule : |
| value = RealLiteral ; |
| terminal RealLiteral : |
| ('+'|'-')?('0'..'9')+ '.' ('0'..'9')+ |
| ('E' ('+'|'-')? ('0'..'9')+)?; |
| |
| //DateTimeLiteral: |
| // TimeString (DateString)? (DayString)? | |
| // DateString (DayString)? | |
| // DayString ; |
| //terminal DateString : |
| // ('0'..'9')('0'..'9')('0'..'9')('0'..'9')'/'('0'('0'..'9')|'1'('0'..'2'))'/'(('0'..'2')('0'..'9')|'3' ('0'|'1')) ; |
| //terminal TimeString : |
| // (('0'..'1')('0'..'9')|'2'('0'..'3'))':'('0'..'5')('0'..'9')(':'('0'..'5')('0'..'9')(':'('0'..'9')('0'..'9'))?)? ; |
| //terminal DayString : |
| // "Mon" | "Tue" | "Wed" | "Thr" | "Fri" | "Sat" | "Sun" ; |
| |
| DateTimeLiteralRule : |
| value = DateTimeLiteral ; |
| terminal DateTimeLiteral: |
| ((('0'..'1')('0'..'9')|'2'('0'..'3'))':'('0'..'5')('0'..'9')(':'('0'..'5')('0'..'9')(':'('0'..'9')('0'..'9'))?)?) (" "('0'..'9')('0'..'9')('0'..'9')('0'..'9')'/'('0'('0'..'9')|'1'('0'..'2'))'/'(('0'..'2')('0'..'9')|'3' ('0'|'1')))? (" " ("Mon" | "Tue" | "Wed" | "Thr" | "Fri" | "Sat" | "Sun"))? | |
| (('0'..'9')('0'..'9')('0'..'9')('0'..'9')'/'('0'('0'..'9')|'1'('0'..'2'))'/'(('0'..'2')('0'..'9')|'3' ('0'|'1'))) (" "("Mon" | "Tue" | "Wed" | "Thr" | "Fri" | "Sat" | "Sun"))? | |
| ("Mon" | "Tue" | "Wed" | "Thr" | "Fri" | "Sat" | "Sun") ; |
| |
| BooleanLiteralRule : |
| value = BooleanLiteral ; |
| terminal BooleanLiteral : |
| "true"|"false" ; |
| |
| NullLiteralRule : |
| value = NullLiteral ; |
| terminal NullLiteral : |
| "null" ; |
| |
| //DefaultLiteralRule : |
| // value = DefaultLiteral ; |
| //terminal DefaultLiteral : |
| // '/' ; |
| |
| DefaultLiteralRule: |
| value = '/' ; |
| |
| StringLiteralRule : |
| value = STRING ; |