Antlr4.Tool.ErrorManager.SetFormat C# (CSharp) Method

SetFormat() public method

public SetFormat ( string formatName ) : void
formatName string
return void
        public virtual void SetFormat(string formatName)
        {
            this.formatName = formatName;
            string fileName = Path.Combine(FORMATS_DIR, formatName + TemplateGroup.GroupFileExtension);
            if (!File.Exists(fileName) && formatName != "antlr")
            {
                SetFormat("antlr");
                return;
            }

            //format.EnableCache = AntlrTool.EnableTemplateCache;
            if (!File.Exists(fileName))
            {
                RawError("ANTLR installation corrupted; cannot find ANTLR messages format file " + fileName);
                Panic();
            }
            //else if (url == null)
            //{
            //    RawError("no such message format file " + fileName + " retrying with default ANTLR format");
            //    SetFormat("antlr"); // recurse on this rule, trying the default message format
            //    return;
            //}

            format = new TemplateGroupFile(
                Path.Combine(
                    Path.GetDirectoryName(typeof(AntlrTool).GetTypeInfo().Assembly.Location),
                    fileName),
                Encoding.UTF8);
            format.Load();

            if (initSTListener.Errors.Count > 0)
            {
                RawError("ANTLR installation corrupted; can't load messages format file:\n" +
                         initSTListener.ToString());
                Panic();
            }

            bool formatOK = VerifyFormat();
            if (!formatOK && formatName.Equals("antlr"))
            {
                RawError("ANTLR installation corrupted; ANTLR messages format file " + formatName + ".stg incomplete");
                Panic();
            }
            else if (!formatOK)
            {
                SetFormat("antlr"); // recurse on this rule, trying the default message format
            }
        }

Usage Example

Example #1
0
 public AntlrTool(string[] args)
 {
     this.args = args;
     defaultListener = new DefaultToolListener(this);
     errMgr = new ErrorManager(this);
     errMgr.SetFormat(msgFormat);
     HandleArgs();
 }