/*
 * generated by Xtext 2.12.0
 */
grammar InternalPattern;

options {
	superClass=AbstractInternalAntlrParser;
}

@lexer::header {
package com.irtsaintexupery.xtext.pseim.parser.antlr.internal;

// Hack: Use our own Lexer superclass by means of import. 
// Currently there is no other way to specify the superclass for the lexer.
import org.eclipse.xtext.parser.antlr.Lexer;
}

@parser::header {
package com.irtsaintexupery.xtext.pseim.parser.antlr.internal;

import org.eclipse.xtext.*;
import org.eclipse.xtext.parser.*;
import org.eclipse.xtext.parser.impl.*;
import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.common.util.Enumerator;
import org.eclipse.xtext.parser.antlr.AbstractInternalAntlrParser;
import org.eclipse.xtext.parser.antlr.XtextTokenStream;
import org.eclipse.xtext.parser.antlr.XtextTokenStream.HiddenTokens;
import org.eclipse.xtext.parser.antlr.AntlrDatatypeRuleToken;
import com.irtsaintexupery.xtext.pseim.services.PatternGrammarAccess;

}

@parser::members {

 	private PatternGrammarAccess grammarAccess;

    public InternalPatternParser(TokenStream input, PatternGrammarAccess grammarAccess) {
        this(input);
        this.grammarAccess = grammarAccess;
        registerRules(grammarAccess.getGrammar());
    }

    @Override
    protected String getFirstRuleName() {
    	return "Pattern";
   	}

   	@Override
   	protected PatternGrammarAccess getGrammarAccess() {
   		return grammarAccess;
   	}

}

@rulecatch {
    catch (RecognitionException re) {
        recover(input,re);
        appendSkippedTokens();
    }
}

// Entry rule entryRulePattern
entryRulePattern returns [EObject current=null]:
	{ newCompositeNode(grammarAccess.getPatternRule()); }
	iv_rulePattern=rulePattern
	{ $current=$iv_rulePattern.current; }
	EOF;

// Rule Pattern
rulePattern returns [EObject current=null]
@init {
	enterRule();
}
@after {
	leaveRule();
}:
	(
		otherlv_0='pattern'
		{
			newLeafNode(otherlv_0, grammarAccess.getPatternAccess().getPatternKeyword_0());
		}
		(
			(
				lv_name_1_0=RULE_ID
				{
					newLeafNode(lv_name_1_0, grammarAccess.getPatternAccess().getNameIDTerminalRuleCall_1_0());
				}
				{
					if ($current==null) {
						$current = createModelElement(grammarAccess.getPatternRule());
					}
					setWithLastConsumed(
						$current,
						"name",
						lv_name_1_0,
						"org.eclipse.xtext.common.Terminals.ID");
				}
			)
		)
		otherlv_2='('
		{
			newLeafNode(otherlv_2, grammarAccess.getPatternAccess().getLeftParenthesisKeyword_2());
		}
		(
			(
				(
					{
						newCompositeNode(grammarAccess.getPatternAccess().getCardinalityElementsCardinalityElementParserRuleCall_3_0_0());
					}
					lv_cardinalityElements_3_0=ruleCardinalityElement
					{
						if ($current==null) {
							$current = createModelElementForParent(grammarAccess.getPatternRule());
						}
						add(
							$current,
							"cardinalityElements",
							lv_cardinalityElements_3_0,
							"com.irtsaintexupery.xtext.pseim.Pattern.CardinalityElement");
						afterParserOrEnumRuleCall();
					}
				)
			)
			(
				otherlv_4=','
				{
					newLeafNode(otherlv_4, grammarAccess.getPatternAccess().getCommaKeyword_3_1_0());
				}
				(
					(
						{
							newCompositeNode(grammarAccess.getPatternAccess().getCardinalityElementsCardinalityElementParserRuleCall_3_1_1_0());
						}
						lv_cardinalityElements_5_0=ruleCardinalityElement
						{
							if ($current==null) {
								$current = createModelElementForParent(grammarAccess.getPatternRule());
							}
							add(
								$current,
								"cardinalityElements",
								lv_cardinalityElements_5_0,
								"com.irtsaintexupery.xtext.pseim.Pattern.CardinalityElement");
							afterParserOrEnumRuleCall();
						}
					)
				)
			)*
		)?
		otherlv_6=')'
		{
			newLeafNode(otherlv_6, grammarAccess.getPatternAccess().getRightParenthesisKeyword_4());
		}
		(
			otherlv_7='{'
			{
				newLeafNode(otherlv_7, grammarAccess.getPatternAccess().getLeftCurlyBracketKeyword_5_0());
			}
			(
				(
					(
						{
							newCompositeNode(grammarAccess.getPatternAccess().getModelElementsPatternComponentParserRuleCall_5_1_0_0());
						}
						lv_modelElements_8_0=rulePatternComponent
						{
							if ($current==null) {
								$current = createModelElementForParent(grammarAccess.getPatternRule());
							}
							add(
								$current,
								"modelElements",
								lv_modelElements_8_0,
								"com.irtsaintexupery.xtext.pseim.Pattern.PatternComponent");
							afterParserOrEnumRuleCall();
						}
					)
				)
				    |
				(
					(
						{
							newCompositeNode(grammarAccess.getPatternAccess().getModelElementsPatternLinkParserRuleCall_5_1_1_0());
						}
						lv_modelElements_9_0=rulePatternLink
						{
							if ($current==null) {
								$current = createModelElementForParent(grammarAccess.getPatternRule());
							}
							add(
								$current,
								"modelElements",
								lv_modelElements_9_0,
								"com.irtsaintexupery.xtext.pseim.Pattern.PatternLink");
							afterParserOrEnumRuleCall();
						}
					)
				)
			)*
			otherlv_10='}'
			{
				newLeafNode(otherlv_10, grammarAccess.getPatternAccess().getRightCurlyBracketKeyword_5_2());
			}
		)?
	)
;

// Entry rule entryRulePatternComponent
entryRulePatternComponent returns [EObject current=null]:
	{ newCompositeNode(grammarAccess.getPatternComponentRule()); }
	iv_rulePatternComponent=rulePatternComponent
	{ $current=$iv_rulePatternComponent.current; }
	EOF;

// Rule PatternComponent
rulePatternComponent returns [EObject current=null]
@init {
	enterRule();
}
@after {
	leaveRule();
}:
	(
		otherlv_0='component'
		{
			newLeafNode(otherlv_0, grammarAccess.getPatternComponentAccess().getComponentKeyword_0());
		}
		(
			(
				lv_name_1_0=RULE_ID
				{
					newLeafNode(lv_name_1_0, grammarAccess.getPatternComponentAccess().getNameIDTerminalRuleCall_1_0());
				}
				{
					if ($current==null) {
						$current = createModelElement(grammarAccess.getPatternComponentRule());
					}
					setWithLastConsumed(
						$current,
						"name",
						lv_name_1_0,
						"org.eclipse.xtext.common.Terminals.ID");
				}
			)
		)
		(
			otherlv_2='['
			{
				newLeafNode(otherlv_2, grammarAccess.getPatternComponentAccess().getLeftSquareBracketKeyword_2_0());
			}
			(
				(
					(
						lv_multiplicityValue_3_0=RULE_INT
						{
							newLeafNode(lv_multiplicityValue_3_0, grammarAccess.getPatternComponentAccess().getMultiplicityValueINTTerminalRuleCall_2_1_0_0());
						}
						{
							if ($current==null) {
								$current = createModelElement(grammarAccess.getPatternComponentRule());
							}
							setWithLastConsumed(
								$current,
								"multiplicityValue",
								lv_multiplicityValue_3_0,
								"org.eclipse.xtext.common.Terminals.INT");
						}
					)
				)
				    |
				(
					(
						{
							if ($current==null) {
								$current = createModelElement(grammarAccess.getPatternComponentRule());
							}
						}
						otherlv_4=RULE_ID
						{
							newLeafNode(otherlv_4, grammarAccess.getPatternComponentAccess().getCardinalityElementCardinalityElementCrossReference_2_1_1_0());
						}
					)
				)
			)
			otherlv_5=']'
			{
				newLeafNode(otherlv_5, grammarAccess.getPatternComponentAccess().getRightSquareBracketKeyword_2_2());
			}
		)?
		otherlv_6='('
		{
			newLeafNode(otherlv_6, grammarAccess.getPatternComponentAccess().getLeftParenthesisKeyword_3());
		}
		(
			(
				(
					{
						newCompositeNode(grammarAccess.getPatternComponentAccess().getContentPatternPortParserRuleCall_4_0_0());
					}
					lv_content_7_0=rulePatternPort
					{
						if ($current==null) {
							$current = createModelElementForParent(grammarAccess.getPatternComponentRule());
						}
						add(
							$current,
							"content",
							lv_content_7_0,
							"com.irtsaintexupery.xtext.pseim.Pattern.PatternPort");
						afterParserOrEnumRuleCall();
					}
				)
			)
			(
				otherlv_8=','
				{
					newLeafNode(otherlv_8, grammarAccess.getPatternComponentAccess().getCommaKeyword_4_1_0());
				}
				(
					(
						{
							newCompositeNode(grammarAccess.getPatternComponentAccess().getContentPatternPortParserRuleCall_4_1_1_0());
						}
						lv_content_9_0=rulePatternPort
						{
							if ($current==null) {
								$current = createModelElementForParent(grammarAccess.getPatternComponentRule());
							}
							add(
								$current,
								"content",
								lv_content_9_0,
								"com.irtsaintexupery.xtext.pseim.Pattern.PatternPort");
							afterParserOrEnumRuleCall();
						}
					)
				)
			)*
		)?
		otherlv_10=')'
		{
			newLeafNode(otherlv_10, grammarAccess.getPatternComponentAccess().getRightParenthesisKeyword_5());
		}
		(
			otherlv_11='{'
			{
				newLeafNode(otherlv_11, grammarAccess.getPatternComponentAccess().getLeftCurlyBracketKeyword_6_0());
			}
			(
				(
					(
						{
							newCompositeNode(grammarAccess.getPatternComponentAccess().getContentPatternComponentParserRuleCall_6_1_0_0());
						}
						lv_content_12_0=rulePatternComponent
						{
							if ($current==null) {
								$current = createModelElementForParent(grammarAccess.getPatternComponentRule());
							}
							add(
								$current,
								"content",
								lv_content_12_0,
								"com.irtsaintexupery.xtext.pseim.Pattern.PatternComponent");
							afterParserOrEnumRuleCall();
						}
					)
				)
				    |
				(
					(
						{
							newCompositeNode(grammarAccess.getPatternComponentAccess().getContentPatternLinkParserRuleCall_6_1_1_0());
						}
						lv_content_13_0=rulePatternLink
						{
							if ($current==null) {
								$current = createModelElementForParent(grammarAccess.getPatternComponentRule());
							}
							add(
								$current,
								"content",
								lv_content_13_0,
								"com.irtsaintexupery.xtext.pseim.Pattern.PatternLink");
							afterParserOrEnumRuleCall();
						}
					)
				)
			)*
			otherlv_14='}'
			{
				newLeafNode(otherlv_14, grammarAccess.getPatternComponentAccess().getRightCurlyBracketKeyword_6_2());
			}
		)?
	)
;

// Entry rule entryRulePatternPort
entryRulePatternPort returns [EObject current=null]:
	{ newCompositeNode(grammarAccess.getPatternPortRule()); }
	iv_rulePatternPort=rulePatternPort
	{ $current=$iv_rulePatternPort.current; }
	EOF;

// Rule PatternPort
rulePatternPort returns [EObject current=null]
@init {
	enterRule();
}
@after {
	leaveRule();
}:
	(
		(
			(
				{
					newCompositeNode(grammarAccess.getPatternPortAccess().getDirPatternPortDirectionEnumRuleCall_0_0());
				}
				lv_dir_0_0=rulePatternPortDirection
				{
					if ($current==null) {
						$current = createModelElementForParent(grammarAccess.getPatternPortRule());
					}
					set(
						$current,
						"dir",
						lv_dir_0_0,
						"com.irtsaintexupery.xtext.pseim.Pattern.PatternPortDirection");
					afterParserOrEnumRuleCall();
				}
			)
		)
		(
			(
				lv_name_1_0=RULE_ID
				{
					newLeafNode(lv_name_1_0, grammarAccess.getPatternPortAccess().getNameIDTerminalRuleCall_1_0());
				}
				{
					if ($current==null) {
						$current = createModelElement(grammarAccess.getPatternPortRule());
					}
					setWithLastConsumed(
						$current,
						"name",
						lv_name_1_0,
						"org.eclipse.xtext.common.Terminals.ID");
				}
			)
		)
		(
			otherlv_2='['
			{
				newLeafNode(otherlv_2, grammarAccess.getPatternPortAccess().getLeftSquareBracketKeyword_2_0());
			}
			(
				(
					(
						lv_multiplicityValue_3_0=RULE_INT
						{
							newLeafNode(lv_multiplicityValue_3_0, grammarAccess.getPatternPortAccess().getMultiplicityValueINTTerminalRuleCall_2_1_0_0());
						}
						{
							if ($current==null) {
								$current = createModelElement(grammarAccess.getPatternPortRule());
							}
							setWithLastConsumed(
								$current,
								"multiplicityValue",
								lv_multiplicityValue_3_0,
								"org.eclipse.xtext.common.Terminals.INT");
						}
					)
				)
				    |
				(
					(
						{
							if ($current==null) {
								$current = createModelElement(grammarAccess.getPatternPortRule());
							}
						}
						otherlv_4=RULE_ID
						{
							newLeafNode(otherlv_4, grammarAccess.getPatternPortAccess().getCardinalityElementCardinalityElementCrossReference_2_1_1_0());
						}
					)
				)
			)
			otherlv_5=']'
			{
				newLeafNode(otherlv_5, grammarAccess.getPatternPortAccess().getRightSquareBracketKeyword_2_2());
			}
		)?
	)
;

// Entry rule entryRuleCardinalityElement
entryRuleCardinalityElement returns [EObject current=null]:
	{ newCompositeNode(grammarAccess.getCardinalityElementRule()); }
	iv_ruleCardinalityElement=ruleCardinalityElement
	{ $current=$iv_ruleCardinalityElement.current; }
	EOF;

// Rule CardinalityElement
ruleCardinalityElement returns [EObject current=null]
@init {
	enterRule();
}
@after {
	leaveRule();
}:
	(
		(
			lv_name_0_0=RULE_ID
			{
				newLeafNode(lv_name_0_0, grammarAccess.getCardinalityElementAccess().getNameIDTerminalRuleCall_0());
			}
			{
				if ($current==null) {
					$current = createModelElement(grammarAccess.getCardinalityElementRule());
				}
				setWithLastConsumed(
					$current,
					"name",
					lv_name_0_0,
					"org.eclipse.xtext.common.Terminals.ID");
			}
		)
	)
;

// Entry rule entryRulePatternLink
entryRulePatternLink returns [EObject current=null]:
	{ newCompositeNode(grammarAccess.getPatternLinkRule()); }
	iv_rulePatternLink=rulePatternLink
	{ $current=$iv_rulePatternLink.current; }
	EOF;

// Rule PatternLink
rulePatternLink returns [EObject current=null]
@init {
	enterRule();
}
@after {
	leaveRule();
}:
	(
		(
			(
				{
					if ($current==null) {
						$current = createModelElement(grammarAccess.getPatternLinkRule());
					}
				}
				{
					newCompositeNode(grammarAccess.getPatternLinkAccess().getSrcPatternPortCrossReference_0_0());
				}
				ruleQualifiedID
				{
					afterParserOrEnumRuleCall();
				}
			)
		)
		otherlv_1='-{'
		{
			newLeafNode(otherlv_1, grammarAccess.getPatternLinkAccess().getHyphenMinusLeftCurlyBracketKeyword_1());
		}
		(
			(
				{
					newCompositeNode(grammarAccess.getPatternLinkAccess().getLinkTypeLinkTypeEnumRuleCall_2_0());
				}
				lv_linkType_2_0=ruleLinkType
				{
					if ($current==null) {
						$current = createModelElementForParent(grammarAccess.getPatternLinkRule());
					}
					set(
						$current,
						"linkType",
						lv_linkType_2_0,
						"com.irtsaintexupery.xtext.pseim.Pattern.LinkType");
					afterParserOrEnumRuleCall();
				}
			)
		)
		otherlv_3='}->'
		{
			newLeafNode(otherlv_3, grammarAccess.getPatternLinkAccess().getRightCurlyBracketHyphenMinusGreaterThanSignKeyword_3());
		}
		(
			(
				{
					if ($current==null) {
						$current = createModelElement(grammarAccess.getPatternLinkRule());
					}
				}
				{
					newCompositeNode(grammarAccess.getPatternLinkAccess().getDstPatternPortCrossReference_4_0());
				}
				ruleQualifiedID
				{
					afterParserOrEnumRuleCall();
				}
			)
		)
	)
;

// Entry rule entryRuleQualifiedID
entryRuleQualifiedID returns [String current=null]:
	{ newCompositeNode(grammarAccess.getQualifiedIDRule()); }
	iv_ruleQualifiedID=ruleQualifiedID
	{ $current=$iv_ruleQualifiedID.current.getText(); }
	EOF;

// Rule QualifiedID
ruleQualifiedID returns [AntlrDatatypeRuleToken current=new AntlrDatatypeRuleToken()]
@init {
	enterRule();
}
@after {
	leaveRule();
}:
	(
		this_ID_0=RULE_ID
		{
			$current.merge(this_ID_0);
		}
		{
			newLeafNode(this_ID_0, grammarAccess.getQualifiedIDAccess().getIDTerminalRuleCall_0());
		}
		(
			kw='.'
			{
				$current.merge(kw);
				newLeafNode(kw, grammarAccess.getQualifiedIDAccess().getFullStopKeyword_1_0());
			}
			this_ID_2=RULE_ID
			{
				$current.merge(this_ID_2);
			}
			{
				newLeafNode(this_ID_2, grammarAccess.getQualifiedIDAccess().getIDTerminalRuleCall_1_1());
			}
		)*
	)
;

// Rule PatternPortDirection
rulePatternPortDirection returns [Enumerator current=null]
@init {
	enterRule();
}
@after {
	leaveRule();
}:
	(
		(
			enumLiteral_0='unspec'
			{
				$current = grammarAccess.getPatternPortDirectionAccess().getUNSPECIFIEDEnumLiteralDeclaration_0().getEnumLiteral().getInstance();
				newLeafNode(enumLiteral_0, grammarAccess.getPatternPortDirectionAccess().getUNSPECIFIEDEnumLiteralDeclaration_0());
			}
		)
		    |
		(
			enumLiteral_1='in'
			{
				$current = grammarAccess.getPatternPortDirectionAccess().getINEnumLiteralDeclaration_1().getEnumLiteral().getInstance();
				newLeafNode(enumLiteral_1, grammarAccess.getPatternPortDirectionAccess().getINEnumLiteralDeclaration_1());
			}
		)
		    |
		(
			enumLiteral_2='out'
			{
				$current = grammarAccess.getPatternPortDirectionAccess().getOUTEnumLiteralDeclaration_2().getEnumLiteral().getInstance();
				newLeafNode(enumLiteral_2, grammarAccess.getPatternPortDirectionAccess().getOUTEnumLiteralDeclaration_2());
			}
		)
		    |
		(
			enumLiteral_3='inout'
			{
				$current = grammarAccess.getPatternPortDirectionAccess().getINOUTEnumLiteralDeclaration_3().getEnumLiteral().getInstance();
				newLeafNode(enumLiteral_3, grammarAccess.getPatternPortDirectionAccess().getINOUTEnumLiteralDeclaration_3());
			}
		)
	)
;

// Rule LinkType
ruleLinkType returns [Enumerator current=null]
@init {
	enterRule();
}
@after {
	leaveRule();
}:
	(
		(
			enumLiteral_0='Transpose'
			{
				$current = grammarAccess.getLinkTypeAccess().getTRANSPOSEEnumLiteralDeclaration_0().getEnumLiteral().getInstance();
				newLeafNode(enumLiteral_0, grammarAccess.getLinkTypeAccess().getTRANSPOSEEnumLiteralDeclaration_0());
			}
		)
		    |
		(
			enumLiteral_1='Identity'
			{
				$current = grammarAccess.getLinkTypeAccess().getIDENTITYEnumLiteralDeclaration_1().getEnumLiteral().getInstance();
				newLeafNode(enumLiteral_1, grammarAccess.getLinkTypeAccess().getIDENTITYEnumLiteralDeclaration_1());
			}
		)
		    |
		(
			enumLiteral_2='First'
			{
				$current = grammarAccess.getLinkTypeAccess().getFIRSTEnumLiteralDeclaration_2().getEnumLiteral().getInstance();
				newLeafNode(enumLiteral_2, grammarAccess.getLinkTypeAccess().getFIRSTEnumLiteralDeclaration_2());
			}
		)
		    |
		(
			enumLiteral_3='Rotate'
			{
				$current = grammarAccess.getLinkTypeAccess().getROTATEEnumLiteralDeclaration_3().getEnumLiteral().getInstance();
				newLeafNode(enumLiteral_3, grammarAccess.getLinkTypeAccess().getROTATEEnumLiteralDeclaration_3());
			}
		)
		    |
		(
			enumLiteral_4='ShiftC'
			{
				$current = grammarAccess.getLinkTypeAccess().getSHIFTCEnumLiteralDeclaration_4().getEnumLiteral().getInstance();
				newLeafNode(enumLiteral_4, grammarAccess.getLinkTypeAccess().getSHIFTCEnumLiteralDeclaration_4());
			}
		)
		    |
		(
			enumLiteral_5='ShiftP'
			{
				$current = grammarAccess.getLinkTypeAccess().getSHIFTPEnumLiteralDeclaration_5().getEnumLiteral().getInstance();
				newLeafNode(enumLiteral_5, grammarAccess.getLinkTypeAccess().getSHIFTPEnumLiteralDeclaration_5());
			}
		)
		    |
		(
			enumLiteral_6='FlattenC'
			{
				$current = grammarAccess.getLinkTypeAccess().getFLATTENCEnumLiteralDeclaration_6().getEnumLiteral().getInstance();
				newLeafNode(enumLiteral_6, grammarAccess.getLinkTypeAccess().getFLATTENCEnumLiteralDeclaration_6());
			}
		)
		    |
		(
			enumLiteral_7='ForkC'
			{
				$current = grammarAccess.getLinkTypeAccess().getFORKCEnumLiteralDeclaration_7().getEnumLiteral().getInstance();
				newLeafNode(enumLiteral_7, grammarAccess.getLinkTypeAccess().getFORKCEnumLiteralDeclaration_7());
			}
		)
		    |
		(
			enumLiteral_8='ForkP'
			{
				$current = grammarAccess.getLinkTypeAccess().getFORKPEnumLiteralDeclaration_8().getEnumLiteral().getInstance();
				newLeafNode(enumLiteral_8, grammarAccess.getLinkTypeAccess().getFORKPEnumLiteralDeclaration_8());
			}
		)
		    |
		(
			enumLiteral_9='JoinC'
			{
				$current = grammarAccess.getLinkTypeAccess().getJOINCEnumLiteralDeclaration_9().getEnumLiteral().getInstance();
				newLeafNode(enumLiteral_9, grammarAccess.getLinkTypeAccess().getJOINCEnumLiteralDeclaration_9());
			}
		)
		    |
		(
			enumLiteral_10='JoinP'
			{
				$current = grammarAccess.getLinkTypeAccess().getJOINPEnumLiteralDeclaration_10().getEnumLiteral().getInstance();
				newLeafNode(enumLiteral_10, grammarAccess.getLinkTypeAccess().getJOINPEnumLiteralDeclaration_10());
			}
		)
		    |
		(
			enumLiteral_11='Last'
			{
				$current = grammarAccess.getLinkTypeAccess().getLASTEnumLiteralDeclaration_11().getEnumLiteral().getInstance();
				newLeafNode(enumLiteral_11, grammarAccess.getLinkTypeAccess().getLASTEnumLiteralDeclaration_11());
			}
		)
	)
;

RULE_ID : '^'? ('a'..'z'|'A'..'Z'|'_') ('a'..'z'|'A'..'Z'|'_'|'0'..'9')*;

RULE_INT : ('0'..'9')+;

RULE_STRING : ('"' ('\\' .|~(('\\'|'"')))* '"'|'\'' ('\\' .|~(('\\'|'\'')))* '\'');

RULE_ML_COMMENT : '/*' ( options {greedy=false;} : . )*'*/';

RULE_SL_COMMENT : '//' ~(('\n'|'\r'))* ('\r'? '\n')?;

RULE_WS : (' '|'\t'|'\r'|'\n')+;

RULE_ANY_OTHER : .;
