From: Jean-Philippe Bruyère Date: Thu, 31 Aug 2017 14:46:02 +0000 (+0200) Subject: block comment handling, multiline debug X-Git-Url: https://git.osiis.dedyn.io/?a=commitdiff_plain;h=19e5f44cb4542d09cd95e4c9b9d3c0f75711c935;p=jp%2Fcrowedit.git block comment handling, multiline debug --- diff --git a/src/Parser.cs b/src/Parser.cs index a72746d..90caa30 100644 --- a/src/Parser.cs +++ b/src/Parser.cs @@ -89,9 +89,10 @@ namespace Crow.Coding protected virtual string Peek(int length) { if (eof) throw new ParsingException (this, "Unexpected End of File"); - if (buffer[currentLine].Length - currentColumn - length < 0) - throw new ParsingException (this, "Unexpected End of line"); - return buffer [currentLine].Substring (currentColumn, length); + int lg = Math.Min(length, Math.Max (buffer [currentLine].Length - currentColumn, buffer [currentLine].Length - currentColumn - length)); + if (lg == 0) + return ""; + return buffer [currentLine].Substring (currentColumn, lg); } protected virtual char Read() { char c = Peek (); @@ -105,17 +106,28 @@ namespace Crow.Coding currentColumn++; return c; } + protected virtual string ReadLine () { + string tmp = ""; + while (!eof) { + if (Peek () == '\n') + return tmp; + tmp += Read (); + } + return tmp; + } protected virtual string ReadLineUntil (string endExp){ string tmp = ""; while (!eof) { - if (buffer [currentLine].Length - currentColumn - endExp.Length < 0) + if (buffer [currentLine].Length - currentColumn - endExp.Length < 0) { + tmp += ReadLine(); break; + } if (string.Equals (Peek (endExp.Length), endExp)) return tmp; tmp += Read(); } - throw new ParsingException (this, string.Format("Expectign '{0}'", endExp)); + return tmp; } protected void SkipWhiteSpaces () { if (currentTok.Type != TokenType.Unknown) diff --git a/src/SourceEditor.cs b/src/SourceEditor.cs index ea5b32a..1f6ae63 100644 --- a/src/SourceEditor.cs +++ b/src/SourceEditor.cs @@ -56,7 +56,8 @@ namespace Crow.Coding formatting.Add ((int)XMLParser.TokenType.AttributeValueOpening, new TextFormatting (Color.DarkPink, Color.Transparent,true)); formatting.Add ((int)XMLParser.TokenType.AttributeValueClosing, new TextFormatting (Color.DarkPink, Color.Transparent,true)); formatting.Add ((int)XMLParser.TokenType.AttributeValue, new TextFormatting (Color.DarkPink, Color.Transparent, false, true)); - formatting.Add ((int)XMLParser.TokenType.XMLDecl, new TextFormatting (Color.SeaGreen, Color.Transparent, true)); + formatting.Add ((int)XMLParser.TokenType.XMLDecl, new TextFormatting (Color.BlueCrayola, Color.Transparent, true)); + formatting.Add ((int)XMLParser.TokenType.BlockComment, new TextFormatting (Color.Gray, Color.Transparent, false, true)); buffer = new CodeBuffer (); buffer.LineUpadateEvent += Buffer_LineUpadateEvent; diff --git a/src/XMLParser.cs b/src/XMLParser.cs index 29f57b3..36a96e7 100644 --- a/src/XMLParser.cs +++ b/src/XMLParser.cs @@ -33,6 +33,7 @@ namespace Crow.Coding InternalSubset, //doctype declaration subset ExternalSubsetInit, ExternalSubset, + BlockComment, DTDEnd,//doctype finished XML,//normal xml StartTag,//inside start tag @@ -128,21 +129,40 @@ namespace Crow.Coding if (eof) break; - switch (Peek()) { - case '\n': + if (Peek () == '\n') { if (currentTok != TokenType.Unknown) throw new ParsingException (this, "Unexpected end of line"); Read (); eol = true; - break; + continue; + } + + if (curState == States.BlockComment) { + if (currentTok != TokenType.Unknown) + Debugger.Break (); + + currentTok.Start = CurrentPosition; + currentTok.Type = (Parser.TokenType)TokenType.BlockComment; + currentTok += ReadLineUntil ("-->"); + if (Peek (3) == "-->") { + readToCurrTok (3); + curState = States.XML; + } + saveAndResetCurrentTok (); + continue; + } + + switch (Peek()) { case '<': readToCurrTok (true); switch (Peek()) { case '?': if (curState != States.init) - throw new ParsingException (this, "prolog may appear only on first line"); + throw new ParsingException (this, "xml decl may appear only on first line"); readToCurrTok (); currentTok += ReadLineUntil ("?>"); + if (Peek (2) != "?>") + throw new ParsingException (this, "expecting '?>'"); readToCurrTok (2); saveAndResetCurrentTok (TokenType.XMLDecl); curState = States.prolog; @@ -154,13 +174,16 @@ namespace Crow.Coding readToCurrTok (); if (Peek () != '-') throw new ParsingException (this, "Expecting comment start tag"); + readToCurrTok (); currentTok += ReadLineUntil ("--"); - if (Peek () != '>') - throw new ParsingException (this, "Expecting comment closing tag"); - readAndResetCurrentTok (TokenType.BlockComment); + if (Peek (3) == "-->") { + readToCurrTok (3); + }else + curState = States.BlockComment; + saveAndResetCurrentTok (TokenType.BlockComment); break; default: - throw new NotImplementedException (); + throw new ParsingException(this, "error"); } break; default: