Ejemplo n.º 1
0
		public Range Find(Range r, Regex findExpression, bool searchUp)
		{
			//	Single line and Multi Line in RegExp doesn't really effect
			//	whether or not a match will include newline charaters. This 
			//	means we can't do a line by line search. We have to search
			//	the entire range becuase it could potentially match the 
			//	entire range.
				
			Match m = findExpression.Match(r.Text);

			if (!m.Success)
				return null;

			if (searchUp)
			{
				//	Since we can't search backwards with RegExp we
				//	have to search the entire string and return the 
				//	last match. Not the most efficient way of doing
				//	things but it works.
				Range range = null;
				while (m.Success)
				{
					range = new Range(r.Start + m.Index, r.Start + m.Index + m.Length, Scintilla);
					m = m.NextMatch();
				}
				return range;
			}

			return new Range(r.Start + m.Index, r.Start + m.Index + m.Length, Scintilla);
		}
Ejemplo n.º 2
0
		public List<Range> FindAll(Range rangeToSearch, string searchString, SearchFlags flags)
		{
			return FindAll(rangeToSearch.Start, rangeToSearch.End, searchString, _flags);
		}
Ejemplo n.º 3
0
 public static void StyleNeeded(Scintilla scintilla, Range range)
 {
     // Create an instance of our lexer and bada-bing the line!
     IniLexer lexer = new IniLexer(scintilla, range.Start, range.StartingLine.Length);
     lexer.Style();
 }
Ejemplo n.º 4
0
		public Range Find(Range r, Regex findExpression)
		{
			return Find(r, findExpression, false);
		}
Ejemplo n.º 5
0
		public Range FindPrevious(Regex findExpression, bool wrap, Range searchRange)
		{
			int caret = Scintilla.Caret.Position;
			if (!searchRange.PositionInRange(caret))
				return Find(searchRange.Start, searchRange.End, findExpression, true);

			int anchor = Scintilla.Caret.Anchor;
			if (!searchRange.PositionInRange(anchor))
				anchor = caret;

			Range r = Find(searchRange.Start, anchor, findExpression, true);
			if (r != null)
				return r;
			else if (wrap)
				return Find(anchor, searchRange.End, findExpression, true);
			else
				return null;
		}
Ejemplo n.º 6
0
		public List<Range> ReplaceAll(Range rangeToSearch, Regex findExpression, string replaceString)
		{
			Scintilla.UndoRedo.BeginUndoAction();

			//	I tried using an anonymous delegate for this but it didn't work too well.
			//	It's too bad because it was a lot cleaner than using member variables as
			//	psuedo globals.
			_lastReplaceAllMatches = new List<Range>();
			_lastReplaceAllReplaceString = replaceString;
			_lastReplaceAllRangeToSearch = rangeToSearch;
			_lastReplaceAllOffset = 0;

			findExpression.Replace(rangeToSearch.Text, new MatchEvaluator(replaceAllEvaluator));

			Scintilla.UndoRedo.EndUndoAction();
			
			//	No use having these values hanging around wasting memory :)
			List<Range> ret = _lastReplaceAllMatches;
			_lastReplaceAllMatches = null;
			_lastReplaceAllReplaceString = null;
			_lastReplaceAllRangeToSearch = null;
			
			return ret;
		}
Ejemplo n.º 7
0
		public Range Search(Range searchRange)
		{
			int foundStart = NativeScintilla.IndicatorEnd(_number, searchRange.Start);
			int foundEnd = NativeScintilla.IndicatorEnd(_number, foundStart);
			if (foundStart < 0 || foundStart > searchRange.End || foundStart == foundEnd)
				return null;


			return new Range(foundStart, foundEnd, Scintilla);
		}
Ejemplo n.º 8
0
		public Range FindNext(Regex findExpression, bool wrap, Range searchRange)
		{
			int caret = Scintilla.Caret.Position;
			if (!searchRange.PositionInRange(caret))
				return Find(searchRange.Start, searchRange.End, findExpression, false);

			Range r = Find(caret, searchRange.End, findExpression);
			if (r != null)
				return r;
			else if (wrap)
				return Find(searchRange.Start, caret, findExpression);
			else
				return null;
		}
Ejemplo n.º 9
0
 public bool IntersectsWith(Range otherRange)
 {
     return otherRange.PositionInRange(_start) | otherRange.PositionInRange(_end) | PositionInRange(otherRange.Start) | PositionInRange(otherRange.End);
 }
Ejemplo n.º 10
0
 /// <summary>
 /// Initializes a new instance of the StyleNeededEventArgs class.
 /// </summary>
 /// <param name="range">the document range that needs styling</param>
 public StyleNeededEventArgs(Range range)
 {
     _range = range;
 }
Ejemplo n.º 11
0
 protected internal ManagedRange(Range range)
     : this(range.Start, range.End, range.Scintilla)
 {
 }
Ejemplo n.º 12
0
 /// <summary>
 /// Copies the contents of a given range to the clipboard.
 /// </summary>
 /// <param name="rangeToCopy">Range of text to copy</param>
 public void Copy(Range rangeToCopy)
 {
     Copy(rangeToCopy.Start, rangeToCopy.End);
 }
        public override bool ExamineSource(ChameleonEditor ed, ScintillaNet.Range searchRange)
        {
            m_checkSucceeded = false;

            ANTLRParser parser = Singleton <ANTLRParser> .Instance;

            if (!parser.ParseCompleted)
            {
                return(false);
            }


            ASTNode root = parser.GetAST();

            List <ASTNode> conditions = (from n in root.Descendants()
                                         where n.text == "condition"
                                         select n).ToList();

            string astText = root.ASTToString();

            foreach (ASTNode condition in conditions)
            {
                List <ASTNode> assignments = (from n in condition.Descendants()
                                              where n.text == "assign" || n.text == "="
                                              select n).ToList();

                if (assignments.Count > 0)
                {
                    foreach (ASTNode assignment in assignments)
                    {
                        int    actualLine = searchRange.StartingLine.Number + assignment.lineNumber - 1;
                        string errorText  = "Assignment not allowed in boolean conditions";

                        AddError(ed, actualLine, errorText);
                    }
                }
            }

            List <ASTNode> whiles = (from n in root.Descendants()
                                     where n.text == "while"
                                     select n).ToList();

            foreach (ASTNode wh in whiles)
            {
                if (wh.firstChild.text != "condition")
                {
                    List <ASTNode> pieces = new List <ASTNode>();

                    Func <ASTNode, bool> getWhilePieces = (node =>
                    {
                        bool keepGoing = true;
                        if (node.text == "body")
                        {
                            keepGoing = false;
                        }
                        else
                        {
                            pieces.Add(node);
                        }

                        return(keepGoing);
                    });

                    wh.TraverseAST(false, getWhilePieces);

                    List <ASTNode> assignmentPieces = pieces.Where(node => node.text == "assign" ||
                                                                   node.text == "=").ToList();

                    if (assignmentPieces.Count > 0)
                    {
                        foreach (ASTNode assignmentPiece in assignmentPieces)
                        {
                            int    actualLine = searchRange.StartingLine.Number + assignmentPiece.lineNumber - 1;
                            string errorText  = "Assignment not allowed in boolean conditions";

                            AddError(ed, actualLine, errorText);
                        }
                    }
                }
            }

            m_checkSucceeded = true;
            return(m_checkSucceeded);
        }
Ejemplo n.º 14
0
		public List<Range> FindAll(Range rangeToSearch, Regex findExpression)
		{
			List<Range> res = new List<Range>();

			while (true)
			{
				Range r = Find(rangeToSearch, findExpression);
				if (r == null)
				{
					break;
				}
				else
				{
					res.Add(r);
					rangeToSearch = new Range(r.End, rangeToSearch.End, Scintilla);
				}
			}
			return res;
		}
Ejemplo n.º 15
0
		public Range Search(Range searchRange, Range startingAfterRange)
		{
			int start = startingAfterRange.End;
			if (start > NativeScintilla.GetTextLength())
				return null;

			int foundStart = NativeScintilla.IndicatorEnd(_number, start);
			int foundEnd = NativeScintilla.IndicatorEnd(_number, foundStart);
			if (foundStart < 0 || foundStart > searchRange.End || foundStart == foundEnd)
				return null;
			
			return new Range(foundStart, foundEnd, Scintilla);
		}
Ejemplo n.º 16
0
		public Range FindNext(string searchString, bool wrap, SearchFlags flags, Range searchRange)
		{
			int caret = Scintilla.Caret.Position;
			if (!searchRange.PositionInRange(caret))
				return Find(searchRange.Start, searchRange.End, searchString, flags);

			Range r = Find(caret, searchRange.End, searchString, flags);
			if (r != null)
				return r;
			else if (wrap)
				return Find(searchRange.Start, caret, searchString, flags);
			else
				return null;
		}
Ejemplo n.º 17
0
		public List<Range> SearchAll(Range searchRange)
		{
			Range foundRange = Scintilla.GetRange(-1, -1);

			List<Range> ret = new List<Range>();
			do
			{
				foundRange = Search(searchRange, foundRange);
				if (foundRange != null)
					ret.Add(foundRange);
			}
			while (foundRange != null);
			return ret;
		}
Ejemplo n.º 18
0
		public Range FindPrevious(string searchString, bool wrap, SearchFlags flags, Range searchRange)
		{
			int caret = Scintilla.Caret.Position;
			if (!searchRange.PositionInRange(caret))
				return Find(searchRange.End, searchRange.Start, searchString, flags);

			int anchor = Scintilla.Caret.Anchor;
			if (!searchRange.PositionInRange(anchor))
			    anchor = caret;

			Range r = Find(anchor, searchRange.Start, searchString, flags);
			if (r != null)
				return r;
			else if (wrap)
				return Find(searchRange.End, anchor, searchString, flags);
			else
				return null;
		}
Ejemplo n.º 19
0
		public Range Find(Range rangeToSearch, string searchString, SearchFlags searchflags)
		{
			return Find(rangeToSearch.Start, rangeToSearch.End, searchString, searchflags);
		}
Ejemplo n.º 20
0
		public List<Range> ReplaceAll(Range rangeToSearch, string searchString, string replaceString, SearchFlags flags)
		{
			return ReplaceAll(rangeToSearch.Start, rangeToSearch.End, searchString, replaceString, _flags);
		}
Ejemplo n.º 21
0
		public Range Find(Range rangeToSearch, string searchString, SearchFlags searchflags, bool searchUp)
		{
			if (searchUp)
				return Find(rangeToSearch.End, rangeToSearch.Start, searchString, searchflags);
			else
				return Find(rangeToSearch.Start, rangeToSearch.End, searchString, searchflags);
		}
Ejemplo n.º 22
0
		private string replaceAllEvaluator(Match m)
		{
			//	So this method is called for every match

			//	We make a replacement in the range based upon
			//	the match range.
			string replacement = m.Result(_lastReplaceAllReplaceString);
			int start = _lastReplaceAllRangeToSearch.Start + m.Index + _lastReplaceAllOffset;
			int end = start + m.Length;

			Range r = new Range(start, end, Scintilla);
			_lastReplaceAllMatches.Add(r);
			r.Text = replacement;

			//	But because we've modified the document, the RegEx
			//	match ranges are going to be different from the
			//	document ranges. We need to compensate
			_lastReplaceAllOffset += replacement.Length - m.Value.Length;
			return replacement;
		}
Ejemplo n.º 23
0
 public StyleNeededEventArgs(Range range)
 {
     _range = range;
 }