<Compile Include="src\TextFormatting.cs" />
<Compile Include="ParsingException.cs" />
<Compile Include="CodeBufferEventArgs.cs" />
+ <Compile Include="src\Node.cs" />
</ItemGroup>
<ItemGroup>
<Folder Include="ui\" />
{
throw new NotImplementedException ();
}
+ public override void SyntaxAnalysis ()
+ {
+ throw new NotImplementedException ();
+ }
}
}
--- /dev/null
+using System;
+using System.Collections.Generic;
+
+namespace Crow.Coding
+{
+ public class Node
+ {
+ public Node Parent;
+ public string Name;
+ public string Type;
+ public int StartLine;
+ public int EndLine;
+ public Dictionary<string,string> Attributes = new Dictionary<string, string> ();
+
+ public List<Node> Children = new List<Node>();
+
+ public Node ()
+ {
+ }
+
+ public void AddChild (Node child) {
+ child.Parent = this;
+ Children.Add (child);
+ }
+
+ public override string ToString ()
+ {
+ return string.Format ("Name:{0}, Type:{1}\n\tparent:{2}", Name, Type, Parent);
+ }
+ }
+}
+
}
reparseSource ();
}
-
void Buffer_LineRemoveEvent (object sender, CodeBufferEventArgs e)
{
for (int i = 0; i < e.LineCount; i++)
Tokens.RemoveAt (e.LineStart + i);
reparseSource ();
}
-
void Buffer_LineUpadateEvent (object sender, CodeBufferEventArgs e)
{
for (int i = 0; i < e.LineCount; i++)
if (Tokens[i].Dirty)
tryParseBufferLine (i);
}
- updateFolding ();
+ try {
+ SyntaxAnalysis ();
+ } catch (ParsingException ex) {
+ Debug.WriteLine ("Syntax Error: " + ex.ToString ());
+ SetLineInError (ex);
+ }
}
void tryParseBufferLine(int lPtr) {
try {
public List<TokenList> Tokens;
protected TokenList TokensLine;
+ public Node RootNode;
+
public Point CurrentPosition {
get { return new Point (currentLine, currentColumn); }
set {
}
public abstract void Parse(int line);
+ public abstract void SyntaxAnalysis ();
+
public virtual void SetLineInError(ParsingException ex) {
currentTok = default(Token);
Tokens [ex.Line] = new TokenList (ex, buffer [ex.Line]);
}
#endregion
- const int leftMarginGap = 0;//gap between items in margin and text
+ const int leftMarginGap = 2;//gap between items in margin and text
const int foldSize = 9;//folding rectangles size
#region private and protected fields
- bool foldingEnabled = false;
+ bool foldingEnabled = true;
string filePath = "unamed.txt";
int leftMargin = 0; //margin used to display line numbers, folding errors,etc...
int visibleLines = 1;
}
//draw folding
if (foldingEnabled){
- if (tokens.foldingTo != null) {
- gr.SetSourceColor (Color.Black);
- Rectangle rFld = new Rectangle (cb.X + leftMargin - leftMarginGap - foldSize, (int)(y + fe.Height / 2.0 - foldSize / 2.0), foldSize, foldSize);
- gr.Rectangle (rFld, 1.0);
- if (tokens.folded) {
- gr.MoveTo (rFld.Center.X + 0.5, rFld.Y + 2);
- gr.LineTo (rFld.Center.X + 0.5, rFld.Bottom - 2);
+ if (tokens.SyntacticNode != null) {
+ if (tokens.SyntacticNode.StartLine < tokens.SyntacticNode.EndLine) {
+ gr.SetSourceColor (Color.Black);
+ Rectangle rFld = new Rectangle (cb.X + leftMargin - leftMarginGap - foldSize, (int)(y + fe.Height / 2.0 - foldSize / 2.0), foldSize, foldSize);
+ gr.Rectangle (rFld, 1.0);
+ if (tokens.folded) {
+ gr.MoveTo (rFld.Center.X + 0.5, rFld.Y + 2);
+ gr.LineTo (rFld.Center.X + 0.5, rFld.Bottom - 2);
+ }
+ gr.MoveTo (rFld.Left + 2, rFld.Center.Y + 0.5);
+ gr.LineTo (rFld.Right - 2, rFld.Center.Y + 0.5);
+ gr.Stroke ();
}
- gr.MoveTo (rFld.Left + 2, rFld.Center.Y + 0.5);
- gr.LineTo (rFld.Right - 2, rFld.Center.Y + 0.5);
- gr.Stroke ();
}
}
public override void onMouseEnter (object sender, MouseMoveEventArgs e)
{
base.onMouseEnter (sender, e);
- currentInterface.MouseCursor = XCursor.Text;
+ if (e.X - ScreenCoordinates(Slot).X < leftMargin + ClientRectangle.X)
+ currentInterface.MouseCursor = XCursor.Default;
+ else
+ currentInterface.MouseCursor = XCursor.Text;
}
public override void onMouseLeave (object sender, MouseMoveEventArgs e)
{
{
base.onMouseMove (sender, e);
+ if (e.X - ScreenCoordinates(Slot).X < leftMargin + ClientRectangle.X)
+ currentInterface.MouseCursor = XCursor.Default;
+ else
+ currentInterface.MouseCursor = XCursor.Text;
+
if (!e.Mouse.IsButtonDown (MouseButton.Left))
return;
if (!HasFocus || SelBegin < 0)
return;
- if (e.X < leftMargin + ClientRectangle.X) {
- }
-
updatemouseLocalPos (e.Position);
SelRelease = CurrentPosition;
/// Folding state reside here because it's the highest level of abstraction line per line
/// </summary>
public bool folded = false;
- public TokenList foldingTo = null;
+ public Node SyntacticNode = null;
/// <summary>
/// if parsing issue error, exception is not null and tokenlist should contains only one token with line content and type = unknown
/// </summary>
public new void Clear() {
EndingState = 0;
folded = false;
- foldingTo = null;
+ SyntacticNode = null;
exception = null;
Dirty = true;
base.Clear ();
using System.Collections.Generic;
using System.Text.RegularExpressions;
using System.Diagnostics;
+using System.Linq;
namespace Crow.Coding
{
readToCurrTok (true);
if (Peek () != '>')
throw new ParsingException (this, "Expecting '>'");
- readAndResetCurrentTok (TokenType.ElementClosing);
+ readAndResetCurrentTok (TokenType.ElementEnd);
curState = States.XML;
break;
if (previousEndingState != curState && line < Tokens.Count - 1)
Tokens [line + 1].Dirty = true;
}
+
+ public override void SyntaxAnalysis ()
+ {
+ RootNode = new Node () { Name = "RootNode", Type="Root" };
+
+ Node currentNode = RootNode;
+
+ for (int i = 0; i < Tokens.Count; i++) {
+ TokenList curTL = Tokens [i];
+ curTL.SyntacticNode = null;
+
+ int tokPtr = 0;
+ while (tokPtr < curTL.Count) {
+ switch ((XMLParser.TokenType)curTL [tokPtr].Type) {
+ case TokenType.ElementStart:
+ tokPtr++;
+ Node newElt = new Node () { Name = curTL [tokPtr].Content, StartLine = i };
+ currentNode.AddChild (newElt);
+ currentNode = newElt;
+ if (curTL.SyntacticNode == null)
+ curTL.SyntacticNode = newElt;
+ break;
+ case TokenType.ElementEnd:
+ tokPtr++;
+ if (tokPtr < curTL.Count) {
+ if ((XMLParser.TokenType)curTL [tokPtr].Type == TokenType.ElementName && curTL [tokPtr].Content != currentNode.Name)
+ throw new ParsingException (this, "Closing tag mismatch");
+ }
+ currentNode.EndLine = i;
+ currentNode = currentNode.Parent;
+ break;
+ case TokenType.ElementClosing:
+ //currentNode = currentNode.Parent;
+ break;
+ default:
+ break;
+ }
+ tokPtr++;
+ }
+ }
+ }
}
}