Ejemplo n.º 1
0
 public void CodeModelTest()
 {
     var model = new CodeModel.CodeModel(GetText(Start, End), ActiveFileName);
 }
Ejemplo n.º 2
0
 private IEnumerable<string> GetFunctionList()
 {
     if (_model == null) _model = ProbeNppPlugin.Instance.CurrentModel;
     if (_model != null) return _model.FunctionNames;
     return new string[0];
 }
Ejemplo n.º 3
0
        public int StyleLine(ILexerLine line, int state)
        {
            _line = line;
            _state = state;
            _tokenCount = 0;
            _table = string.Empty;
            _model = null;

            char nextCh;
            int lastPos = -1;

            while (!line.EOL)
            {
                nextCh = line.NextChar;

                if (line.Position == lastPos) throw new LexerException(string.Format(
                    "The lexer did not advance the line position when styling line [{0}] at position [{1}]",
                    line.Text, lastPos));
                lastPos = line.Position;

                if ((_state & State_InsideComment) != 0)
                {
                    // Currently inside block comment.
                    if (line.Match("*/"))
                    {
                        line.Style(_commentStyle, 2);
                        _state &= ~State_InsideComment;
                    }
                    else
                    {
                        line.Style(_commentStyle);
                    }
                    SetLastToken(State_Token_BlockComment);
                }
                else if ((_state & State_InsideReplace) != 0 && line.Peek(5) != "#with")
                {
                    _line.Style(_replacedStyle);
                    SetLastToken(State_Token_None);
                }
                else if (line.Match("//"))
                {
                    // Start of line comment; rest of line is forfeit.
                    line.StyleRemainder(_commentStyle);
                    SetLastToken(State_Token_StreamComment);
                }
                else if (line.Match("/*"))
                {
                    // Start of block comment. Switch the state on so it passes down to other lines.
                    _line.Style(_commentStyle, 2);
                    _state |= State_InsideComment;
                    SetLastToken(State_Token_BlockComment);
                }
                else if (Char.IsLetter(nextCh) || nextCh == '_')
                {
                    // Token beginning with letter or underscore.  Standard identifier.
                    StyleIdent();
                }
                else if (Char.IsDigit(nextCh))
                {
                    // Token beginning with number.
                    line.Style(_numberStyle, (ch) => Char.IsDigit(ch) || ch == '.');
                    SetLastToken(State_Token_Number);
                }
                else if (nextCh == '\"' || nextCh == '\'')
                {
                    // String literal.
                    char lastCh = '\\';
                    bool done = false;
                    line.Style(_stringStyle, (ch) =>
                        {
                            if (done) return false;
                            if (ch == nextCh && lastCh != '\\') done = true;
                            if (ch == '\\' && lastCh == '\\') lastCh = '\0';	// To avoid problems with "\\" where last 2 chars appear to be another escape sequence.
                            else lastCh = ch;
                            return true;
                        });
                    SetLastToken(State_Token_String);
                }
                else if (nextCh == '{')
                {
                    // Opening braces are the start of a code folding section.
                    line.FoldStart();
                    line.Style(_operatorStyle);
                    SetLastToken(State_Token_Operator);
                }
                else if (nextCh == '}')
                {
                    // Closing braces are the end of a code folding section.
                    line.FoldEnd();
                    line.Style(_operatorStyle);
                    SetLastToken(State_Token_Operator);
                }
                else if (nextCh == '#')
                {
                    StylePreprocessor();
                }
                else if (nextCh == '.')
                {
                    line.Style(_operatorStyle);

                    if (GetLastToken() == State_Token_Table)
                    {
                        SetLastToken(State_Token_TableDelim);
                    }
                    else
                    {
                        SetLastToken(State_Token_Operator);
                    }
                }
                else if (ProbeNppPlugin.Instance.OperatorChars.Contains(nextCh))
                {
                    line.Style(_operatorStyle);
                    SetLastToken(State_Token_Operator);
                }
                else if (!Char.IsWhiteSpace(nextCh))
                {
                    line.Style(_defaultStyle);
                    SetLastToken(State_Token_Unknown);
                }
                else
                {
                    line.Style(_defaultStyle);
                }
            }

            return _state;
        }
Ejemplo n.º 4
0
 private IEnumerable<string> GetDataTypeNames()
 {
     if (_model == null) _model = ProbeNppPlugin.Instance.CurrentModel;
     if (_model != null) return _model.DataTypeNames;
     return new string[0];
 }
Ejemplo n.º 5
0
        private void CreateModel()
        {
            try
            {
                var app = ProbeNppPlugin.Instance;
                var source = app.GetText(app.Start, app.End);
                var model = new CodeModel.CodeModel(source, app.ActiveFileName);

                lock (_modelLock)
                {
                    _model = model;
                }
            }
            catch (Exception ex)
            {
                ProbeNppPlugin.Instance.Output.WriteLine(OutputStyle.Error, "Exception when generating code model: {0}", ex);
                _model = null;
            }
        }