ATSyRA Studio

ATSyRA ABS Language Reference

ATSyRA ABS Language Reference
TODO list of ABS language keyword and links to other section in the user guide

1. ABS textual syntax

ABS comes with several concrete syntaxes, one of them is a textual syntax written with xText.

1.1. ABS XText grammar

ABS xText grammar from fr.irisa.atsyra.absystem.xtext plugin :

ABS.xtext
// automatically generated by Xtext
grammar fr.irisa.atsyra.absystem.xtext.AssetBasedSystemDsl with org.eclipse.xtext.common.Terminals

import "http://www.irisa.fr/atsyra//absystem"
import "http://www.eclipse.org/emf/2002/Ecore" as ecore

AssetBasedSystem returns AssetBasedSystem:
	{AssetBasedSystem}
	'AssetBasedSystem'
	(imports+=Import)*
	(localizations+=LocaleGroup)*
	(definitionGroups+=DefinitionGroupRule | assetGroups+=AssetGroup)*
	;


AbstractAssetType returns AbstractAssetType:
	AssetType | AssetTypeAspect;
	
PrimitiveDataType returns PrimitiveDataType:
	PrimitiveDataType_Impl | EnumDataType;

DefinitionGroupRule returns DefinitionGroup:
	{DefinitionGroup}
	'DefinitionGroup'
	name=EString
	'{' 
		(
			('tags' '(' (tags+=[Tag|QualifiedName] ( "," tags+=[Tag|QualifiedName])*)? ')' )? &
			('annotations' '{' (annotations+=AnnotationEntry)*'}')?
		)
		definitions+=Definition*
	'}';
	
Definition returns Definition:
	DefinitionGroupRule | AbstractAssetType | Contract | PrimitiveDataType | StaticMethod | Tag | AnnotationKey | GuardedAction | Requirement
;

AssetGroup returns AssetGroup:
	{AssetGroup}
	'AssetGroup'
	name=EString
	'{' 
		('annotations' '{' (annotations+=AnnotationEntry)*'}')?
		elements+=AssetGroupContent*
	'}';

AssetGroupContent returns AssetGroupContent:
	AssetGroup | Asset | AssetLink | Goal
;

AnnotationKey returns AnnotationKey:
	{AnnotationKey}
	"annotation" name=EString
;

AssetType returns AssetType:
	{AssetType}
	(abstract?='abstract')?
	'AssetType'
	name=EString
	('extends' '(' (extends+=[AssetType|QualifiedName] (',' extends+=[AssetType|QualifiedName])* )? ')')?
	'{' (
			('level' level=EString)? &
			('tags' '(' (tags+=[Tag|QualifiedName] ( "," tags+=[Tag|QualifiedName])*)? ')' )? &
			('description' (descriptionFormat=TextFormat)? description=STRING)? &
			('annotations' '{' (annotations+=AnnotationEntry)*'}')?
		)
		(
			assetTypeProperties+=AssetTypeReference |
			assetTypeAttributes+=AssetTypeAttribute
		)*
	'}';
	
AssetTypeAspect returns AssetTypeAspect:
	'AssetTypeAspect'
	baseAssetType=[AssetType|QualifiedName]
	'{'
		(
			assetTypeProperties+=AssetTypeReference |
			assetTypeAttributes+=AssetTypeAttribute
		)*
	'}';

PrimitiveDataType_Impl returns PrimitiveDataType:
	{PrimitiveDataType}
	'PrimitiveDataType'
	name=EString;
	
StaticMethod returns StaticMethod:
	{StaticMethod}
	'StaticMethod'
	name=EString
;
LambdaParameter returns LambdaParameter:
	{LambdaParameter}
	name=EString
;


Tag returns Tag:
	{Tag}
	'Tag'
	name=EString;

AssetTypeReference returns AssetTypeReference:
	//(many?='many')?
	(isContainer?='container')? 'reference'
	name=EString
	':' propertyType=[AssetType|QualifiedName]
	(
		multiplicity=MultiplicitySingle? ('opposite' oppositeTypeReference=[AssetTypeReference])? (hasDefault?='default' 'undefined')? |
		multiplicity=MultiplicityMany ('opposite' oppositeTypeReference=[AssetTypeReference])?  (hasDefault?='default' '[' ']')?
	);

AssetTypeAttribute returns AssetTypeAttribute:
	{AssetTypeAttribute}
	'attribute'
	name=EString
	':' attributeType=[PrimitiveDataType|QualifiedName]
	(
		multiplicity=MultiplicitySingle? (hasDefault?='default' defaultValues+=AttributeConstantExpression)? |
		multiplicity=MultiplicityMany (hasDefault?='default' '[' defaultValues+=AttributeConstantExpression? (',' defaultValues+=AttributeConstantExpression)*']')?
	);

enum MultiplicitySingle returns Multiplicity:
	One='[1]' | ZeroOrOne='[0..1]'
;

enum MultiplicityMany returns Multiplicity:
	ZeroOrMany='[*]' | OneOrMany='[1..*]'
;

EBoolean returns ecore::EBoolean:
	'true' | 'false';

EnumDataType returns EnumDataType:
	{EnumDataType}
	'EnumDataType'
	name=EString
	'{'
		('annotations' '{' (annotations+=AnnotationEntry)*'}')?
		enumLiteral+=EnumLiteral ( "," enumLiteral+=EnumLiteral)* 
	'}';

EnumLiteral returns EnumLiteral:
	{EnumLiteral}
	name=EString
;

Asset returns Asset:
	'Asset'
	name=EString ':' assetType=[AssetType|QualifiedName]
	'{' 
		('description' (descriptionFormat=TextFormat)? description=STRING)?
		(assetAttributeValues+=AssetAttributeValue ( assetAttributeValues+=AssetAttributeValue)* )?
	'}';

AssetLink returns AssetLink:
	'link' sourceAsset=[Asset|QualifiedName] 
	'to' targetAsset=[Asset|QualifiedName]
	('as' referenceType=[AssetTypeReference|QualifiedName] ('#' oppositeReferenceType=[AssetTypeReference|QualifiedName])?)? 
	;

AssetAttributeValue returns AssetAttributeValue:
	{AssetAttributeValue}
	'attribute' attributeType=[AssetTypeAttribute|QualifiedName] ':=' (
		values+=AttributeConstantExpression |
		collection?='[' values+=AttributeConstantExpression (',' values+=AttributeConstantExpression)* ']'
	);

AttributeConstantExpression returns ConstantExpression:
	{IntConstant} value=INT |
	{StringConstant} value=STRING |
	{BooleanConstant} value=('true' | 'false') |
	{VersionConstant} value=Version |
	{EnumConstant} value=[EnumLiteral|QualifiedName] |
	Undefined
	;

Contract returns Contract:
	{Contract}
	(dynamic?='dynamic' | ('static')?)
	'contract'
	name=EString
	'(' (guardParameters+=GuardParameter (',' guardParameters+=GuardParameter)* )? ')'
	'{'
	(('severity' '=' severity=Severity)? & 
	 ('description' (descriptionFormat=TextFormat)? description=STRING)? &
	 ('annotations' '{' (annotations+=AnnotationEntry)*'}')?
	)
	'guard' '=' guardExpression=Expression
	'}';
	
GuardedAction returns GuardedAction:
	{GuardedAction}
	'GuardedAction'
	name=EString
	'(' (guardParameters+=GuardParameter (',' guardParameters+=GuardParameter)* )? ')'
	'{'
	( ('description' (descriptionFormat=TextFormat)? description=STRING)? &
	  ('annotations' '{' (annotations+=AnnotationEntry)*'}')?
	)
	'guard' '=' guardExpression=Expression
	'action' '{' (guardActions+=Action ';')* '}'
	'}';


GuardParameter returns GuardParameter:
	{GuardParameter}
	name=EString
	':' parameterType=[AssetType|QualifiedName] 
	;

Goal returns Goal:
	{Goal}
	'Goal'
	name=EString
	'{'
	( ('description' (descriptionFormat=TextFormat)? description=STRING)? &
	  ('annotations' '{' (annotations+=AnnotationEntry)*'}')?
	)
	('pre' '=' precondition=Expression)?
	('post' '=' postcondition=Expression)?
	'}';

AnnotationEntry returns AnnotationEntry:
	{AnnotationEntry}
	key=[AnnotationKey|EString] '=' value=STRING
;

Expression:
	ImpliesExpression;
	
ImpliesExpression returns Expression:
	OrExpression ({ImpliesExpression.lhs=current} "=>" rhs=OrExpression)*;
OrExpression returns Expression:
	AndExpression ({OrExpression.lhs=current} "||" rhs=AndExpression)*;
AndExpression returns Expression:
	NotExpression ({AndExpression.lhs=current} "&&" rhs=NotExpression)*;
NotExpression returns Expression:
	{NotExpression} "!" expression=NotExpression |
	ComparisonExpression;	
	
ComparisonExpression returns Expression:
	SelectionExpression (({EqualityComparisonExpression.lhs=current} op=("==" | "!=")
	rhs=SelectionExpression)* | ({InequalityComparisonExpression.lhs=current} op=("<" | "<=" | ">" | ">=")
	rhs=SelectionExpression))
;

SelectionExpression returns Expression:
	TerminalExpression	(
		{MemberSelection.receiver=current} '.' 
		member=[Member|QualifiedName]
		
		(methodInvocation?='(' 
			(args+=ExpressionOrLambdaExpression (',' args+=Expression)*)? ')'	)?
	
	)*
;

ExpressionOrLambdaExpression returns Expression:
	LambdaExpression | Expression
;
LambdaExpression returns Expression:
	{LambdaExpression}
	'{'
	lambdaParameter=LambdaParameter
	'->'
	body=Expression
	'}'
;

TerminalExpression returns Expression:
	 {IntConstant} value=INT |
	{StringConstant} value=STRING |
	{BooleanConstant} value=('true' | 'false') |
	{VersionConstant} value=Version |
	{SymbolRef} symbol=[Symbol|QualifiedName] |
	Collection |
	Undefined |
	'(' Expression ')'
	;
	
Collection returns Collection: 
	{Collection} '[' elements+=Expression? (',' elements+=Expression)* ']'
;


ActionSelectionExpression returns MemberSelection:
	{MemberSelection} receiver=TerminalExpression '.' 
		member=[Member|QualifiedName]
		
		(methodInvocation?='(' 
			(args+=ExpressionOrLambdaExpression (',' args+=Expression)*)? ')'	)?
	({MemberSelection.receiver=current} '.' 
		member=[Member|QualifiedName]
		
		(methodInvocation?='(' 
			(args+=ExpressionOrLambdaExpression (',' args+=Expression)*)? ')'	)?
	
	)*
;

Action returns Action:
	{Action}
	target=ActionSelectionExpression
	'.' actionType=ActionEnum
	'(' 
			((args+=Expression | lambdaAction=LambdaAction) (',' args+=Expression)*)? 
	')' 
; 

LambdaAction returns LambdaAction:
	{LambdaAction}
	'{'
	lambdaParameter=LambdaParameter
	'->'
	actions+=Action (';' actions+=Action)*
	'}'
;

Version returns EVersion:
	INT '.' INT '.' INT ('-' VID)? ('+' VID)?
;
VID:
	ID | INT
;

Undefined returns UndefinedConstant:
	{UndefinedConstant} 'undefined'
;

	
enum Severity returns Severity:
	ERROR='ERROR' | WARNING='WARNING'
;	

enum ActionEnum returns ActionEnum:
	assign='assign' | add='add' | addAll='addAll' | clear='clear' | remove='remove' | removeAll='removeAll' | forAll='forAll'
;

EString returns ecore::EString:
	STRING | ID;


Import returns Import:
	{Import}
	('with' importedNamespace=ImportedFQN ('from' importURI=STRING)? ';') |
	('import' importURI=STRING ';')
	;

QualifiedName: ID ('::' ID)*;
ImportedFQN: QualifiedName ('::''*')?;

LocaleGroup: 
	'Locale' '{'
		'locale' '=' locale=STRING
		objectLocales+=DefinitionGroupLocale*
	'}'
;

DefinitionGroupLocale: 
	'DefinitionGroup' ref=[DefinitionGroup|QualifiedName] '{'
		('annotations' '{' annotations+=AnnotationEntry* '}')?
		definitionLocales+=(DefinitionGroupLocale | AssetTypeLocale | AssetTypeAspectLocale | PrimitiveDataTypeLocale | GuardLocale | RequirementLocale)*
	'}'
;

AssetTypeLocale:
	{AssetTypeLocale} 'AssetType' ref=[AssetType|QualifiedName] '=' name=STRING '{'
	('description' '=' (descriptionFormat=TextFormat)? description=STRING)?
	features+=AssetTypeFeatureLocale*
	'}'
;

AssetTypeAspectLocale:
	{AssetTypeAspectLocale} 'AssetTypeAspect' baseAssetType=[AssetType|QualifiedName] '{'
	features+=AssetTypeFeatureLocale*
	'}'
;

AssetTypeFeatureLocale:
	{AssetTypeFeatureLocale} ('reference' ref=[AssetTypeReference|QualifiedName] | 'attribute' ref=[AssetTypeAttribute|QualifiedName]) '=' name=STRING
;

PrimitiveDataTypeLocale:
	{PrimitiveDataTypeLocale} 'PrimitiveDataType' ref=[EnumDataType|QualifiedName] '=' name=STRING '{'
	literals+=EnumLiteralLocale*
	'}'
;
EnumLiteralLocale:
	{EnumLiteralLocale} 'EnumLiteral' ref=[EnumLiteral|QualifiedName] '=' name=STRING
;
GuardLocale:
	{GuardLocale} 'Guard' ref=[Guard|QualifiedName] '=' name=STRING '{'
	('description' '=' (descriptionFormat=TextFormat)? description=STRING)?
	('annotations' '{' annotations+=AnnotationEntry* '}')?
	'}'
;

enum TextFormat returns TextFormat:
	plaintext | HTML='html' | Markdown='markdown'
;

Requirement returns Requirement:
	'Requirement' name=ID '{'
	('title' title=STRING)?
	('description' (descriptionFormat=TextFormat)? description=STRING)?
	('annotations' '{' annotations+=AnnotationEntry* '}')?
	('contracts' '(' contracts+=[Contract|QualifiedName] (',' contracts+=[Contract|QualifiedName])* ')')?
	'}'
;

RequirementLocale:
	{RequirementLocale} 'Requirement' ref=[Requirement|QualifiedName] '{'
	('title' '=' title=STRING)?
	('description' '=' (descriptionFormat=TextFormat)? description=STRING)?
	('annotations' '{' annotations+=AnnotationEntry* '}')?
	'}'
;