Пример #1
0
 public void Move(Directive directive)
 {
     Copy(directive);
     Remove();
 }
Пример #2
0
        private string IndentDirective(Directive directive, string text)
        {
            StringBuilder builder = new StringBuilder(4);

            for (Directive parent = directive.Parent; !(parent is IBorder); parent = parent.Parent)
            {
                IIndentScope scope = parent as IIndentScope;
                if (scope != null)
                {
                    builder.Insert(0, scope.Spaces);
                }
            }

            return builder.Append(text).ToString();
        }
Пример #3
0
        private void ParseTextStart(string line)
        {
            Assertion.Assert(line != null, "line cannot be null.");

            Text text = new Text();
            this.currentDirective.Directives.Add(text);
            this.currentDirective = text;

            this.contextStack.Push(
                new Context(
                    TemplateMode.Static,
                    line.Substring(0, CountLeadingWhiteSpace(line))));
        }
Пример #4
0
 public void Copy(Directive directive)
 {
     directive.Directives.Add(directive);
 }
Пример #5
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;
        }
Пример #6
0
        private void ParseTextEnd()
        {
            if (this.contextStack.Count <= 1 ||
                this.contextStack.Peek().Mode != TemplateMode.Static)
            {
                TemplateParsingException ex =
                    new TemplateParsingException(
                        Resources.TextDirectiveWrong);
                FillParseError(ex);
                throw ex;
            }

            this.currentDirective = this.currentDirective.Parent;

            this.contextStack.Pop();
        }
Пример #7
0
        private void ParseOutputStart(string line)
        {
            Assertion.Assert(line != null, "line cannot be null.");

            string trimedLine = line.TrimStart();
            string key = trimedLine.Substring(OutputStartDirective.Length).Trim();

            if (trimedLine.Length == OutputStartDirective.Length ||
                trimedLine[OutputStartDirective.Length] != ' ' ||
                key.Length == 0)
            {
                TemplateParsingException ex =
                    new TemplateParsingException(
                        Resources.NoOutputKeyProvided);
                FillParseError(ex);
                throw ex;
            }

            Output output = new Output(key);
            this.currentDirective.Directives.Add(output);
            this.currentDirective = output;

            this.outputStack.Push(
                new OutputContext(
                    key,
                    line.Substring(0, CountLeadingWhiteSpace(line))));

            this.contextStack.Push(new Context(TemplateMode.Static, ""));
        }
Пример #8
0
        private void ParseSectionEnd()
        {
            if (!(this.currentDirective is SectionDefinition))
            {
                TemplateParsingException ex =
                    new TemplateParsingException(
                        Resources.SectionDefDirectiveWrong);
                FillParseError(ex);
                throw ex;
            }

            this.currentDirective = this.currentDirective.Parent;
        }
Пример #9
0
        private void ParseOutputEnd()
        {
            if (this.outputStack.Count == 0)
            {
                TemplateParsingException ex =
                    new TemplateParsingException(
                        Resources.OutputDirectiveWrong);
                FillParseError(ex);
                throw ex;
            }

            this.currentDirective = this.currentDirective.Parent;

            this.outputStack.Pop();
            this.contextStack.Pop();
        }
Пример #10
0
        private void ParseCodeStart(string line)
        {
            Assertion.Assert(line != null, "line cannot be null.");

            string spaces = line.Substring(0, line.IndexOf(CodeStartDirective));
            Code code = new Code(spaces);
            this.currentDirective.Directives.Add(code);
            this.currentDirective = code;

            this.contextStack.Push(
                new Context(
                    TemplateMode.Dynamic,
                    line.Substring(0, CountLeadingWhiteSpace(line))));
        }
Пример #11
0
        private void ParseBetweenStartIfAny(string line)
        {
            Assertion.Assert(line != null, "line cannot be null.");

            if (betweenStartHandlingExpr.IsMatch(line))
            {
                Between between = new Between();
                this.currentDirective.Directives.Add(between);
                this.currentDirective = between;

                this.contextStack.Push(new Context(
                    TemplateMode.Dynamic, string.Empty));
            }
        }
Пример #12
0
        private void ParseBetweenEnd(string line)
        {
            if (this.contextStack.Count <= 1 ||
                this.contextStack.Peek().Mode != TemplateMode.Dynamic)
            {
                TemplateParsingException ex =
                    new TemplateParsingException(Resources.BetweenDirectiveWrong);
                FillParseError(ex);
                throw ex;
            }

            this.currentDirective = this.currentDirective.Parent;

            this.contextStack.Pop();

            this.ParseTextLine(
                line.Substring(
                    line.IndexOf(BetweenEndDirective) + BetweenEndDirective.Length));
        }
Пример #13
0
        private void InitParsing()
        {
            this.ast = new AtTemplateAst();

            this.ast.Head.References.Add(new Reference("System.dll"));
            this.ast.Head.References.Add(new Reference(Assembly.GetExecutingAssembly().Location));

            this.currentDirective = this.ast.Body;

            if (this.outputStack == null)
            {
                this.outputStack = new Stack<OutputContext>();
            }
            else
            {
                this.outputStack.Clear();
            }

            if (this.contextStack == null)
            {
                this.contextStack = new ContextStack();
            }
            else
            {
                this.contextStack.Clear();
            }

            if (this.sections == null)
            {
                this.sections = new Dictionary<string, object>();
            }
            else
            {
                this.sections.Clear();
            }

            this.contextStack.Push(new Context(TemplateMode.Static, string.Empty));

            this.lineCount = 0;
            this.isInGlobalBlock = false;
        }