예제 #1
0
        public virtual ITokenEnumerator Colorize(string sourceCode, SourceState state)
        {
            TokenColorInfoList list = new TokenColorInfoList();

            this._state = SourceState.STATE_COLOR_NORMAL;
            if (sourceCode.Length > 0)
            {
                Context sourceContext = new Context(null, sourceCode);
                this._scanner.SetSource(sourceContext);
                try
                {
                    if (SourceState.STATE_COLOR_COMMENT == state)
                    {
                        int length = this._scanner.SkipMultiLineComment();
                        if (length > sourceCode.Length)
                        {
                            this._state = SourceState.STATE_COLOR_COMMENT;
                            length      = sourceCode.Length;
                        }
                        list.Add(sourceContext);
                        if (length == sourceCode.Length)
                        {
                            return(list);
                        }
                    }
                    this._scanner.GetNextToken();
                    JSToken none = JSToken.None;
                    while (sourceContext.GetToken() != JSToken.EndOfFile)
                    {
                        list.Add(sourceContext);
                        none = sourceContext.GetToken();
                        this._scanner.GetNextToken();
                    }
                    if (JSToken.UnterminatedComment == none)
                    {
                        this._state = SourceState.STATE_COLOR_COMMENT;
                    }
                }
                catch (ScannerException)
                {
                }
            }
            return(list);
        }
 public virtual ITokenEnumerator Colorize(string sourceCode, SourceState state)
 {
     TokenColorInfoList list = new TokenColorInfoList();
     this._state = SourceState.STATE_COLOR_NORMAL;
     if (sourceCode.Length > 0)
     {
         Context sourceContext = new Context(null, sourceCode);
         this._scanner.SetSource(sourceContext);
         try
         {
             if (SourceState.STATE_COLOR_COMMENT == state)
             {
                 int length = this._scanner.SkipMultiLineComment();
                 if (length > sourceCode.Length)
                 {
                     this._state = SourceState.STATE_COLOR_COMMENT;
                     length = sourceCode.Length;
                 }
                 list.Add(sourceContext);
                 if (length == sourceCode.Length)
                 {
                     return list;
                 }
             }
             this._scanner.GetNextToken();
             JSToken none = JSToken.None;
             while (sourceContext.GetToken() != JSToken.EndOfFile)
             {
                 list.Add(sourceContext);
                 none = sourceContext.GetToken();
                 this._scanner.GetNextToken();
             }
             if (JSToken.UnterminatedComment == none)
             {
                 this._state = SourceState.STATE_COLOR_COMMENT;
             }
         }
         catch (ScannerException)
         {
         }
     }
     return list;
 }