Exemple #1
0
        private MixedContentFile ReadAndParseFile()
        {
            // Read the file:
            MixedContentFile file = new MixedContentFile(this.templatefileinfo.FullName, File.ReadAllText(this.templatefileinfo.FullName), TemplatePartTypes.TemplateBody);

            // Process comments:
            file.ApplyParserRegex(TemplatePartTypes.TemplateBody, TemplatePartTypes.Comment, GenerationLanguage.RxComments);
            file.ExtractPartsGroup(TemplatePartTypes.Comment, "comment", TemplatePartTypes.Comment);

            // Pre-processor 'includes':
            while (file.ApplyParserRegex(TemplatePartTypes.TemplateBody, TemplatePartTypes.IncludePragma, GenerationLanguage.RxIncludes))
            {
                foreach (ContentPart part in file.Parts)
                {
                    if ((TemplatePartTypes)part.Type == TemplatePartTypes.IncludePragma)
                    {
                        string fn = part.Data["filename"];
                        fn = Path.Combine(Path.GetDirectoryName(part.File.Filename), fn);
                        part.Substitute(new MixedContentFile(fn, File.ReadAllText(fn), TemplatePartTypes.TemplateBody), TemplatePartTypes.TemplateBody);
                    }
                }
            }

            // Process declarations:
            file.ApplyParserRegex(TemplatePartTypes.TemplateBody, TemplatePartTypes.Declaration, GenerationLanguage.RxDirectives);

            // Process scripts:
            file.ApplyParserRegex(TemplatePartTypes.TemplateBody, TemplatePartTypes.Script, GenerationLanguage.RxScripts);
            file.ExtractPartsGroup(TemplatePartTypes.Script, "body", TemplatePartTypes.Script);

            // Process scriptlets:
            file.ApplyParserRegex(TemplatePartTypes.TemplateBody, TemplatePartTypes.Scriptlet, GenerationLanguage.RxScriptlets);
            file.ExtractPartsGroup(TemplatePartTypes.Scriptlet, "body", TemplatePartTypes.Scriptlet);

            // Process embedded body:
            file.ApplyParserRegex(TemplatePartTypes.Scriptlet, TemplatePartTypes.EmbeddedBody, GenerationLanguage.RxEmbeddedBody);
            file.ExtractPartsGroup(TemplatePartTypes.EmbeddedBody, "body", TemplatePartTypes.TemplateBody);

            return file;
        }