protected bool eof = true;
public List<TokenList> Tokens;
+ protected TokenList TokensLine;
public Point CurrentPosition { get { return new Point (currentLine, currentColumn); } }
currentTok.Start = CurrentPosition;
currentTok += Read();
}
+ protected void readToCurrTok(int length) {
+ for (int i = 0; i < length; i++)
+ currentTok += Read ();
+ }
protected void readAndResetCurrentTok(System.Enum type, bool startToc = false) {
readToCurrTok ();
saveAndResetCurrentTok (type);
protected void saveAndResetCurrentTok(System.Enum type) {
currentTok.Type = (TokenType)type;
currentTok.End = CurrentPosition;
- Tokens[currentLine].Add (currentTok);
+ TokensLine.Add (currentTok);
currentTok = default(Token);
}
protected virtual char Peek() {
currentColumn++;
return c;
}
- protected virtual string ReadUntil (string endExp){
+ protected virtual string ReadLineUntil (string endExp){
string tmp = "";
while (!eof) {
- if (buffer [currentLine].Length - currentColumn - endExp.Length < 0) {
- currentLine++;
- if (currentLine >= buffer.Length)
- eof = true;
- currentColumn = 0;
- continue;
- }
+ if (buffer [currentLine].Length - currentColumn - endExp.Length < 0)
+ break;
if (string.Equals (Peek (endExp.Length), endExp))
return tmp;
tmp += Read();
#region CTOR
public SourceEditor ():base()
{
- 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));
-
- 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));
+ formatting.Add ((int)XMLParser.TokenType.AttributeName, new TextFormatting (Color.UnitedNationsBlue, Color.Transparent));
+ formatting.Add ((int)XMLParser.TokenType.ElementName, new TextFormatting (Color.DarkBlue, Color.Transparent, true));
+ formatting.Add ((int)XMLParser.TokenType.ElementStart, new TextFormatting (Color.Red, Color.Transparent,true));
+ formatting.Add ((int)XMLParser.TokenType.ElementEnd, new TextFormatting (Color.Red, Color.Transparent,true));
+ formatting.Add ((int)XMLParser.TokenType.ElementClosing, new TextFormatting (Color.Red, Color.Transparent, true));
+ formatting.Add ((int)XMLParser.TokenType.Affectation, new TextFormatting (Color.Red, Color.Transparent, true));
+
+ 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));
buffer = new CodeBuffer ();
buffer.LineUpadateEvent += Buffer_LineUpadateEvent;
Point _selBegin = -1; //selection start (row,column)
Point _selRelease = -1; //selection end (row,column)
- Dictionary<int,TextFormatting> formatting = new Dictionary<int, TextFormatting>();
+ Dictionary<int, TextFormatting> formatting = new Dictionary<int, TextFormatting>();
protected Rectangle rText;
protected FontExtents fe;
Color fg = this.Foreground;
Color selbg = this.SelectionBackground;
Color selfg = this.SelectionForeground;
+ FontSlant fts = FontSlant.Normal;
+ FontWeight ftw = FontWeight.Normal;
if (formatting.ContainsKey ((int)tokens [t].Type)) {
TextFormatting tf = formatting [(int)tokens [t].Type];
bg = tf.Background;
fg = tf.Foreground;
+ if (tf.Bold)
+ ftw = FontWeight.Bold;
+ if (tf.Italic)
+ fts = FontSlant.Italic;
}
+ gr.SelectFontFace (Font.Name, fts, ftw);
gr.SetSourceColor (fg);
int x = cb.X + (int)((lPtr - ScrollX) * fe.MaxXAdvance);
CurrentLine--;
else
CurrentLine = ScrollY + (int)Math.Floor (mouseLocalPos.Y / fe.Height);
+
+ CurrentPosition = buffer.VisualPosition; //for rounding if in middle of tabs
}
public override void onMouseEnter (object sender, MouseMoveEventArgs e)
{
currentColumn = 0;
eof = false;
bool eol = false;
+ TokensLine = Tokens [line];
//retrieve current parser state from previous line
if (line > 0)
else
curState = States.init;
- States previousEndingState = (States)Tokens[line].EndingState;
- Tokens[line].Clear ();
-
-
+ States previousEndingState = (States)TokensLine.EndingState;
+ TokensLine.Clear ();
while (! (eof||eol)) {
SkipWhiteSpaces ();
if (curState != States.init)
throw new ParsingException (this, "prolog may appear only on first line");
readToCurrTok ();
- currentTok += ReadUntil ("?>");
+ currentTok += ReadLineUntil ("?>");
+ readToCurrTok (2);
saveAndResetCurrentTok (TokenType.XMLDecl);
curState = States.prolog;
break;
readToCurrTok ();
if (Peek () != '-')
throw new ParsingException (this, "Expecting comment start tag");
- currentTok += ReadUntil ("--");
+ currentTok += ReadLineUntil ("--");
if (Peek () != '>')
throw new ParsingException (this, "Expecting comment closing tag");
readAndResetCurrentTok (TokenType.BlockComment);
}
break;
default:
- if (!(curState == States.Content || curState == States.XML || curState == States.init))
+ if (!(curState == States.Content || curState == States.XML || curState == States.init || curState == States.prolog))
throw new ParsingException (this, "Unexpected char: '<'");
if (Peek () == '/') {
curState = States.EndTag;
readAndResetCurrentTok (TokenType.AttributeValueOpening, true);
currentTok.Start = CurrentPosition;
- currentTok.Content = ReadUntil (new string (new char[]{ openAttVal }));
+ currentTok.Content = ReadLineUntil (new string (new char[]{ openAttVal }));
saveAndResetCurrentTok (TokenType.AttributeValue);
if (Peek () != openAttVal)
}
}
- Tokens[line].EndingState = (int)curState;
- Tokens [line].Dirty = false;
+ TokensLine.EndingState = (int)curState;
+ TokensLine.Dirty = false;
if (previousEndingState != curState && line < Tokens.Count - 1)
Tokens [line + 1].Dirty = true;