grammar com.irtsaintexupery.xtext.pseim.Pattern with org.eclipse.xtext.common.Terminals

import "http://www.eclipse.org/emf/2002/Ecore" as ecore
import "http://www.irt-saintexupery.com/seim/0.1" as seim
import "http://www.irt-saintexupery.com/pseim/0.1"

Pattern returns Pattern:
	'pattern' name=ID '(' (cardinalityElements+=CardinalityElement (',' cardinalityElements+=CardinalityElement)*)? ')' 
	('{'
		(
			modelElements+=PatternComponent |
			modelElements+=PatternLink
		)*
	'}')?;

PatternComponent returns PatternComponent:
	'component' name=ID ('[' (multiplicityValue=INT | cardinalityElement=[CardinalityElement]) ']')? '(' (content+=PatternPort (',' content+=PatternPort)*)? ')' 
	('{'
		(
			content+=PatternComponent |
			content+=PatternLink
		)*
	'}')?;

PatternPort returns PatternPort:
	dir=PatternPortDirection name=ID ('[' (multiplicityValue=INT | cardinalityElement=[CardinalityElement]) ']')?
	;

enum PatternPortDirection returns PatternPortDirection:
				UNSPECIFIED = 'unspec' | IN = 'in' | OUT = 'out' | INOUT = 'inout';
				
CardinalityElement returns CardinalityElement:
	name=ID	
;

PatternLink returns PatternLink:
	src=[PatternPort|QualifiedID] '-{' linkType=LinkType '}->' dst=[PatternPort|QualifiedID]
	;
	
enum LinkType returns LinkType:
	TRANSPOSE = 'Transpose' | IDENTITY = 'Identity' | FIRST = 'First' | ROTATE = 'Rotate' 
	| SHIFTC = 'ShiftC' | SHIFTP = 'ShiftP' | FLATTENC = 'FlattenC' | FORKC = 'ForkC' | FORKP = 'ForkP'
	| JOINC = 'JoinC' | JOINP = 'JoinP' | LAST = 'Last'  
;

enum PortDirection returns seim::PortDirection:
	UNSPECIFIED = 'unspec' | IN = 'in' | OUT = 'out' | INOUT = 'inout'
;

QualifiedID:
	ID('.'ID)*	
;