예제 #1
0
 public virtual void ImportWhitespaceOrComment(Token token)
 {
     if (importReplaceTabs != null) token.Value = token.Value.Replace("\t", importReplaceTabs);
     if (importReplaceSpaces != null) token.Value = token.Value.Replace(importReplaceSpaces, "\t");
 }
예제 #2
0
 public virtual void ImportTokenValue(Token t)
 {
 }
예제 #3
0
 public virtual void ImportTrailingWhitespace(Token token)
 {
     var t2 = token.Next as Token;
     while (t2 != null && t2.IsWhitespaceOrComment) t2 = t2.Next as Token;
     if (t2 == null) {
         token = token.Next as Token;
         if (token != null && token.IsWhitespaceOrComment) {
             ImportWhitespaceOrComment(token);
             ImportTrailingWhitespace(token);
         }
     }
 }
예제 #4
0
 public virtual void WriteTrailingWhitespace(Token token)
 {
     var nextNonWhitespace = token.Next as Token;
     while (nextNonWhitespace != null && nextNonWhitespace.IsWhitespaceOrComment) nextNonWhitespace = nextNonWhitespace.Next as Token;
     if (nextNonWhitespace == null) { // only write trailing whitespace if there is no more next token that will write leading whitespace.
         var next = token.Next as Token;
         if (next != null && next.IsWhitespaceOrComment) {
             WriteWhitespaceOrComment(next);
             WriteTrailingWhitespace(next);
         }
     }
 }
예제 #5
0
 public Reader()
 {
     EndOfDocument = new Token(TokenClass.EndOfDocument);
     WhitespaceTokens = new Queue<Token>();
     Text = string.Empty;
 }
예제 #6
0
 public virtual void WriteLeadingWhitespace(Token token)
 {
     var prev = token.Previous as Token;
     if (prev != null && prev.IsWhitespaceOrComment) 	{
         WriteLeadingWhitespace(prev);
         WriteWhitespaceOrComment(prev);
     }
 }
예제 #7
0
 public virtual void WriteToken(Token token)
 {
     WriteLeadingWhitespace(token);
     if (token.IsWhitespaceOrComment) WriteWhitespaceOrComment(token);
     else {
         if (token.Class == TokenClass.String) {
             if (token.StringClass == StringClass.DoubleQuote) {
                 TextWriter.Write('"');
                 TextWriter.Write(token.Value);
                 TextWriter.Write('"');
             } else {
                 TextWriter.Write("'");
                 TextWriter.Write(token.Value);
                 TextWriter.Write("'");
             }
         } else if (token.Class != TokenClass.EndOfDocument) TextWriter.Write(token.Value);
     }
     WriteTrailingWhitespace(token);
 }
예제 #8
0
 public virtual void ReadToReserved(Token t)
 {
     ReadTo(t, Reserved);
 }
예제 #9
0
 public virtual void Skip(Token t)
 {
     if (t.Length < 0) t.Length = 0;
     while (Position < Text.Length && Position < t.End) {
         if (Text[Position] == '\n') { Line++; LastNewline = Position+1; }
         Position++;
     }
 }
예제 #10
0
 public virtual void ReadTo(Token t, params char[] characters)
 {
     Skip(t);
     int w;
     if (characters.Length > 1) {
         w = Text.IndexOfAny(characters, Position);
     } else {
         w = Text.IndexOf(characters[0], Position);
     }
     if (w > 0) {
         t.End = w;
         Skip(t);
     } else {
         //Start = End = Html.Length;
         t.End = Text.Length;
         Skip(t);
     }
 }
예제 #11
0
 public virtual void ReadTo(Token t, string s)
 {
     while(true) {
         ReadTo(t, s[0]);
         if (Position == Text.Length || Peek(s, null)) return;
         t.Length++;
     }
 }
예제 #12
0
 public virtual void ReadOver(Token t, string s)
 {
     ReadTo(t, s);
     if (Position < Text.Length) t.Length += s.Length;
     else t.End = Text.Length;
     Skip(t);
 }
예제 #13
0
 public void Read(Token t)
 {
     Contract.Ensures(t.Start <= t.End);
     Skip(t);
     if (t.Class == TokenClass.EndOfDocument) return;
     if (t.Class == TokenClass.String) t.Value = Text.Substring(t.Start + 1, t.Length - 2);
     else t.Value = Text.Substring(t.Start, t.Length);
     if (t.Class != TokenClass.Whitespace) {
         t.Identation = CurrentIdentation;
         CurrentIdentation = string.Empty;
     }
 }
예제 #14
0
 public virtual bool Peek(string s, Token t)
 {
     return Peek(0, s);
 }
예제 #15
0
 public void CopyFrom(Token t)
 {
     Start = t.Start; End = t.End; Line = t.Line; Column = t.Column; Identation = t.Identation; tokenClass = t.tokenClass; stringClass = t.stringClass; serverTagClass = t.serverTagClass; Value = t.Value;
 }
예제 #16
0
 public virtual void SkipWhitespace(ref Token t)
 {
     var start = Position;
     while (Position < Text.Length && Whitespace.Contains(Text[Position])) {
         if (Text[Position] == '\n') { Line++; LastNewline = Position+1; }
         Position++;
     }
     if (start != Position) {
         t.Class = TokenClass.Whitespace; t.End = Position;
         WhitespaceTokens.Enqueue(t); Read(t);
         if (LastNewline >= t.Start) CurrentIdentation = Text.Substring(LastNewline, t.End - LastNewline);
         t = NewToken();
         CurrentToken = t;
     }
 }
예제 #17
0
 public void ExportServerControlToken(Token t)
 {
     t.Value = t.Value.Replace("<", "[&lt;").Replace(">", "&gt;]");
 }
예제 #18
0
 public virtual void ImportLeadingWhitespace(Token token)
 {
     token = token.Previous as Token;
     if (token != null && token.IsWhitespaceOrComment) {
         ImportLeadingWhitespace(token);
         ImportWhitespaceOrComment(token);
     }
 }
예제 #19
0
 public virtual void WriteNewLineAfter(Token token)
 {
     if (!token.IsWhitespaceOrComment) WriteToken(token);
 }
예제 #20
0
 public virtual void ImportNewLineAfter(Token token)
 {
     if (!token.IsWhitespaceOrComment) ImportToken(token);
 }
예제 #21
0
 public virtual void WriteTokenValue(Token t)
 {
     switch (t.Class) {
     case TokenClass.EndTagStart: t.Value = "</"; break;
     case TokenClass.Equals: t.Value = "="; break;
     case TokenClass.ServerTagEnd:
         if (t.ServerTagClass == ServerTagClass.Comment) t.Value = "--%>";
         else if (t.ServerTagClass == ServerTagClass.PersistentObjectName) t.Value = "]";
         else t.Value = "%>";
         break;
     case TokenClass.ServerTagStart:
         switch (t.ServerTagClass) {
         case ServerTagClass.AspNetExpression: t.Value = "<%$"; break;
         case ServerTagClass.HtmlEncodedExpression: t.Value = "<%:"; break;
         case ServerTagClass.Binding: t.Value = "<%#"; break;
         case ServerTagClass.Expression: t.Value = "<%="; break;
         case ServerTagClass.Declaration: t.Value = "<%@"; break;
         case ServerTagClass.Comment: t.Value = "<%--"; break;
         case ServerTagClass.Code: t.Value = "<%"; break;
         case ServerTagClass.PersistentObject: t.Value = "<%--[Silversite.PersistentObject:"; break;
         }
         break;
     case TokenClass.SingleTagEnd: t.Value = "/>"; break;
     case TokenClass.TagEnd: t.Value = ">"; break;
     case TokenClass.TagStart: t.Value = "<"; break;
     case TokenClass.DoctypeStart: t.Value = "<!DOCTYPE"; break;
     case TokenClass.HtmlCommentStart: t.Value = "<!--"; break;
     case TokenClass.HtmlCommentEnd: t.Value = "-->"; break;
     case TokenClass.CDataEnd: t.Value = "]]>"; break;
     case TokenClass.CDataStart: t.Value = "<![CDATA["; break;
     case TokenClass.Literal:
     case TokenClass.Script:
     case TokenClass.Identifier:
     case TokenClass.String: t.Value = string.Empty; break;
     case TokenClass.Whitespace: t.Value = " "; break;
     case TokenClass.XmlDocTagStart: t.Value = "<?"; break;
     case TokenClass.XmlDocTagEnd: t.Value = "?>"; break;
     default: break;
     }
 }
예제 #22
0
 public virtual void ImportToken(Token token)
 {
     if (token.IsWhitespaceOrComment) ImportWhitespaceOrComment(token);
     else {
         ImportLeadingWhitespace(token);
         ImportTokenValue(token);
         ImportTrailingWhitespace(token);
     }
 }
예제 #23
0
 public virtual void WriteWhitespaceOrComment(Token token)
 {
     switch (token.Class) {
     case TokenClass.ServerTagStart:
     case TokenClass.ServerTagEnd:
     case TokenClass.Literal: if (token.ServerTagClass == ServerTagClass.Comment) TextWriter.Write(token.Value); break;
     case TokenClass.Whitespace:
         string value = token.Value;
         if (replaceTabs != null) value = value.Replace("\t", replaceTabs);
         if (replaceSpaces != null) value = value.Replace(replaceSpaces, "\t");
         TextWriter.Write(value);
         break;
     case TokenClass.HtmlComment:
     case TokenClass.HtmlCommentEnd:
     case TokenClass.HtmlCommentStart: TextWriter.Write(token.Value); break;
     default: break;
     }
 }
예제 #24
0
 public Token NewToken()
 {
     var t = new Token(); t.Start = Position; t.Length = 0; t.Line = Line; t.Column = t.Start - LastNewline + 1; t.Parser = Parser; return t;
 }