public void Move(Directive directive) { Copy(directive); Remove(); }
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(); }
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)))); }
public void Copy(Directive directive) { directive.Directives.Add(directive); }
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; }
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(); }
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, "")); }
private void ParseSectionEnd() { if (!(this.currentDirective is SectionDefinition)) { TemplateParsingException ex = new TemplateParsingException( Resources.SectionDefDirectiveWrong); FillParseError(ex); throw ex; } this.currentDirective = this.currentDirective.Parent; }
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(); }
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)))); }
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)); } }
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)); }
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; }