Esempio n. 1
0
            protected override bool ScanSpanEnd(Mono.TextEditor.Highlighting.Span cur, ref int i)
            {
                if (spanStack.Any(s => s is CodeDeclarationSpan) && i + 9 <= doc.TextLength && doc.GetTextAt(i, 9) == "</script>")
                {
                    while (!(spanStack.Peek() is CodeDeclarationSpan))
                    {
                        FoundSpanEnd(spanStack.Peek(), i, 0);
                    }
                    cur = spanStack.Peek();
                    FoundSpanEnd(cur, i, "</script>".Length);
                    i += "</script>".Length - 1;
                    return(true);
                }

                if (spanStack.Any(s => s is CodeExpressionSpan) && i + 2 < doc.TextLength && doc.GetTextAt(i, 2) == "%>")
                {
                    while (!(spanStack.Peek() is CodeExpressionSpan))
                    {
                        FoundSpanEnd(spanStack.Peek(), i, 0);
                    }
                    cur = spanStack.Peek();
                    FoundSpanEnd(cur, i, 2);
                    return(true);
                }
                return(base.ScanSpanEnd(cur, ref i));
            }
Esempio n. 2
0
            protected override bool ScanSpanEnd(Mono.TextEditor.Highlighting.Span cur, ref int i)
            {
                if (cur is IfBlockSpan || cur is ElseIfBlockSpan || cur is ElseBlockSpan)
                {
                    int  textOffset = i - StartOffset;
                    bool end        = CurText.IsAt(textOffset, "#endif");
                    if (end)
                    {
                        FoundSpanEnd(cur, i, 6);                          // put empty end tag in

                        // if we're in a complex span stack pop it up to the if block
                        if (spanStack.Count > 0)
                        {
                            var prev = spanStack.Peek();

                            if ((cur is ElseIfBlockSpan || cur is ElseBlockSpan) && (prev is ElseIfBlockSpan || prev is IfBlockSpan))
                            {
                                PopCurrentIfBlock();
                            }
                        }
                    }
                    return(end);
                }
                return(base.ScanSpanEnd(cur, ref i));
            }
Esempio n. 3
0
 protected override bool ScanSpanEnd(Mono.TextEditor.Highlighting.Span cur, ref int i)
 {
     if (cur is IfBlockSpan || cur is ElseIfBlockSpan || cur is ElseBlockSpan)
     {
         int  textOffset = i - StartOffset;
         bool end        = CurText.IsAt(textOffset, "#endif");
         if (end)
         {
             FoundSpanEnd(cur, i, 6);                          // put empty end tag in
             while (spanStack.Count > 0 && (spanStack.Peek() is IfBlockSpan || spanStack.Peek() is ElseIfBlockSpan || spanStack.Peek() is ElseBlockSpan))
             {
                 spanStack.Pop();
                 if (ruleStack.Count > 1)                             // rulStack[1] is always syntax mode
                 {
                     ruleStack.Pop();
                 }
             }
         }
         return(end);
     }
     return(base.ScanSpanEnd(cur, ref i));
 }
            protected override bool ScanSpanEnd(Mono.TextEditor.Highlighting.Span cur, ref int i)
            {
                if (cur is IfBlockSpan || cur is ElseIfBlockSpan || cur is ElseBlockSpan)
                {
                    bool end = i + 6 <= doc.Length && doc.GetTextAt(i, 6) == "#endif";
                    if (end)
                    {
                        OnFoundSpanEnd(cur, i, 6);                          // put empty end tag in
                        while (spanStack.Count > 0 && !(spanStack.Peek() is IfBlockSpan))
                        {
                            spanStack.Pop();
                            if (ruleStack.Count > 1)                             // rulStack[1] is always syntax mode
                            {
                                ruleStack.Pop();
                            }
                        }
                        if (spanStack.Count > 0)
                        {
                            spanStack.Pop();
                        }
                        if (ruleStack.Count > 1)                         // rulStack[1] is always syntax mode
                        {
                            ruleStack.Pop();
                        }

                        /*	// put pre processor eol span on stack, so that '#endif' gets the correct highlight
                         *      foreach (Span span in mode.Spans) {
                         *              if (span.Rule == "text.preprocessor") {
                         *                      OnFoundSpanBegin (span, i, 6);
                         *                      spanStack.Push (span);
                         *                      ruleStack.Push (GetRule (span));
                         *                      break;
                         *              }
                         *      }*/
                    }
                    return(end);
                }
                return(base.ScanSpanEnd(cur, ref i));
            }
Esempio n. 5
0
 public FSharpSpanParser(Document doc, SyntaxMode mode, LineSegment line, Stack<Span> spanStack)
     : base(doc, mode, line, spanStack)
 {
     foreach (Span span in mode.Spans) {
         if (span.Rule == "text.preprocessor") {
             preprocessorSpan = span;
             preprocessorRule = GetRule (span);
         }
     }
 }
			bool EndsWithContinuation (Span span, LineSegment line)
			{
				return !span.StopAtEol || span.StopAtEol && !string.IsNullOrEmpty (span.Continuation) &&
					line != null && doc.GetTextAt (line).Trim ().EndsWith (span.Continuation);
			}
Esempio n. 7
0
			public void FoundSpanEnd (Span span, int offset, int length)
			{
				curChunk.Length = offset - curChunk.Offset;
				curChunk.Style  = GetStyle (curChunk) ?? GetChunkStyle (span);
				AddChunk (ref curChunk, 0, defaultStyle);

				curChunk.Offset = offset;
				curChunk.Length = length;
				curChunk.Style  = span.TagColor ?? GetChunkStyle (span);
				AddChunk (ref curChunk, 0, defaultStyle);
				spanParser.PopSpan ();
			}
Esempio n. 8
0
 protected override bool ScanSpanEnd(Span cur, ref int i)
 {
     return base.ScanSpanEnd(cur, ref i);
 }
Esempio n. 9
0
			protected virtual bool ScanSpanEnd (Span cur, ref int i)
			{
				int textOffset = i - StartOffset;
				
				if (cur.End != null) {
					RegexMatch match = cur.End.TryMatch (CurText, textOffset);
					if (match.Success) {
						FoundSpanEnd (cur, i, match.Length);
						i += match.Length - 1;
						return true;
					}
				}

				if (cur.Exit != null) {
					RegexMatch match = cur.Exit.TryMatch (CurText, textOffset);
					if (match.Success) {
						FoundSpanExit (cur, i, match.Length);
						i += match.Length - 1;
						return true;
					}
				}
				return false;
			}
Esempio n. 10
0
			public void FoundSpanBegin (Span span, int offset, int length)
			{
				curChunk.Length = offset - curChunk.Offset;
				curChunk.Style = GetStyle (curChunk);
				if (string.IsNullOrEmpty (curChunk.Style)) {
//					Span tmpSpan = spanParser.SpanStack.Count > 0 ? spanParser.SpanStack.Pop () : null;
					curChunk.Style = GetSpanStyle ();
//					if (tmpSpan != null)
//						spanParser.SpanStack.Push (tmpSpan);
				}
				AddChunk (ref curChunk, 0, curChunk.Style);

				Rule spanRule = spanParser.GetRule (span);
				
				if (spanRule == null)
					throw new Exception ("Rule " + span.Rule + " not found in " + span);
				spanParser.PushSpan (span, spanRule);

				curChunk.Offset = offset;
				curChunk.Length = length;
				curChunk.Style  = span.TagColor ?? GetChunkStyle (span);
				curChunk.SpanStack.Push (span);
				AddChunk (ref curChunk, 0, curChunk.Style);
				foreach (SemanticRule semanticRule in spanRule.SemanticRules) {
					semanticRule.Analyze (this.doc, line, curChunk, offset, line.EndOffset);
				}
			}
Esempio n. 11
0
			void DefaultFoundSpanBegin (Span span, int offset, int length)
			{
				PushSpan (span, GetRule (span));
			}
Esempio n. 12
0
			public void PushSpan (Span span, Rule rule)
			{
				spanStack.Push (span);
				ruleStack.Push (rule);
				this.CurRule = rule;
				this.CurSpan = span;
			}
Esempio n. 13
0
            protected override bool ScanSpanEnd(Mono.TextEditor.Highlighting.Span cur, ref int i)
            {
                JayBlockSpan jbs        = cur as JayBlockSpan;
                int          textOffset = i - StartOffset;

                if (jbs != null)
                {
                    if (CurText[textOffset] == '}')
                    {
                        int  brackets = 0;
                        bool isInString = false, isInChar = false, isVerbatimString = false;
                        bool isInLineComment = false, isInBlockComment = false;

                        for (int j = jbs.Offset; j <= i; j++)
                        {
                            char ch = doc.GetCharAt(j);
                            switch (ch)
                            {
                            case '\n':
                            case '\r':
                                isInLineComment = false;
                                if (!isVerbatimString)
                                {
                                    isInString = false;
                                }
                                break;

                            case '/':
                                if (isInBlockComment)
                                {
                                    if (j > 0 && doc.GetCharAt(j - 1) == '*')
                                    {
                                        isInBlockComment = false;
                                    }
                                }
                                else if (!isInString && !isInChar && j + 1 < doc.TextLength)
                                {
                                    char nextChar = doc.GetCharAt(j + 1);
                                    if (nextChar == '/')
                                    {
                                        isInLineComment = true;
                                    }
                                    if (!isInLineComment && nextChar == '*')
                                    {
                                        isInBlockComment = true;
                                    }
                                }
                                break;

                            case '\\':
                                if (isInChar || (isInString && !isVerbatimString))
                                {
                                    j++;
                                }
                                break;

                            case '@':
                                if (!(isInString || isInChar || isInLineComment || isInBlockComment) && j + 1 < doc.TextLength && doc.GetCharAt(j + 1) == '"')
                                {
                                    isInString       = true;
                                    isVerbatimString = true;
                                    j++;
                                }
                                break;

                            case '"':
                                if (!(isInChar || isInLineComment || isInBlockComment))
                                {
                                    if (isInString && isVerbatimString && j + 1 < doc.TextLength && doc.GetCharAt(j + 1) == '"')
                                    {
                                        j++;
                                    }
                                    else
                                    {
                                        isInString       = !isInString;
                                        isVerbatimString = false;
                                    }
                                }
                                break;

                            case '\'':
                                if (!(isInString || isInLineComment || isInBlockComment))
                                {
                                    isInChar = !isInChar;
                                }
                                break;

                            case '{':
                                if (!(isInString || isInChar || isInLineComment || isInBlockComment))
                                {
                                    brackets++;
                                }
                                break;

                            case '}':
                                if (!(isInString || isInChar || isInLineComment || isInBlockComment))
                                {
                                    brackets--;
                                }
                                break;
                            }
                        }
                        if (brackets == 0)
                        {
                            FoundSpanEnd(cur, i, 1);
                            return(true);
                        }
                        return(false);
                    }
                }

                if (cur is ForcedJayBlockSpan)
                {
                    if (textOffset + 1 < CurText.Length && CurText[textOffset] == '%' && CurText[textOffset + 1] == '}')
                    {
                        FoundSpanEnd(cur, i, 2);
                        return(true);
                    }
                }

                if (cur is JayDefinitionSpan)
                {
                    if (textOffset + 1 < CurText.Length && CurText[textOffset] == '%' && CurText[textOffset + 1] == '%')
                    {
                        FoundSpanEnd(cur, i, 2);
                        return(true);
                    }
                }
                return(base.ScanSpanEnd(cur, ref i));
            }
			public virtual void OnFoundSpanBegin (Span span, int offset, int length)
			{
				if (FoundSpanBegin != null)
					FoundSpanBegin (span, offset, length);
			}
			public void FoundSpanBegin (Span span, int offset, int length)
			{
				curChunk.Length = offset - curChunk.Offset;
				curChunk.Style  = GetStyle (curChunk) ?? GetSpanStyle ();
				AddChunk (ref curChunk, 0, curChunk.Style);
				
				curChunk.Offset = offset;
				curChunk.Length = length;
				curChunk.Style  = GetChunkStyle (span);
				AddChunk (ref curChunk, 0, curChunk.Style);
				Rule spanRule = spanParser.GetRule (span);
				if (spanRule == null)
					throw new Exception ("Rule " + span.Rule + " not found in " + span);
				foreach (SemanticRule semanticRule in spanRule.SemanticRules) {
					semanticRule.Analyze (this.doc, line, curChunk, offset, line.EndOffset);
				}
			}
			protected virtual bool ScanSpanEnd (Span cur, int i)
			{
				if (cur.End != null) {
					RegexMatch match = cur.End.TryMatch (doc, i);
					if (match.Success) {
						OnFoundSpanEnd (cur, i, match.Length);
						spanStack.Pop ();
						if (ruleStack.Count > 1) // rulStack[1] is always syntax mode
							ruleStack.Pop ();
						return true;
					}
				}
				
				if (cur.Exit != null) {
					RegexMatch match = cur.Exit.TryMatch (doc, i);
					if (match.Success) {
						spanStack.Pop ();
						if (ruleStack.Count > 1) // rulStack[1] is always syntax mode
							ruleStack.Pop ();
						OnFoundSpanExit (cur, i, match.Length);
						return true;
					}
				}
				return false;
			}
			public virtual void OnFoundSpanEnd (Span span, int offset, int length)
			{
				if (FoundSpanEnd != null)
					FoundSpanEnd (span, offset, length);
			}
Esempio n. 18
0
			public static Span CreatePreprocessorSpan ()
			{
				var result = new Span ();
				result.TagColor = "text.preprocessor";
				result.Color = "text.preprocessor";
				result.Rule = "String";
				result.StopAtEol = true;
				return result;
			}
Esempio n. 19
0
			public void PushSpan (Span span, Rule rule)
			{
				spanStack.Push (span);
				ruleStack.Push (rule);
				CurRule = rule;
				CurSpan = span;
				if (rule.Name == "InterpolatedString" || rule.Name == "InterpolatedVerbatimString")
					interpolatedBraces.Push(0);
			}
Esempio n. 20
0
			void DefaultFoundSpanEnd (Span span, int offset, int length)
			{
				PopSpan ();
			}
Esempio n. 21
0
			protected virtual bool ScanSpanEnd (Span cur, ref int i)
			{
				int textOffset = i - StartOffset;
				
				if (cur.End != null) {
					if (interpolatedBraces.Count > 0) {
						char ch = CurText [textOffset];
						if (ch == '{')
							interpolatedBraces.Push (interpolatedBraces.Pop () + 1);
						else if (ch == '}')
							interpolatedBraces.Push (interpolatedBraces.Pop () - 1);
						if (interpolatedBraces.Peek () >= 1)
							return false;
					}
					RegexMatch match = cur.End.TryMatch (CurText, textOffset);
					if (match.Success) {
						FoundSpanEnd (cur, i, match.Length);
						i += System.Math.Max (0, match.Length - 1);
						return true;
					}
				}

				if (cur.Exit != null) {
					RegexMatch match = cur.Exit.TryMatch (CurText, textOffset);
					if (match.Success) {
						FoundSpanExit (cur, i, match.Length);
						i += System.Math.Max (0, match.Length - 1);
						return true;
					}
				}
				return false;
			}
Esempio n. 22
0
			public Rule GetRule (Span span)
			{
				if (string.IsNullOrEmpty (span.Rule))
					return new Rule (mode);
				return CurRule.GetRule (span.Rule);
			}
            protected override bool ScanSpanEnd(Span cur, ref int i)
            {
                int textOffset = i - StartOffset;

                if (cur.End != null && (cur.Rule == "Table" || cur.Rule == "TableHeader")) {
                    if (cur.Rule == "Table") {
                        if (CurText [textOffset] != cur.End.Pattern [0] || CurText.Skip (textOffset + 1).Any (e => e == cur.End.Pattern [0])) {
                            return false;
                        }
                    }

                    if (cur.Rule == "TableHeader") {
                        if (textOffset != 0 || (!string.IsNullOrWhiteSpace(CurText) && CurText.First (ch => !char.IsWhiteSpace (ch)) == cur.End.Pattern [0])) {
                            return false;
                        }
                    }

                    FoundSpanEnd (cur, i, 1);
                    return true;
                }

                if (cur.End != null) {
                    RegexMatch match = cur.End.TryMatch (CurText, textOffset);
                    if (match.Success) {
                        FoundSpanEnd (cur, i, match.Length);
                        i += Math.Max (0, match.Length - 1);
                        return true;
                    }
                }

                if (cur.Exit != null) {
                    RegexMatch match = cur.Exit.TryMatch (CurText, textOffset);
                    if (match.Success) {
                        FoundSpanExit (cur, i, match.Length);
                        i += -1;
                        return true;
                    }
                }

                return false;
            }
Esempio n. 24
0
			string GetChunkStyle (Span span)
			{
				if (span == null)
					return GetSpanStyle ();
				return span.Color ?? GetSpanStyle ();
			}
Esempio n. 25
0
		public Span Clone ()
		{
			var newSpan = new Span ();
			if (Begin != null)
				newSpan.Begin = Begin.Clone ();
			newSpan.BeginFlags = BeginFlags;
			newSpan.Color = Color;
			newSpan.Continuation = Continuation;
			if (End != null)
				newSpan.End = End.Clone ();
			newSpan.EndFlags = EndFlags;
			newSpan.Escape = Escape;
			if (Exit != null)
				newSpan.Exit = Exit.Clone ();
			newSpan.ExitFlags = ExitFlags;
			newSpan.NextColor = NextColor;
			newSpan.Rule = Rule;
			newSpan.StopAtEol = StopAtEol;
			newSpan.TagColor = TagColor;
			newSpan.BeginTagColor = beginTagColor;
			newSpan.EndTagColor = endTagColor;
			return newSpan;
		}
Esempio n. 26
0
			public void FoundSpanExit (Span span, int offset, int length)
			{
				curChunk.Length = offset - curChunk.Offset;
				AddChunk (ref curChunk, 0, GetChunkStyle (span));
				spanParser.PopSpan ();

			}
		public static Span Read (XmlReader reader)
		{
			Span result = new Span ();
			
			result.Rule       = reader.GetAttribute ("rule");
			result.Color      = reader.GetAttribute ("color");
			result.TagColor   = reader.GetAttribute ("tagColor");
			result.NextColor  = reader.GetAttribute ("nextColor");
			
			result.Escape = reader.GetAttribute ("escape");
			
			string stopateol = reader.GetAttribute ("stopateol");
			if (!String.IsNullOrEmpty (stopateol)) {
				result.StopAtEol = Boolean.Parse (stopateol);
			}
			
			if (reader.LocalName == AltNode) {
				AddFlags (result.BeginFlags, reader.GetAttribute ("flags"));
				result.Continuation = reader.GetAttribute ("continuation");
				result.Begin        = new Regex (reader.ReadElementString ());
				result.StopAtEol = true;
			} else {
				XmlReadHelper.ReadList (reader, Node, delegate () {
					switch (reader.LocalName) {
					case "Begin":
						AddFlags (result.BeginFlags, reader.GetAttribute ("flags"));
						result.Begin = new Regex (reader.ReadElementString ());
						return true;
					case "End":
						AddFlags (result.EndFlags, reader.GetAttribute ("flags"));
						result.End = new Regex (reader.ReadElementString ());
						return true;
					case "Exit":
						AddFlags (result.ExitFlags, reader.GetAttribute ("flags"));
						result.Exit = new Regex (reader.ReadElementString ());
						return true;
					}
					return false;
				});
			}
			return result;
		}
			bool EndsWithContinuation (Span span, DocumentLine line)
			{
				return !span.StopAtEol || span.StopAtEol && !string.IsNullOrEmpty (span.Continuation) &&
					line != null && doc.GetTextAt (line).Trim ().EndsWith (span.Continuation, StringComparison.Ordinal);
			} 
		static bool IsEqual (Span[] spans1, Span[] spans2)
		{
			if (spans1 == null || spans1.Length == 0) 
				return spans2 == null || spans2.Length == 0;
			if (spans2 == null || spans1.Length != spans2.Length)
				return false;
			for (int i = 0; i < spans1.Length; i++) {
				if (spans1[i] != spans2[i]) {
					return false;
				}
			}
			return true;
		}