]> O.S.I.I.S - jp/crowedit.git/commitdiff
code clean and formatting
authorJean-Philippe Bruyère <jp_bruyere@hotmail.com>
Wed, 30 Aug 2017 22:22:09 +0000 (00:22 +0200)
committerJean-Philippe Bruyère <jp_bruyere@hotmail.com>
Wed, 30 Aug 2017 22:22:09 +0000 (00:22 +0200)
CodeBufferEventArgs.cs [new file with mode: 0644]
CrowEdit.csproj
ParsingException.cs [new file with mode: 0644]
src/CSharpParser.cs
src/CodeBuffer.cs
src/Parser.cs
src/SourceEditor.cs
src/TextFormatting.cs [new file with mode: 0644]
src/XMLParser.cs

diff --git a/CodeBufferEventArgs.cs b/CodeBufferEventArgs.cs
new file mode 100644 (file)
index 0000000..07dd25b
--- /dev/null
@@ -0,0 +1,20 @@
+using System;
+
+namespace Crow.Coding
+{
+       public class CodeBufferEventArgs : EventArgs {
+               public int LineStart;
+               public int LineCount;
+
+               public CodeBufferEventArgs(int lineNumber) {
+                       LineStart = lineNumber;
+                       LineCount = 1;
+               }
+               public CodeBufferEventArgs(int lineStart, int lineCount) {
+                       LineStart = lineStart;
+                       LineCount = lineCount;
+               }
+       }
+
+}
+
index ea89cf2365e43d32d78068bc4e222f30c62d6eb9..d3877abc78c5baaa2ac07adbad085c429e239044 100644 (file)
@@ -81,6 +81,9 @@
     <Compile Include="src\CSharpParser.cs" />
     <Compile Include="src\TokenList.cs" />
     <Compile Include="src\CodeBuffer.cs" />
+    <Compile Include="src\TextFormatting.cs" />
+    <Compile Include="ParsingException.cs" />
+    <Compile Include="CodeBufferEventArgs.cs" />
   </ItemGroup>
   <ItemGroup>
     <Folder Include="ui\" />
diff --git a/ParsingException.cs b/ParsingException.cs
new file mode 100644 (file)
index 0000000..88c51c9
--- /dev/null
@@ -0,0 +1,22 @@
+using System;
+
+namespace Crow.Coding
+{
+       public class ParsingException : Exception
+       {
+               public int Line;
+               public int Column;
+               public ParsingException(Parser parser, string txt)
+                       : base(string.Format("Parser exception ({0},{1}): {2}", parser.currentLine, parser.currentColumn, txt))
+               {
+                       Line = parser.currentLine;
+                       Column = parser.currentColumn;
+               }
+               public ParsingException(Parser parser, string txt, Exception innerException)
+                       : base(txt, innerException)
+               {
+                       txt = string.Format("Parser exception ({0},{1}): {2}", parser.currentLine, parser.currentColumn, txt);
+               }
+       }
+}
+
index f9d7cbae0c926230d9f7f738edffbd7ce1ac0512..472d004fdfcdd74be5f39079f8b1d4b517198396 100644 (file)
@@ -28,7 +28,7 @@ namespace Crow.Coding
                        Preprocessor,
                }
 
-               public CSharpParser (CodeTextBuffer _buffer) : base(_buffer)
+               public CSharpParser (CodeBuffer _buffer) : base(_buffer)
                {
                }
 
index ab764f7d4b4292a9bb137d1a956e2fa31b38a86e..104ddb4d958580d46217da8ae0bdbcc922ed7134 100644 (file)
@@ -25,21 +25,7 @@ using System.Text.RegularExpressions;
 
 namespace Crow.Coding
 {
-       public class CodeBufferEventArgs : EventArgs {
-               public int LineStart;
-               public int LineCount;
-
-               public CodeBufferEventArgs(int lineNumber) {
-                       LineStart = lineNumber;
-                       LineCount = 1;
-               }
-               public CodeBufferEventArgs(int lineStart, int lineCount) {
-                       LineStart = lineStart;
-                       LineCount = lineCount;
-               }
-       }
-
-       public class CodeTextBuffer
+       public class CodeBuffer
        {
                #region Events
                public event EventHandler<CodeBufferEventArgs> LineUpadateEvent;
@@ -49,11 +35,13 @@ namespace Crow.Coding
                #endregion
 
                #region CTOR
-               public CodeTextBuffer () : base() {}
+               public CodeBuffer () : base() {}
                #endregion
 
-
+               string lineBreak = Interface.LineBreak;
                List<string> lines = new List<string>();
+               public int longestLineIdx = 0;
+               public int longestLineCharCount = 0;
 
                public int Length { get { return lines.Count;}}
 
@@ -86,7 +74,6 @@ namespace Crow.Coding
                        BufferCleared.Raise (this, null);
                }
 
-
                public void Load(string rawSource) {
                        this.Clear();
 
@@ -98,10 +85,6 @@ namespace Crow.Coding
                        lineBreak = detectLineBreakKind (rawSource);
                        findLongestLine ();
                }
-               string lineBreak = Interface.LineBreak;
-
-               public int longestLineIdx = 0;
-               public int longestLineCharCount = 0;
 
                void findLongestLine(){
                        longestLineCharCount = 0;
index 4d5b0ce5f8792048450999e29edfb9397316392f..f5d91c6741be40874338c16372b3a5b0ed30ea5d 100644 (file)
@@ -30,19 +30,6 @@ namespace Crow.Coding
                        Preprocessor,
                }
 
-               public class ParsingException : Exception
-               {
-                       public ParsingException(Parser parser, string txt)
-                               : base(string.Format("Parser exception ({0},{1}): {2}", parser.currentLine, parser.currentColumn, txt))
-                       {
-                       }
-                       public ParsingException(Parser parser, string txt, Exception innerException)
-                               : base(txt, innerException)
-                       {
-                               txt = string.Format("Parser exception ({0},{1}): {2}", parser.currentLine, parser.currentColumn, txt);
-                       }
-               }
-
                #region CTOR
                public Parser (CodeBuffer _buffer)
                {
@@ -54,30 +41,29 @@ namespace Crow.Coding
 
                #endregion
 
-               protected int currentLine = 0;
-               protected int currentColumn = 0;
+               CodeBuffer buffer;
+
+               internal int currentLine = 0;
+               internal int currentColumn = 0;
                protected Token currentTok;
                protected bool eof = true;
 
-               CodeBuffer buffer;
-
                public List<TokenList> Tokens;
-               protected TokenList TokensLine;
 
                public Point CurrentPosition { get { return new Point (currentLine, currentColumn); } }
 
-               public virtual void SetLineInError(int lineNumber) {
+               public abstract void Parse(int line);
+               public virtual void SetLineInError(ParsingException ex) {
                        currentTok = default(Token);
-                       Tokens [lineNumber] = new TokenList () {new Token () { Content = buffer [lineNumber] }};
+                       Tokens [ex.Line] = new TokenList () {new Token () { Content = buffer [ex.Line] }};
                }
-               public abstract void Parse(int line);
 
+               #region low level parsing
                protected void readToCurrTok(bool startOfTok = false){
                        if (startOfTok)
                                currentTok.Start = CurrentPosition;
                        currentTok += Read();
                }
-
                protected void readAndResetCurrentTok(System.Enum type, bool startToc = false) {
                        readToCurrTok ();
                        saveAndResetCurrentTok (type);
@@ -86,11 +72,9 @@ namespace Crow.Coding
                protected void saveAndResetCurrentTok(System.Enum type) {
                        currentTok.Type = (TokenType)type;
                        currentTok.End = CurrentPosition;
-                       TokensLine.Add (currentTok);
-
+                       Tokens[currentLine].Add (currentTok);
                        currentTok = default(Token);
                }
-
                protected virtual char Peek() {
                        if (eof)
                                throw new ParsingException (this, "Unexpected End of File");
@@ -116,7 +100,6 @@ namespace Crow.Coding
                                currentColumn++;
                        return c;
                }
-
                protected virtual string ReadUntil (string endExp){
                        string tmp = "";
 
@@ -134,7 +117,6 @@ namespace Crow.Coding
                        }
                        throw new ParsingException (this, string.Format("Expectign '{0}'", endExp));
                }
-
                protected void SkipWhiteSpaces () {
                        if (currentTok.Type != TokenType.Unknown)
                                throw new ParsingException (this, "current token should be reset to unknown (0) before skiping white spaces");
@@ -147,5 +129,6 @@ namespace Crow.Coding
                        if (currentTok.Type != TokenType.Unknown)
                                saveAndResetCurrentTok ();
                }
+               #endregion
        }
 }
\ No newline at end of file
index f2304f9e191eb32a61dcf6ae84e807fcafcb70b8..7b73819fd83fb2689606f3088fbdd712a9426d81 100644 (file)
@@ -38,15 +38,6 @@ using CrowEdit;
 
 namespace Crow.Coding
 {
-       public struct TextFormating {
-               public Color Foreground;
-               public Color Background;
-
-               public TextFormating(Color fg, Color bg){
-                       Foreground = fg;
-                       Background = bg;
-               }
-       }
        /// <summary>
        /// Scrolling text box optimized for monospace fonts, for coding
        /// </summary>
@@ -55,17 +46,17 @@ namespace Crow.Coding
                #region CTOR
                public SourceEditor ():base()
                {
-                       formating.Add ((int)XMLParser.TokenType.AttributeName, new TextFormating (Color.DarkBlue, Color.Transparent));
-                       formating.Add ((int)XMLParser.TokenType.ElementName, new TextFormating (Color.DarkRed, Color.Transparent));
-                       formating.Add ((int)XMLParser.TokenType.ElementStart, new TextFormating (Color.Red, Color.Transparent));
-                       formating.Add ((int)XMLParser.TokenType.ElementEnd, new TextFormating (Color.Red, Color.Transparent));
-                       formating.Add ((int)XMLParser.TokenType.ElementClosing, new TextFormating (Color.Red, Color.Transparent));
+                       formatting.Add ((int)XMLParser.TokenType.AttributeName, new TextFormatting (Color.DarkBlue, Color.Transparent));
+                       formatting.Add ((int)XMLParser.TokenType.ElementName, new TextFormatting (Color.DarkRed, Color.Transparent));
+                       formatting.Add ((int)XMLParser.TokenType.ElementStart, new TextFormatting (Color.Red, Color.Transparent));
+                       formatting.Add ((int)XMLParser.TokenType.ElementEnd, new TextFormatting (Color.Red, Color.Transparent));
+                       formatting.Add ((int)XMLParser.TokenType.ElementClosing, new TextFormatting (Color.Red, Color.Transparent));
 
-                       formating.Add ((int)XMLParser.TokenType.AttributeValueOpening, new TextFormating (Color.DarkPink, Color.Transparent));
-                       formating.Add ((int)XMLParser.TokenType.AttributeValueClosing, new TextFormating (Color.DarkPink, Color.Transparent));
-                       formating.Add ((int)XMLParser.TokenType.AttributeValue, new TextFormating (Color.DarkPink, Color.Transparent));
+                       formatting.Add ((int)XMLParser.TokenType.AttributeValueOpening, new TextFormatting (Color.DarkPink, Color.Transparent));
+                       formatting.Add ((int)XMLParser.TokenType.AttributeValueClosing, new TextFormatting (Color.DarkPink, Color.Transparent));
+                       formatting.Add ((int)XMLParser.TokenType.AttributeValue, new TextFormatting (Color.DarkPink, Color.Transparent));
 
-                       buffer = new CodeTextBuffer ();
+                       buffer = new CodeBuffer ();
                        buffer.LineUpadateEvent += Buffer_LineUpadateEvent;
                        buffer.LineAdditionEvent += Buffer_LineAdditionEvent;;
                        buffer.LineRemoveEvent += Buffer_LineRemoveEvent;
@@ -75,7 +66,6 @@ namespace Crow.Coding
                }
                #endregion
 
-               Dictionary<int,TextFormating> formating = new Dictionary<int, TextFormating>();
 
                public event EventHandler TextChanged;
 
@@ -87,7 +77,7 @@ namespace Crow.Coding
                #region private and protected fields
                int visibleLines = 1;
                int visibleColumns = 1;
-               CodeTextBuffer buffer;
+               CodeBuffer buffer;
                Parser parser;
                Color selBackground;
                Color selForeground;
@@ -96,37 +86,13 @@ namespace Crow.Coding
                Point _selBegin = -1;   //selection start (row,column)
                Point _selRelease = -1; //selection end (row,column)
 
+               Dictionary<int,TextFormatting> formatting = new Dictionary<int, TextFormatting>();
+
                protected Rectangle rText;
                protected FontExtents fe;
                protected TextExtents te;
                #endregion
 
-               [XmlAttributeAttribute][DefaultValue("label")]
-               public string Text
-               {
-                       get {
-                               return buffer == null ? "" : buffer.FullText;
-                       }
-                       set
-                       {
-                               if (string.Equals (value, buffer?.FullText, StringComparison.Ordinal))
-                                       return;
-
-                               buffer.Load (value);
-
-                               MaxScrollY = Math.Max (0, buffer.Length - visibleLines);
-                               MaxScrollX = Math.Max (0, buffer.longestLineCharCount - visibleColumns);
-
-                               OnTextChanged (this, null);
-                               RegisterForGraphicUpdate ();
-                       }
-               }
-
-               void Buffer_BufferCleared (object sender, EventArgs e)
-               {
-                       parser = new XMLParser (buffer);
-                       RegisterForGraphicUpdate ();
-               }
                void reparseSource () {
                        for (int i = 0; i < parser.Tokens.Count; i++) {
                                if (parser.Tokens[i].Dirty)
@@ -136,12 +102,18 @@ namespace Crow.Coding
                void tryParseBufferLine(int lPtr) {
                        try {
                                parser.Parse (lPtr);
-                       } catch (Exception ex) {
+                       } catch (ParsingException ex) {
                                Debug.WriteLine (ex.ToString ());
-                               parser.SetLineInError (lPtr);
+                               parser.SetLineInError (ex);
                        }
                        RegisterForGraphicUpdate ();
                }
+               #region Buffer events handlers
+               void Buffer_BufferCleared (object sender, EventArgs e)
+               {
+                       parser = new XMLParser (buffer);
+                       RegisterForGraphicUpdate ();
+               }
                void Buffer_LineAdditionEvent (object sender, CodeBufferEventArgs e)
                {
                        for (int i = 0; i < e.LineCount; i++) {
@@ -167,7 +139,29 @@ namespace Crow.Coding
                        reparseSource ();
                        RegisterForGraphicUpdate ();
                }
+               #endregion
+
+               #region Public Crow Properties
+               [XmlAttributeAttribute][DefaultValue("label")]
+               public string Text
+               {
+                       get {
+                               return buffer == null ? "" : buffer.FullText;
+                       }
+                       set
+                       {
+                               if (string.Equals (value, buffer?.FullText, StringComparison.Ordinal))
+                                       return;
 
+                               buffer.Load (value);
+
+                               MaxScrollY = Math.Max (0, buffer.Length - visibleLines);
+                               MaxScrollX = Math.Max (0, buffer.longestLineCharCount - visibleColumns);
+
+                               OnTextChanged (this, null);
+                               RegisterForGraphicUpdate ();
+                       }
+               }
                [XmlAttributeAttribute][DefaultValue("BlueGray")]
                public virtual Color SelectionBackground {
                        get { return selBackground; }
@@ -317,7 +311,9 @@ namespace Crow.Coding
                }
                [XmlIgnore]public bool selectionIsEmpty
                { get { return SelRelease == SelBegin; } }
+               #endregion
 
+               #region Editing and moving cursor
                /// <summary>
                /// Moves cursor one char to the left.
                /// </summary>
@@ -406,42 +402,39 @@ namespace Crow.Coding
                        }
                        OnTextChanged (this, null);
                }
-
-               #region GraphicObject overrides
-               public override Font Font {
-                       get { return base.Font; }
-                       set {
-                               base.Font = value;
-
-                               using (ImageSurface img = new ImageSurface (Format.Argb32, 1, 1)) {
-                                       using (Context gr = new Context (img)) {
-                                               gr.SelectFontFace (Font.Name, Font.Slant, Font.Wheight);
-                                               gr.SetFontSize (Font.Size);
-
-                                               fe = gr.FontExtents;
-                                       }
-                               }
-                               MaxScrollY = 0;
-                               RegisterForGraphicUpdate ();
-                       }
-               }
-               protected override int measureRawSize(LayoutingType lt)
+               /// <summary>
+               /// Insert new string at caret position, should be sure no line break is inside.
+               /// </summary>
+               /// <param name="str">String.</param>
+               protected void Insert(string str)
                {
-                       if (lt == LayoutingType.Height)
-                               return (int)Math.Ceiling(fe.Height * buffer.Length) + Margin * 2;
-
-                       return (int)(fe.MaxXAdvance * buffer.longestLineCharCount) + Margin * 2;
+                       if (!selectionIsEmpty)
+                               this.DeleteChar ();
+                       string[] strLines = Regex.Split (str, "\r\n|\r|\n|" + @"\\n").ToArray();
+                       buffer [CurrentLine] = buffer [CurrentLine].Insert (CurrentColumn, strLines[0]);
+                       CurrentColumn += strLines[0].Length;
+                       for (int i = 1; i < strLines.Length; i++) {
+                               InsertLineBreak ();
+                               buffer [CurrentLine] = buffer [CurrentLine].Insert (CurrentColumn, strLines[i]);
+                               CurrentColumn += strLines[i].Length;
+                       }
+                       OnTextChanged (this, null);
+                       RegisterForGraphicUpdate();
                }
-               public override void OnLayoutChanges (LayoutingType layoutType)
+               /// <summary>
+               /// Insert a line break.
+               /// </summary>
+               protected void InsertLineBreak()
                {
-                       base.OnLayoutChanges (layoutType);
-
-                       if (layoutType == LayoutingType.Height)
-                               updateVisibleLines ();
-                       else if (layoutType == LayoutingType.Width)
-                               updateVisibleColumns ();
+                       buffer.Insert(CurrentLine + 1, buffer[CurrentLine].Substring(CurrentColumn));
+                       buffer [CurrentLine] = buffer [CurrentLine].Substring (0, CurrentColumn);
+                       CurrentLine++;
+                       CurrentColumn = 0;
+                       OnTextChanged (this, null);
                }
+               #endregion
 
+               #region Drawing
                void draw(Context gr){
                        gr.SelectFontFace (Font.Name, Font.Slant, Font.Wheight);
                        gr.SetFontSize (Font.Size);
@@ -559,8 +552,8 @@ namespace Crow.Coding
                                Color selbg = this.SelectionBackground;
                                Color selfg = this.SelectionForeground;
 
-                               if (formating.ContainsKey ((int)tokens [t].Type)) {
-                                       TextFormating tf = formating [(int)tokens [t].Type];
+                               if (formatting.ContainsKey ((int)tokens [t].Type)) {
+                                       TextFormatting tf = formatting [(int)tokens [t].Type];
                                        bg = tf.Background;
                                        fg = tf.Foreground;
                                }
@@ -606,6 +599,43 @@ namespace Crow.Coding
                                lPtr += lstr.Length;
                        }
                }
+               #endregion
+
+               #region GraphicObject overrides
+               public override Font Font {
+                       get { return base.Font; }
+                       set {
+                               base.Font = value;
+
+                               using (ImageSurface img = new ImageSurface (Format.Argb32, 1, 1)) {
+                                       using (Context gr = new Context (img)) {
+                                               gr.SelectFontFace (Font.Name, Font.Slant, Font.Wheight);
+                                               gr.SetFontSize (Font.Size);
+
+                                               fe = gr.FontExtents;
+                                       }
+                               }
+                               MaxScrollY = 0;
+                               RegisterForGraphicUpdate ();
+                       }
+               }
+               protected override int measureRawSize(LayoutingType lt)
+               {
+                       if (lt == LayoutingType.Height)
+                               return (int)Math.Ceiling(fe.Height * buffer.Length) + Margin * 2;
+
+                       return (int)(fe.MaxXAdvance * buffer.longestLineCharCount) + Margin * 2;
+               }
+               public override void OnLayoutChanges (LayoutingType layoutType)
+               {
+                       base.OnLayoutChanges (layoutType);
+
+                       if (layoutType == LayoutingType.Height)
+                               updateVisibleLines ();
+                       else if (layoutType == LayoutingType.Width)
+                               updateVisibleColumns ();
+               }
+
                protected override void onDraw (Context gr)
                {
                        base.onDraw (gr);
@@ -910,39 +940,5 @@ namespace Crow.Coding
                        System.Diagnostics.Debug.WriteLine ("update visible columns: " + visibleColumns);
                        System.Diagnostics.Debug.WriteLine ("update MaxScrollX: " + MaxScrollX);
                }
-
-
-
-               /// <summary>
-               /// Insert new string at caret position, should be sure no line break is inside.
-               /// </summary>
-               /// <param name="str">String.</param>
-               protected void Insert(string str)
-               {
-                       if (!selectionIsEmpty)
-                               this.DeleteChar ();
-                       string[] strLines = Regex.Split (str, "\r\n|\r|\n|" + @"\\n").ToArray();
-                       buffer [CurrentLine] = buffer [CurrentLine].Insert (CurrentColumn, strLines[0]);
-                       CurrentColumn += strLines[0].Length;
-                       for (int i = 1; i < strLines.Length; i++) {
-                               InsertLineBreak ();
-                               buffer [CurrentLine] = buffer [CurrentLine].Insert (CurrentColumn, strLines[i]);
-                               CurrentColumn += strLines[i].Length;
-                       }
-                       OnTextChanged (this, null);
-                       RegisterForGraphicUpdate();
-               }
-
-               /// <summary>
-               /// Insert a line break.
-               /// </summary>
-               protected void InsertLineBreak()
-               {
-                       buffer.Insert(CurrentLine + 1, buffer[CurrentLine].Substring(CurrentColumn));
-                       buffer [CurrentLine] = buffer [CurrentLine].Substring (0, CurrentColumn);
-                       CurrentLine++;
-                       CurrentColumn = 0;
-                       OnTextChanged (this, null);
-               }
        }
 }
\ No newline at end of file
diff --git a/src/TextFormatting.cs b/src/TextFormatting.cs
new file mode 100644 (file)
index 0000000..64e7aea
--- /dev/null
@@ -0,0 +1,15 @@
+using System;
+
+namespace Crow.Coding
+{
+       public struct TextFormatting {
+               public Color Foreground;
+               public Color Background;
+
+               public TextFormatting(Color fg, Color bg){
+                       Foreground = fg;
+                       Background = bg;
+               }
+       }
+}
+
index 6e4a3ea111ee52c001d14738744218e487117681..011857119d6ebc8a68cafde6e282907d2c0df082 100644 (file)
@@ -8,11 +8,6 @@ namespace Crow.Coding
 {
        public class XMLParser : Parser
        {
-
-               public XMLParser (CodeTextBuffer _buffer) : base(_buffer)
-               {
-               }
-
                public new enum TokenType {
                        Unknown = Parser.TokenType.Unknown,
                        WhiteSpace = Parser.TokenType.WhiteSpace,
@@ -30,6 +25,7 @@ namespace Crow.Coding
                        AttributeValueClosing = Parser.TokenType.StringLitteralClosing,
                        AttributeValue = Parser.TokenType.StringLitteral,
                }
+
                public enum States
                {
                        init,       //first statement of prolog, xmldecl should only apear in this state
@@ -38,12 +34,16 @@ namespace Crow.Coding
                        ExternalSubsetInit,
                        ExternalSubset,
                        DTDEnd,//doctype finished
-                       XML,
-                       StartTag,
-                       Content,
-                       EndTag,
-                       XMLEnd
+                       XML,//normal xml
+                       StartTag,//inside start tag
+                       Content,//after start tag with no closing slash
+                       EndTag
                }
+
+               #region CTOR
+               public XMLParser (CodeBuffer _buffer) : base(_buffer) {}
+               #endregion
+
                enum Keywords
                {
                        DOCTYPE,
@@ -97,10 +97,10 @@ namespace Crow.Coding
 //             }
                #endregion
 
-               public override void SetLineInError (int lineNumber)
+               public override void SetLineInError (ParsingException ex)
                {
-                       base.SetLineInError (lineNumber);
-                       Tokens[lineNumber].EndingState = (int)States.init;
+                       base.SetLineInError (ex);
+                       Tokens[ex.Line].EndingState = (int)States.init;
                }
 
                public override void Parse (int line)
@@ -112,16 +112,14 @@ namespace Crow.Coding
                        eof = false;
                        bool eol = false;
 
+                       //retrieve current parser state from previous line
                        if (line > 0)
                                curState = (States)Tokens [line - 1].EndingState;
                        else
                                curState = States.init;
 
-                       TokensLine = Tokens [line];
-
-                       States previousEndingState = (States)TokensLine.EndingState;
-
-                       TokensLine.Clear ();
+                       States previousEndingState = (States)Tokens[line].EndingState;
+                       Tokens[line].Clear ();
 
 
 
@@ -244,10 +242,8 @@ namespace Crow.Coding
                                }
                        }
 
-                       TokensLine.EndingState = (int)curState;
-                       TokensLine.Dirty = false;
-
-                       Debug.WriteLine ("\tState:{0}->{1}", previousEndingState, curState);
+                       Tokens[line].EndingState = (int)curState;
+                       Tokens [line].Dirty = false;
 
                        if (previousEndingState != curState && line < Tokens.Count - 1)
                                Tokens [line + 1].Dirty = true;