示例#1
0
 public MIPreFsh ParseOne(String fshText,
     String relativePath)
 {
     MIPreFsh retVal = ParseOneOnly(fshText, relativePath);
     this.Fsh.Add(retVal);
     return retVal;
 }
示例#2
0
文件: MFsh.cs 项目: goelalex/Eir.MFSH
        public void Process(MIPreFsh fsh)
        {
            const String fcn = "Process";

            if (Path.GetExtension(fsh.RelativePath).ToLower() == MINCSuffix)
            {
                return;
            }

            this.usings = fsh.Usings;
            String relativeFshPath = this.SetProfileVariables(fsh.RelativePath);

            this.variableBlocks = new List <VariablesBlock>();
            this.variableBlocks.Insert(0, this.GlobalVars);
            this.variableBlocks.Insert(0, this.profileVariables);

            if (this.GetFileData(relativeFshPath, this.variableBlocks, out FileData fd) == false)
            {
                this.ConversionError(ClassName, fcn, $"Output file {fd.AbsoluteOutputPath} already exists!");
                return;
            }

            this.Process(fsh.Items, fd, this.variableBlocks);

            this.variableBlocks   = null;
            this.profileVariables = null;
        }
示例#3
0
文件: MFsh.cs 项目: goelalex/Eir.MFSH
        void ProcessFragments()
        {
            const String fcn = "ProcessFragments";

            if (String.IsNullOrEmpty(this.FragDir))
            {
                return;
            }

            if (String.IsNullOrEmpty(this.FragTemplatePath) == true)
            {
                this.ConversionError(ClassName, fcn, $"Fragment template not set!");
                return;
            }

            if (File.Exists(this.FragTemplatePath) == false)
            {
                this.ConversionError(ClassName, fcn, $"Fragment template {this.FragTemplatePath} does not exist!");
                return;
            }

            String   fragTempText = File.ReadAllText(this.FragTemplatePath);
            MIPreFsh fragTempCmds = this.Parser.ParseOne(fragTempText, this.FragTemplatePath);

            foreach (MIFragment frag in this.MacroMgr.Fragments())
            {
                this.ProcessFragment(fragTempCmds, frag);
            }
        }
示例#4
0
文件: MFsh.cs 项目: goelalex/Eir.MFSH
        void ProcessFragment(MIPreFsh fragTempCmds,
                             MIFragment frag)
        {
            const String fcn = "ProcessFragment";

            this.appliedMacros.Clear();
            this.incompatibleMacros.Clear();

            String relativePath = this.SetProfileVariables(frag.SourceFile);

            if (String.IsNullOrEmpty(frag.Parent) == true)
            {
                this.ConversionError(ClassName, fcn, $"Fragment {frag.Name} missing parent!");
                return;
            }

            if (relativePath.ToUpper().StartsWith(@"FRAGMENTS\"))
            {
                relativePath = relativePath.Substring(10);
            }
            String absolutePath = Path.Combine(this.FragDir, relativePath);

            absolutePath = Path.GetFullPath(absolutePath);

            if (this.FileItems.TryGetValue(absolutePath.ToUpper().Trim(), out FileData fd) == false)
            {
                fd = new FileData();
                fd.AbsoluteOutputPath = absolutePath;
                this.FileItems.Add(absolutePath.ToUpper().Trim(), fd);
            }
            else
            {
                fd.AppendLine("");
                fd.AppendLine("");
                fd.AppendLine("");
            }

            VariablesBlock        localVb = StartNewFrag(frag, out String name);
            List <VariablesBlock> local   = new List <VariablesBlock>();

            local.Insert(0, this.GlobalVars);
            local.Insert(0, this.profileVariables);
            local.Insert(0, localVb);

            this.skipRedirects = false;
            this.Process(fragTempCmds.Items, fd, local);
            this.skipRedirects = true;

            this.Process(frag.Items, fd, local);
        }
示例#5
0
        public MIPreFsh ParseOneOnly(String fshText,
            String relativePath)
        {
            fshText = fshText.Replace("\r", "");
            String[] inputLines = fshText.Split('\n');

            Parser.MFSHLexer lexer = new Parser.MFSHLexer(new AntlrInputStream(fshText));
            lexer.RemoveErrorListeners();
            lexer.AddErrorListener(new MFSHErrorListenerLexer(this.Mfsh,
                "MFsh Lexer",
                relativePath,
                inputLines));

            Parser.MFSHParser parser = new Parser.MFSHParser(new CommonTokenStream(lexer));
            parser.Trace = false;
            parser.RemoveErrorListeners();
            parser.AddErrorListener(new MFSHErrorListenerParser(this.Mfsh,
                "MFsh Parser",
                relativePath,
                inputLines));
            //parser.ErrorHandler = new BailErrorStrategy();

            Parser.MFSHVisitor visitor = new Parser.MFSHVisitor(this.Mfsh, relativePath);
            visitor.DebugFlag = this.DebugFlag;
            visitor.Visit(parser.document());
            if (visitor.state.Count != 1)
            {
                String fullMsg = $"Error processing {relativePath}. Unterminated #{visitor.state.Peek().Name}";
                this.Mfsh.ConversionError("mfsh", "ProcessInclude", fullMsg);
            }

            ParseBlock block = visitor.Current;
            MIPreFsh retVal = new MIPreFsh(relativePath, 0)
            {
                Items = block.Items,
                RelativePath = relativePath,
                Usings = visitor.Usings
            };

            return retVal;
        }