Пример #1
0
        void IncrGAnalysisListener.OnMatch(GAnlysInput nextInput, AfterMatchListener afterListener, AlternativeIncrGAnalyzer alternative)
        {
            List <IndexedAfterMatchListener> updatedMatches = new List <IndexedAfterMatchListener>(previoudMatches);

            updatedMatches.Add(new IndexedAfterMatchListener(nextIndex - 1, afterListener));
            if (nextIndex < analyzers.Count)
            {
                var recordingListener = new RecordingIncrGAnalysListener {
                    baseListener = new ChainListenerOld {
                        analyzers = analyzers, nextIndex = nextIndex + 1, rootListener = rootListener, previoudMatches = updatedMatches, afterListenerFactory = afterListenerFactory
                    }
                };
                analyzers[nextIndex].Analyze(nextInput, recordingListener);
                if (!recordingListener.didMatch && alternative != null)
                {
                    updatedMatches.RemoveAt(updatedMatches.Count - 1);
                    AlternativeIncrGAnalyzer currentAlternative = alternative;
                    var altListener = new ChainListenerOld {
                        analyzers = analyzers, nextIndex = nextIndex, rootListener = rootListener, previoudMatches = updatedMatches, afterListenerFactory = afterListenerFactory
                    };
                    alternative.AnalyzeAgain(altListener);
                }
            }
            else
            {
                //rootListener.OnMatch(nextInput, new ClusterAfterListener { afterListeners = updatedMatches });
                rootListener.OnMatch(nextInput, afterListenerFactory(updatedMatches), alternative);
            }
        }
Пример #2
0
 void IncrGAnalysisListener.OnMatch(GAnlysInput _nextInput, AfterMatchListener _listener, AlternativeIncrGAnalyzer _alternative)
 {
     didMatch    = true;
     nextInput   = _nextInput;
     listener    = _listener;
     alternative = _alternative;
 }
Пример #3
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);
             }
         }
     }
 }
Пример #4
0
 void IncrGAnalysisListener.OnMatch(GAnlysInput result, AfterMatchListener listener, AlternativeIncrGAnalyzer alternative)
 {
     didMatch = true;
     baseListener.OnMatch(result, listener, alternative);
 }
Пример #5
0
 void IncrGAnalysisListener.OnMatch(GAnlysInput nextInput, AfterMatchListener listener, AlternativeIncrGAnalyzer alternative)
 {
     didHit = true;
     if (alternative != null)
     {
         clientListner.OnMatch(nextInput, listener,
                               new UnitAltAnlys {
             parent = parent, nextIndex = nextAnalyzerIndex, subAltAnalyzer = alternative, originalInput = originalInput
         }
                               );
     }
     else
     {
         if (nextAnalyzerIndex < parent.candidates.Count)
         {
             clientListner.OnMatch(nextInput, listener, new UnitAltAnlys {
                 parent = parent, nextIndex = nextAnalyzerIndex, originalInput = originalInput
             });
         }
         else
         {
             clientListner.OnMatch(nextInput, listener);
         }
     }
 }
Пример #6
0
            void AlternativeIncrGAnalyzer.AnalyzeAgain(IncrGAnalysisListener listener)
            {
                Stack <EasyIncrGAnalysListener> resultArchives = new Stack <EasyIncrGAnalysListener>(givenResultArchive);
                EasyIncrGAnalysListener         lastLis        = null;

                while (true)
                {
                    if (resultArchives.Count <= 0)
                    {
                        return;
                    }
                    var analyzer = resultArchives.Pop();
                    if (analyzer.alternative == null)
                    {
                        continue;
                    }
                    var easyLis = new EasyIncrGAnalysListener();
                    analyzer.alternative.AnalyzeAgain(easyLis);
                    if (easyLis.didMatch)
                    {
                        resultArchives.Push(easyLis);
                        lastLis = easyLis;
                        break;
                    }
                }
                while (true)
                {
                    if (parent.conjectionAnalyzer != null)
                    {
                        var conjLis = new EasyIncrGAnalysListener {
                        };
                        parent.conjectionAnalyzer.Analyze(lastLis.nextInput, conjLis);
                        if (conjLis.didMatch)
                        {
                            lastLis = conjLis;
                        }
                        else if (!parent.isConjectionOptional)
                        {
                            return;
                        }
                    }
                    var easyLis = new EasyIncrGAnalysListener();
                    parent.baseAnalyzer.Analyze(lastLis.nextInput, easyLis);
                    if (!easyLis.didMatch)
                    {
                        if (resultArchives.Count == 0)
                        {
                            return;
                        }
                        else
                        {
                            break;
                        }
                    }
                    else
                    {
                        resultArchives.Push(easyLis);
                    }
                }
                List <AfterMatchListener> afLiss = new List <AfterMatchListener>();

                foreach (var result in resultArchives)
                {
                    afLiss.Add(result.listener);
                }
                bool hasAlt = false;

                foreach (var result in resultArchives)
                {
                    if (result.alternative != null)
                    {
                        hasAlt = true;
                    }
                }
                AlternativeIncrGAnalyzer altAnlys = null;

                if (hasAlt)
                {
                    altAnlys = new PrvtAltIGAnlys {
                        givenResultArchive = resultArchives, parent = parent
                    };
                }
                listener.OnMatch(resultArchives.Peek().nextInput, new PrvtLis {
                    listeners = afLiss
                }, altAnlys);
            }
Пример #7
0
        void IncrementalGAnalyzer.Analyze(GAnlysInput input, IncrGAnalysisListener listener)
        {
            Stack <EasyIncrGAnalysListener> resultArchives = new Stack <EasyIncrGAnalysListener>();

            while (true)
            {
                var currentInput = resultArchives.Count == 0 ? input : resultArchives.Peek().nextInput;
                if (resultArchives.Count > 0 && conjectionAnalyzer != null)
                {
                    var conjLis = new EasyIncrGAnalysListener();
                    conjectionAnalyzer.Analyze(currentInput, conjLis);
                    if (conjLis.didMatch)
                    {
                        currentInput = conjLis.nextInput;
                    }
                    if (!conjLis.didMatch && !isConjectionOptional)
                    {
                        break;
                    }
                }
                var easyLis = new EasyIncrGAnalysListener();
                baseAnalyzer.Analyze(currentInput, easyLis);
                if (!easyLis.didMatch)
                {
                    if (resultArchives.Count == 0)
                    {
                        return;
                    }
                    else
                    {
                        break;
                    }
                }
                else
                {
                    resultArchives.Push(easyLis);
                }
            }
            List <AfterMatchListener> afLiss = new List <AfterMatchListener>();

            foreach (var result in resultArchives)
            {
                afLiss.Add(result.listener);
            }
            bool hasAlt = false;

            foreach (var result in resultArchives)
            {
                if (result.alternative != null)
                {
                    hasAlt = true;
                }
            }
            AlternativeIncrGAnalyzer altLis = null;

            if (hasAlt)
            {
                altLis = new PrvtAltIGAnlys {
                    givenResultArchive = resultArchives, parent = this
                };
            }
            listener.OnMatch(resultArchives.Peek().nextInput, new PrvtLis {
                listeners = afLiss
            }, altLis);
        }
Пример #8
0
 void IncrGAnalysisListener.OnMatch(GAnlysInput _nextInput, AfterMatchListener listener, AlternativeIncrGAnalyzer alternative)
 {
     if (alternative != null)
     {
         baseListener.OnMatch(_nextInput, parent.ChangeAfterListener(listener), new ResultAltIncrGAnalyzer {
             baseAltAnalyzer = alternative, parent = parent
         });
     }
     else
     {
         baseListener.OnMatch(_nextInput, parent.ChangeAfterListener(listener));
     }
 }