예제 #1
0
 public void VisitExecute(AExpression expression)
 {
     // Use reflection to find and invoke the correct Visit method
     var types = new[] {expression.GetType()};
     MethodInfo methodInfo = GetType().GetMethod("VisitExecute", types);
     if (methodInfo != null)
     {
         methodInfo.Invoke(this, new object[] {expression});
     }
     else
     {
         throw new Exception("Visitor does not implement the Visit method for the type: " + expression.GetType());
     }
 }
예제 #2
0
        public void VisitEnter(AExpression expression)
        {
            // Use reflection to find and invoke the correct Visit method
            var        types      = new[] { expression.GetType() };
            MethodInfo methodInfo = GetType().GetMethod("VisitEnter", types);

            if (methodInfo != null)
            {
                methodInfo.Invoke(this, new object[] { expression });
            }
            else
            {
                throw new Exception("Visitor does not implement the Visit method for the type: " + expression.GetType());
            }
        }
예제 #3
0
		public AstNode Parse(IInputIterator inputIterator)
		{

			string grammar = @"
NewLine: [\r][\n] / [\n][\r] / [\n] / [\r];
Space: ' ';
Tab: [\t];
(?<EndOfLineComment>): (('#' / '//') (?<msg>(!NewLine .)*) NewLine) ;
(?<MultilineComment>):  ('/*' (?<msg>(!'*/' .)*) '*/');
s: ( Space / Tab / MultilineComment )+;
S: ( NewLine / EndOfLineComment )+;
S1: ( NewLine / EndOfLineComment );
W: (s / S);
(?<Table>):(?<Row>
  s* ('|' (?<DataColumn>  (! ('|' / S)  .)+ ))+ '|' S1  
)+;
(?<Gherkin>): (((?<Line> s* (?<Key> 'Given'\i / 'When'\i / 'Then'\i / 'And'\i / 'But'\i )  (?<Statement> (!S .)+ ) ) W*) / Table)+;
(?<TagLine>): (?<Tag>'@'  ((?<Name> (!(s* '@' / s* S) .)+ )) s*)+ W;
(?<FeatureLine>): 'Feature'\i	 s* ':' s* (?<Title> (!S .)+ ) W+ 
  (?<InOrder> s* &'In order to'\i (?<Text> (!S .)+ ) S1)?
  (?<AsAn> s* &'As an'\i (?<Text> (!S .)+ ) S1)?
  (?<IWantTo> s* &'I want to'\i (?<Text> (!S .)+ ) S1)?;
(?<Background>): 'Background'\i	 s* ':' W* Gherkin ;
(?<Scenario>): TagLine* 'Scenario'\i s* ':'  (?<Title> (!S .)+ ) W* Gherkin?;
(?<ScenarioOutline>): TagLine* 'Scenario'\i s 'Outline'\i s* ':'  (?<Title> (!S .)+ ) W* Gherkin? (?<Example> s* 'Examples:'\i S1 Table);
(?<Document>):  W* TagLine* FeatureLine Background? W* ((Scenario/ScenarioOutline) W*)+ ;
".Trim();

			lock (RuleInstanceLock)
			{
				if (RuleInstance == null)
				{
					RuleInstance = PEGrammar.Load(grammar);
				}
			}

			var visitor = new NpegParserVisitor(inputIterator);
			RuleInstance.Accept(visitor);

			if (visitor.IsMatch)
			{
				return visitor.AST;
			}

			throw new InvalidInputException();
		}
 public Sequence Sequence(AExpression other)
 {
     return(new Sequence(this, other));
 }
 public PrioritizedChoice Or(AExpression other)
 {
     return(new PrioritizedChoice(this, other));
 }
예제 #6
0
 public Sequence Sequence(AExpression other)
 {
     return new Sequence(this, other);
 }
예제 #7
0
 public PrioritizedChoice Or(AExpression other)
 {
     return new PrioritizedChoice(this, other);
 }