Esempio n. 1
0
 void IncrGAnalysisListener.OnMatch(GAnlysInput nextInput, AfterMatchListener afterListener, AlternativeIncrGAnalyzer alternative)
 {
     results.Add(new IndexAndResult {
         index  = index,
         result = new EasyIncrGAnalysListener {
             alternative = alternative, didMatch = true, listener = afterListener, nextInput = nextInput
         }
     });
     //last analyzer
     if (index == analyzers.Count - 1)
     {
         didFinalMatch = true;
         finalListener.OnMatch(nextInput, afterListenerFactory(new List <IndexAndResult>(results)), new PrvtAltAnlys {
             results = new List <IndexAndResult>(results), afterListenerFactory = afterListenerFactory, analyzers = analyzers
         });
     }
     //go to next analyzer
     else
     {
         var nextLis = new ChainListener {
             afterListenerFactory = afterListenerFactory, analyzers = analyzers, finalListener = finalListener, index = index + 1, results = results
         };
         analyzers[index + 1].Analyze(nextInput, nextLis);
         didFinalMatch = nextLis.didFinalMatch;
         if (!nextLis.didFinalMatch)
         {
             bool hasAlternative = false;
             foreach (var result in results)
             {
                 if (result.result.alternative != null)
                 {
                     hasAlternative = true;
                     break;
                 }
             }
             if (hasAlternative)
             {
                 AlternativeIncrGAnalyzer alt = new PrvtAltAnlys {
                     afterListenerFactory = afterListenerFactory, analyzers = analyzers, results = new List <IndexAndResult>(results)
                 };
                 alt.AnalyzeAgain(finalListener);
             }
         }
     }
 }
Esempio n. 2
0
            void AlternativeIncrGAnalyzer.AnalyzeAgain(IncrGAnalysisListener listener)
            {
                var newResults = new List <IndexAndResult>(results);

                while (newResults.Count > 0)
                {
                    var lastResult = newResults[newResults.Count - 1];
                    newResults.RemoveAt(newResults.Count - 1);
                    var altLis = new ChainListener {
                        finalListener        = listener,
                        index                = lastResult.index,
                        analyzers            = analyzers,
                        afterListenerFactory = afterListenerFactory,
                        results              = newResults
                    };
                    lastResult.result.alternative?.AnalyzeAgain(altLis);
                    if (altLis.didFinalMatch)
                    {
                        return;
                    }
                }
            }