예제 #1
0
        internal IEnumerable <AsmRange> GetColorRanges(string text)
        {
            AsmRange range = new AsmRange();

            while (GetNextRange(text, ref range))
            {
                yield return(range);
            }
        }
예제 #2
0
        internal IEnumerable <AsmRange> GetColorRanges(string text, int start, int end)
        {
            AsmRange range = new AsmRange();

            range.Start = start;
            while (range.Start < end && GetNextRange(text, ref range))
            {
                yield return(range);
            }
        }
예제 #3
0
        internal bool GetNextRange(string text, ref AsmRange range)
        {
            int start, end;

            start = range.Start + range.Length;
            while (start != text.Length)
            {
                end = start + 1;
                AsmRangeKind kind = AsmRangeKind.Other;
                char         ch   = text[start];
                if (IsWS(ch))
                {
                    kind = AsmRangeKind.WS;
                    while (end != text.Length && IsWS(text[end]))
                    {
                        ++end;
                    }
                }
                else if (ch == ';')
                {
                    kind = AsmRangeKind.Comment;
                    while (end != text.Length && text[end] != '\n')
                    {
                        ++end;
                    }
                    if (end != text.Length)
                    {
                        ++end;
                    }
                }
                else if (ch == '@')
                {
                    kind = AsmRangeKind.GlobalVar;
                    LexVar(text, start, ref end);
                }
                //else if (ch == '$')
                //{
                // lex dollar
                //}
                else if (ch == '%')
                {
                    kind = AsmRangeKind.LocalVar;
                    LexVar(text, start, ref end);
                }
                else if (ch == '"')
                {
                    kind = AsmRangeKind.StringConstant;
                    while (end != text.Length && (text[end] != '"'))
                    {
                        ++end;
                    }
                    if (end != text.Length)
                    {
                        ++end;
                    }
                    if (end != text.Length && text[end] == ':')
                    {
                        ++end;
                        kind = AsmRangeKind.Label;
                    }
                }
                else if (ch == '!')
                {
                    kind = AsmRangeKind.Metadata;
                    while (end != text.Length && IsMetadataChar(text[end]))
                    {
                        ++end;
                    }
                }
                else if (ch == '#')
                {
                    kind = AsmRangeKind.AttributeGroup;
                    while (end != text.Length && Char.IsDigit(text[end]))
                    {
                        ++end;
                    }
                    if (end != text.Length)
                    {
                        ++end;
                    }
                }
                else if (IsNumericLead(ch))
                {
                    // lex number or positive
                    kind = AsmRangeKind.Number;
                    while (end != text.Length && IsNumeric(text[end]))
                    {
                        ++end;
                    }
                    if (end != text.Length)
                    {
                        ++end;
                    }
                }
                else if (IsPunctuation(ch))
                {
                    kind = AsmRangeKind.Punctuation;
                }
                else
                {
                    kind = AsmRangeKind.Other;
                    while (end != text.Length && !IsWS(text[end]) && !IsPunctuation(text[end]))
                    {
                        ++end;
                    }
                    kind = ClassifyIdentifierLike(text, start, end);
                }
                range = new AsmRange(start, end - start, kind);
                return(true);
            }
            return(false);
        }