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 ();
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)
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;
InternalSubset, //doctype declaration subset
ExternalSubsetInit,
ExternalSubset,
+ BlockComment,
DTDEnd,//doctype finished
XML,//normal xml
StartTag,//inside start tag
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;
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: