Пример #1
0
        public override string ToString()
        {
            GrammarAST decisionASTNode = probe.dfa.DecisionASTNode;

            line = decisionASTNode.Line;
            charPositionInLine = decisionASTNode.CharPositionInLine;
            string fileName = probe.dfa.nfa.grammar.FileName;

            if (fileName != null)
            {
                file = fileName;
            }

            StringTemplate st = GetMessageTemplate();
            // Now fill template with information about problemState
            var    labels = probe.GetSampleNonDeterministicInputSequence(problemState);
            string input  = probe.GetInputSequenceDisplay(labels);

            st.SetAttribute("input", input);

            if (probe.dfa.IsTokensRuleDecision)
            {
                var disabledAlts = probe.GetDisabledAlternatives(problemState);
                foreach (int altI in disabledAlts)
                {
                    string tokenName =
                        probe.GetTokenNameForTokensRuleAlt((int)altI);
                    // reset the line/col to the token definition (pick last one)
                    NFAState ruleStart =
                        probe.dfa.nfa.grammar.GetRuleStartState(tokenName);
                    line = ruleStart.associatedASTNode.Line;
                    charPositionInLine = ruleStart.associatedASTNode.CharPositionInLine;
                    st.SetAttribute("disabled", tokenName);
                }
            }
            else
            {
                st.SetAttribute("disabled", probe.GetDisabledAlternatives(problemState));
            }

            var      nondetAlts = probe.GetNonDeterministicAltsForState(problemState);
            NFAState nfaStart   = probe.dfa.NFADecisionStartState;
            // all state paths have to begin with same NFA state
            int firstAlt = 0;

            if (nondetAlts != null)
            {
                foreach (int displayAltI in nondetAlts)
                {
                    if (DecisionProbe.verbose)
                    {
                        int tracePathAlt =
                            nfaStart.TranslateDisplayAltToWalkAlt((int)displayAltI);
                        if (firstAlt == 0)
                        {
                            firstAlt = tracePathAlt;
                        }
                        IList path =
                            probe.GetNFAPathStatesForAlt(firstAlt,
                                                         tracePathAlt,
                                                         labels);
                        st.SetAttribute("paths.{alt,states}",
                                        displayAltI, path);
                    }
                    else
                    {
                        if (probe.dfa.IsTokensRuleDecision)
                        {
                            // alts are token rules, convert to the names instead of numbers
                            string tokenName =
                                probe.GetTokenNameForTokensRuleAlt((int)displayAltI);
                            st.SetAttribute("conflictingTokens", tokenName);
                        }
                        else
                        {
                            st.SetAttribute("conflictingAlts", displayAltI);
                        }
                    }
                }
            }
            st.SetAttribute("hasPredicateBlockedByAction", problemState.dfa.hasPredicateBlockedByAction);
            return(base.ToString(st));
        }