コード例 #1
0
ファイル: JaySyntaxMode.cs プロジェクト: natosha/monodevelop
			protected override void ScanSpan (ref int i)
			{
				bool hasJayDefinitonSpan = spanStack.Any (s => s is JayDefinitionSpan);
				
				if (i + 1 < doc.Length && doc.GetCharAt (i) == '%')  {
					char next = doc.GetCharAt (i + 1);
					if (next == '{') {
						ForcedJayBlockSpan forcedBlockSpan = new ForcedJayBlockSpan ();
						OnFoundSpanBegin (forcedBlockSpan, i, 2);
						spanStack.Push (forcedBlockSpan);
						ruleStack.Push (GetRule (forcedBlockSpan));
						i++;
						return;
					}
					
					if (!hasJayDefinitonSpan && next == '%') {
						JayDefinitionSpan jayDefinitionSpan = new JayDefinitionSpan ();
						OnFoundSpanBegin (jayDefinitionSpan, i, 2);
						spanStack.Push (jayDefinitionSpan);
						ruleStack.Push (GetRule (jayDefinitionSpan));
						return;
					}
					
					if (next == '}' && spanStack.Any (s => s is ForcedJayBlockSpan)) {
						foreach (Span span in spanStack.ToArray ().Reverse ()) {
							OnFoundSpanEnd (span, i, span.End.Pattern.Length);
							if (spanStack.Count > 0) {
								spanStack.Pop ();
							}
							if (ruleStack.Count > 1) // rulStack[1] is always syntax mode
								ruleStack.Pop ();
							if (span is ForcedJayBlockSpan)
								break;
						}
						return;
					}
				}
				
				
				if (CurSpan is JayDefinitionSpan && doc.GetCharAt (i) == '{' && hasJayDefinitonSpan && !spanStack.Any (s => s is JayBlockSpan)) {
					JayBlockSpan jayBlockSpan = new JayBlockSpan (i);
					OnFoundSpanBegin (jayBlockSpan, i, 1);
					spanStack.Push (jayBlockSpan);
					ruleStack.Push (GetRule (jayBlockSpan));
					return;
				}
				
				
				base.ScanSpan (ref i);
			}
コード例 #2
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));
            }
コード例 #3
0
            protected override void ScanSpan(ref int i)
            {
                bool hasJayDefinitonSpan = spanStack.Any(s => s is JayDefinitionSpan);

                if (i + 1 < doc.Length && doc.GetCharAt(i) == '%')
                {
                    char next = doc.GetCharAt(i + 1);
                    if (next == '{')
                    {
                        ForcedJayBlockSpan forcedBlockSpan = new ForcedJayBlockSpan();
                        OnFoundSpanBegin(forcedBlockSpan, i, 2);
                        spanStack.Push(forcedBlockSpan);
                        ruleStack.Push(GetRule(forcedBlockSpan));
                        i++;
                        return;
                    }

                    if (!hasJayDefinitonSpan && next == '%')
                    {
                        JayDefinitionSpan jayDefinitionSpan = new JayDefinitionSpan();
                        OnFoundSpanBegin(jayDefinitionSpan, i, 2);
                        spanStack.Push(jayDefinitionSpan);
                        ruleStack.Push(GetRule(jayDefinitionSpan));
                        return;
                    }

                    if (next == '}' && spanStack.Any(s => s is ForcedJayBlockSpan))
                    {
                        foreach (Span span in spanStack.ToArray().Reverse())
                        {
                            OnFoundSpanEnd(span, i, span.End.Pattern.Length);
                            if (spanStack.Count > 0)
                            {
                                spanStack.Pop();
                            }
                            if (ruleStack.Count > 1)                             // rulStack[1] is always syntax mode
                            {
                                ruleStack.Pop();
                            }
                            if (span is ForcedJayBlockSpan)
                            {
                                break;
                            }
                        }
                        return;
                    }
                }


                if (CurSpan is JayDefinitionSpan && doc.GetCharAt(i) == '{' && hasJayDefinitonSpan && !spanStack.Any(s => s is JayBlockSpan))
                {
                    JayBlockSpan jayBlockSpan = new JayBlockSpan(i);
                    OnFoundSpanBegin(jayBlockSpan, i, 1);
                    spanStack.Push(jayBlockSpan);
                    ruleStack.Push(GetRule(jayBlockSpan));
                    return;
                }


                base.ScanSpan(ref i);
            }