]> O.S.I.I.S - jp/crowedit.git/commitdiff
block comment handling, multiline debug
authorJean-Philippe Bruyère <jp_bruyere@hotmail.com>
Thu, 31 Aug 2017 14:46:02 +0000 (16:46 +0200)
committerJean-Philippe Bruyère <jp_bruyere@hotmail.com>
Thu, 31 Aug 2017 14:46:02 +0000 (16:46 +0200)
src/Parser.cs
src/SourceEditor.cs
src/XMLParser.cs

index a72746dedf9b3c40a7906114b16517201d4522d5..90caa30fbc0fee0f6db322a4c1062eb7ca34e269 100644 (file)
@@ -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)
index ea5b32ac8046a646e1c415690692e93e87cd25f9..1f6ae638fa2a30210f9f4e5f019c1dfa55c00731 100644 (file)
@@ -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;
index 29f57b31b6dc02fbfbbd6e4fa1cc7d4389b4eb63..36a96e740b2fa27f372bbd5fc7bb9209d37e8da4 100644 (file)
@@ -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: