Example #1
0
 /// <summary>
 /// Modifies the content of the current part to have its
 /// source from a different file. Typically used to implement an
 /// #include functionality.
 /// </summary>
 /// <param name="file">The file to 'include'.</param>
 /// <param name="type">The initial type of the substituted section.</param>
 public void Substitute(MixedContentFile file, object type)
 {
     this.file   = file;
     this.type   = type;
     this.offset = 0;
     this.length = file.Content.Length;
     this.regex  = null;
     this.match  = null;
     this.data   = new NameValueCollection();
 }
Example #2
0
		/// <summary>
		/// Modifies the content of the current part to have its
		/// source from a different file. Typically used to implement an
		/// #include functionality.
		/// </summary>
		/// <param name="file">The file to 'include'.</param>
		/// <param name="type">The initial type of the substituted section.</param>
		public void Substitute(MixedContentFile file, object type)
		{
			this.file = file;
			this.type = type;
			this.offset = 0;
			this.length = file.Content.Length;
			this.regex = null;
			this.match = null;
			this.data = new NameValueCollection();
		}
Example #3
0
		/// <summary>
		/// Constructs a ContentPart matching the whole file content.
		/// </summary>
		public ContentPart(MixedContentFile file, object contentType)
		{
			this.file = file;
			this.type = contentType;
			this.offset = 0;
			this.length = file.Content.Length;
			this.regex = null;
			this.match = null;
			this.data = new NameValueCollection();
		}
Example #4
0
 /// <summary>
 /// Constructs a ContentPart matching the whole file content.
 /// </summary>
 public ContentPart(MixedContentFile file, object contentType)
 {
     this.file   = file;
     this.type   = contentType;
     this.offset = 0;
     this.length = file.Content.Length;
     this.regex  = null;
     this.match  = null;
     this.data   = new NameValueCollection();
 }
Example #5
0
		/// <summary>
		/// Constructs a ContentPart.
		/// </summary>
		public ContentPart(MixedContentFile file, object type, int offset, int length, Regex regex, Match match)
		{
			this.file = file;
			this.type = type;
			this.offset = offset;
			this.length = length;
			this.regex = regex;
			this.match = match;

			if (regex == null || match == null)
			{
				this.data = new NameValueCollection();
			}
			else
			{
				this.data = this.DataOfMatch(regex, match);
			}
		}
Example #6
0
        /// <summary>
        /// Constructs a ContentPart.
        /// </summary>
        public ContentPart(MixedContentFile file, object type, int offset, int length, Regex regex, Match match)
        {
            this.file   = file;
            this.type   = type;
            this.offset = offset;
            this.length = length;
            this.regex  = regex;
            this.match  = match;

            if (regex == null || match == null)
            {
                this.data = new NameValueCollection();
            }
            else
            {
                this.data = this.DataOfMatch(regex, match);
            }
        }
Example #7
0
 /// <summary>
 /// Only parse, but do not act on this Template
 /// </summary>
 public void Parse()
 {
     this.host.Log("Parsing template: \"{0}\".", this.templatefileinfo.FullName);
     this.fileContent = this.ReadAndParseFile();
     this.ReadDirectives(this.fileContent);
 }
Example #8
0
        private void ReadDirectives(MixedContentFile file)
        {
            // Initialize directives:
            this.directives = new Dictionary<string, IList<NameValueCollection>>();

            // Collect directives:
            foreach (ContentPart part in file.FindPartsOfType(TemplatePartTypes.Declaration))
            {
                foreach (Match match in directiveParser.Matches(part.Content))
                {
                    string name = match.Groups["elementName"].Value;
                    NameValueCollection attributes = new NameValueCollection();
                    for (int i = 0; i < match.Groups["name"].Captures.Count; i++)
                    {
                        attributes[match.Groups["name"].Captures[i].Value]
                            = match.Groups["value"].Captures[i].Value;
                    }
                    if (this.directives.ContainsKey(name) == false)
                        this.directives[name] = new List<NameValueCollection>();
                    this.directives[name].Add(attributes);
                }
            }
        }
Example #9
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;
        }