aboutsummaryrefslogtreecommitdiffstatsci
path: root/CrowIDE/src/SourceEditor/CodeLine.cs
blob: 612cac7388d11e4415392b66603b8188b3725cb5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
using System;
using System.Text;
using System.Collections.Generic;

namespace Crow.Coding
{
	public class CodeLine
	{
		public string Content;
		public List<Token> Tokens;
		public int EndingState = 0;
		public Node SyntacticNode;
		public ParserException exception;

		public CodeLine (string _content){
			Content = _content;
			Tokens = null;
			exception = null;
		}

		public char this[int i]
		{
			get { return Content[i]; }
			set {
				if (Content [i] == value)
					return;
				StringBuilder sb = new StringBuilder(Content);
				sb[i] = value;
				Content = sb.ToString();
				Tokens = null;
				//LineUpadateEvent.Raise (this, new CodeBufferEventArgs (i));
			}
		}
		public bool IsFoldable { get { return SyntacticNode != null; } }
		public bool IsFolded = false;
		public bool IsParsed {
			get { return Tokens != null; }
		}
		public string PrintableContent {
			get {
				return string.IsNullOrEmpty (Content) ? "" : Content.Replace ("\t", new String (' ', Interface.TabSize));
			}
		}
		public int PrintableLength {
			get {
				return PrintableContent.Length;
			}
		}
		public int Length {
			get {
				return string.IsNullOrEmpty (Content) ? 0 : Content.Length;
			}
		}

		public void SetLineInError (ParserException ex) {
			Tokens = null; 
			exception = ex;
		}

//		public static implicit operator string(CodeLine sl) {
//			return sl == null ? "" : sl.Content;
//		}
		public static implicit operator CodeLine(string s) {
			return new CodeLine(s);
		}
		public static bool operator ==(string s1, CodeLine s2)
		{
			return string.Equals (s1, s2.Content);
		}
		public static bool operator !=(string s1, CodeLine s2)
		{
			return !string.Equals (s1, s2.Content);
		}
	}
}