Exemplo n.º 1
0
        private void CompleteCorrectedInput(ParserCorrectionModel model)
        {
            int i   = model.GetRequiredInputSize() + VerificationLength;
            int end = failedInput.Count;

            for (; i < end; ++i)
            {
                correction.Add(failedInput[i]);
            }
        }
Exemplo n.º 2
0
        private void CompleteCorrectionWithVerificationSuffix(ParserCorrectionModel model)
        {
            int i   = model.GetRequiredInputSize();
            int end = i + VerificationLength;

            for (; i != end; ++i)
            {
                if (i >= failedInput.Count)
                {
                    break;
                }

                correction.Add(failedInput[i]);
            }
        }
Exemplo n.º 3
0
        private bool Match(int start, ParserCorrectionModel m)
        {
            if (start == m.Count)
            {
                return(ValidateCorrection());
            }

            foreach (var candidate in Following(m, start))
            {
                correction[start] = candidate;
                if (Match(start + 1, m))
                {
                    return(true);
                }
            }

            return(false);
        }
Exemplo n.º 4
0
        private IEnumerable <Msg> Following(ParserCorrectionModel m, int k)
        {
            Debug.Assert(k != m.Count);

            if (m[k] == Insertion)
            {
                if (!useViolatingRules)
                {
                    foreach (int term in terms)
                    {
                        var categories = grammar.GetTokenCategories(term);
                        if ((categories & SymbolCategory.DoNotInsert) == 0)
                        {
                            yield return(new Msg(term, null, Loc.Unknown)); // TODO: Location and value
                        }
                    }
                }
                else
                {
                    foreach (int term in terms)
                    {
                        var categories = grammar.GetTokenCategories(term);
                        if ((categories & SymbolCategory.DoNotInsert) != 0)
                        {
                            yield return(new Msg(term, null, Loc.Unknown)); // TODO: Location and value
                        }
                    }
                }
            }
            else if (m[k] == Spelling)
            {
                throw new NotImplementedException();
            }
            else
            {
                yield return(failedInput[m[k]]);
            }
        }
Exemplo n.º 5
0
        private bool FindCorrection()
        {
            foreach (var model in CorrectionModels)
            {
                if (failedInput.Count < model.GetRequiredInputSize())
                {
                    continue;
                }

                var  deletedTokens      = model.GetDeletedIndexes().Select(i => failedInput[i].Id);
                bool violatesDontDelete = deletedTokens.Any(grammar.IsDontDelete);
                if (!useViolatingRules && violatesDontDelete)
                {
                    continue;
                }
                if (useViolatingRules && !violatesDontDelete)
                {
                    continue;
                }

                correction.Clear();
                int count = model.Count;
                for (int i = 0; i != count; ++i)
                {
                    if (model[i] == Insertion)
                    {
                        correction.Add(default(Msg));
                    }
                    else if (model[i] == Spelling)
                    {
                        throw new NotImplementedException();
                    }
                    else if (model[i] < failedInput.Count)
                    {
                        correction.Add(failedInput[model[i]]);
                    }
                    else
                    {
                        break;
                    }
                }

                // Complete correction with the correction-verifiction suffix
                CompleteCorrectionWithVerificationSuffix(model);

                this.currentModel = model;

                if (Match(0, model))
                {
                    // Complete correction with remaining collected failedInput
                    CompleteCorrectedInput(model);

                    logging.Write(
                        new LogEntry
                    {
                        Severity  = Severity.Error,
                        Location  = model.GetHiglightLocation(failedInput),
                        HLocation = model.GetHiglightHLocation(failedInput),
                        Message   = model.FormatMessage(grammar, failedInput, correction)
                    });
                    return(true);
                }
            }

            correction.Clear();
            return(false);
        }