예제 #1
0
        public void SetSource(string source, int offset)
        {
            //System.Diagnostics.Debug.WriteLine(string.Format("Scan line {0}", _currentLine));

            ScanLexer lexer = GetLexer();

            if (lexer != null)
            {
                if (_currentLine >= 0 && source.Length > 0)
                {
                    if (_source != null && _source.ProjectInfo != null)
                    {
                        var ret = _source.ProjectInfo.Engine.GetActiveEnv(_source.FileIndex, _currentLine + 1);

                        if (ret.Field0 != null)
                        {
                            _env  = ret.Field0;
                            _type = ret.Field1;
                        }
                    }
                }

                lexer.SetLine(_currentLine + 1, source, offset, _env, _type);
            }
        }
예제 #2
0
        /// <summary>
        /// Get tokens of specified line.
        /// </summary>
        /// <param name="line">Line number which tokens it is necessary retrieve</param>
        /// <param name="isForward">Direction of iteration (true is forward)</param>
        /// <returns>Token list</returns>
        List <ScanTokenInfo> GetLineTokens(int nline, bool isForward)
        {
            int       line      = nline - 1;
            ScanState scanState = GetLineState(nline);
            string    lineText;

            int index = line - _startBufferLine;

            // читаем буферами по BufferLen стрк, чтобы ускорить работу
            if (index < 0 || index >= _buffer.Length)
            {
                int start, end;

                if (isForward)
                {
                    end   = Math.Min(_lineCount - 1, line + BufferLen);
                    start = line;
                }
                else
                {
                    start = Math.Max(0, line - BufferLen);
                    end   = line;
                }

                var str = Source.GetText(start, 0, end, Source.GetLineLength(end));
                _buffer          = str.Split(new string[] { "\r\n", "\n", "\r" }, StringSplitOptions.None);
                _startBufferLine = start;
                index            = line - _startBufferLine;
            }

            lineText = _buffer[index];

            Scanner.SetSource(lineText, 0);
            Lex.SetLine(nline, lineText, 0, null, null);
            List <ScanTokenInfo> lst = new List <ScanTokenInfo>();

            foreach (ScanTokenInfo var in GetLineTokens(Lex, scanState))
            {
                lst.Add(var);
            }

            if (!isForward)
            {
                lst.Reverse();
            }

            return(lst);
        }