Ejemplo n.º 1
0
        /** Use reflection to find list of MSG_ fields and then verify a
         *  template exists for each one from the locale's group.
         */
        static bool VerifyMessages()
        {
            bool ok = true;

            FieldInfo[] fields = typeof(ErrorManager).GetFields();
            for (int i = 0; i < fields.Length; i++)
            {
                FieldInfo f            = fields[i];
                String    fieldName    = f.Name;
                String    templateName =
                    fieldName.Substring("MSG_".Length);
                if (fieldName.StartsWith("MSG_"))
                {
                    if (!messages.IsDefined(templateName))
                    {
                        Console.Out.WriteLine("Message " + templateName + " in locale " +
                                              locale + " not found");
                        ok = false;
                    }
                }
            }
            // check for special templates
            if (!messages.IsDefined("warning"))
            {
                Console.Error.WriteLine("Message template 'warning' not found in locale " + locale);
                ok = false;
            }
            if (!messages.IsDefined("error"))
            {
                Console.Error.WriteLine("Message template 'error' not found in locale " + locale);
                ok = false;
            }
            return(ok);
        }
Ejemplo n.º 2
0
        /** Verify the message format template group */
        static bool VerifyFormat()
        {
            bool ok = true;

            if (!format.IsDefined("location"))
            {
                Console.Error.WriteLine("Format template 'location' not found in " + formatName);
                ok = false;
            }
            if (!format.IsDefined("message"))
            {
                Console.Error.WriteLine("Format template 'message' not found in " + formatName);
                ok = false;
            }
            if (!format.IsDefined("report"))
            {
                Console.Error.WriteLine("Format template 'report' not found in " + formatName);
                ok = false;
            }
            return(ok);
        }
Ejemplo n.º 3
0
        protected StringTemplate GetTokenElementST(string name,
                                                   string elementName,
                                                   GrammarAST elementAST,
                                                   GrammarAST ast_suffix,
                                                   string label)
        {
            bool tryUnchecked = false;

            if (name == "matchSet" && !string.IsNullOrEmpty(elementAST.enclosingRuleName) && Rule.GetRuleType(elementAST.enclosingRuleName) == RuleType.Lexer)
            {
                if ((elementAST.Parent.Type == ANTLRLexer.ALT && elementAST.Parent.Parent.Parent.Type == RULE && elementAST.Parent.Parent.ChildCount == 2) ||
                    (elementAST.Parent.Type == ANTLRLexer.NOT && elementAST.Parent.Parent.Parent.Parent.Type == RULE && elementAST.Parent.Parent.Parent.ChildCount == 2))
                {
                    // single alt at the start of the rule needs to be checked
                }
                else
                {
                    tryUnchecked = true;
                }
            }

            string suffix = GetSTSuffix(elementAST, ast_suffix, label);
            // if we're building trees and there is no label, gen a label
            // unless we're in a synpred rule.
            Rule r = grammar.GetRule(currentRuleName);

            if ((grammar.BuildAST || suffix.Length > 0) && label == null &&
                (r == null || !r.isSynPred))
            {
                label = generator.CreateUniqueLabel(elementName);
                CommonToken labelTok = new CommonToken(ANTLRParser.ID, label);
                grammar.DefineTokenRefLabel(currentRuleName, labelTok, elementAST);
            }

            StringTemplate elementST = null;

            if (tryUnchecked && templates.IsDefined(name + "Unchecked" + suffix))
            {
                elementST = templates.GetInstanceOf(name + "Unchecked" + suffix);
            }
            if (elementST == null)
            {
                elementST = templates.GetInstanceOf(name + suffix);
            }

            if (label != null)
            {
                elementST.SetAttribute("label", label);
            }
            return(elementST);
        }