Example #1
0
        private void ProcessSectionDef(SectionDefinition directive)
        {
            this.builder.Append("private void ");
            this.builder.Append(directive.Name);
            this.builder.Append('(');

            for (int i = 0; i < directive.Parameters.Count; i++)
            {
                KeyValuePair<string, string> p = directive.Parameters[i];
                this.builder.Append(p.Value);
                this.builder.Append(' ');
                this.builder.Append(p.Key);
            }

            if (directive.Parameters.Count == 0)
            {
                this.builder.Append("string _spaces_, string writerKey");
            }
            else
            {
                this.builder.Append(", string _spaces_, string writerKey");
            }

            this.builder.AppendLine(") {");
            ProcessSectionDirectives(directive.Directives);
            this.builder.AppendLine("}");
            this.builder.AppendLine();
        }
Example #2
0
        private void ParseSectionStart(string line)
        {
            Assertion.Assert(line != null, "line cannot be null.");

            string trimedLine = line.TrimStart();
            string sectionDef = trimedLine.Substring(SectionDefStartDirective.Length).Trim();

            if (trimedLine.Length == SectionDefStartDirective.Length ||
                trimedLine[SectionDefStartDirective.Length] != ' ' ||
                sectionDef.Length == 0)
            {
                TemplateParsingException ex =
                    new TemplateParsingException(
                        Resources.BadSectionDef);
                FillParseError(ex);
                throw ex;
            }

            if (!(this.currentDirective is Body))
            {
                TemplateParsingException ex =
                    new TemplateParsingException(
                        Resources.SectionDefNotTopLevel);
                FillParseError(ex);
                throw ex;
            }

            Match match = sectionExp.Match(sectionDef);

            if (!match.Success)
            {
                TemplateParsingException ex =
                    new TemplateParsingException(
                        Resources.BadSectionDef);
                FillParseError(ex);
                throw ex;
            }

            if (this.sections.ContainsKey(match.Groups["name"].Value))
            {
                TemplateParsingException ex =
                    new TemplateParsingException(
                        String.Format(
                            Resources.SectionNameNotUnique,
                            match.Groups["name"].Value));
                FillParseError(ex);
                throw ex;
            }
            else
            {
                this.sections.Add(match.Groups["name"].Value, null);
            }

            SectionDefinition def = new SectionDefinition(match.Groups["name"].Value);

            for (int i = 0; i < match.Groups["pname"].Captures.Count; i++)
            {
                string pname = match.Groups["pname"].Captures[i].Value;
                string ptype = match.Groups["ptype"].Captures[i].Value;
                def.Parameters.Add(new KeyValuePair<string, string>(pname, ptype));
            }

            this.currentDirective.Directives.Add(def);
            this.currentDirective = def;
        }