public bool IsAutoCompletionAllowedHere(TextLocation location) { var app = ProbeNppPlugin.Instance; var currentLine = app.CurrentLine; var lineText = app.GetLineText(currentLine); var state = currentLine > 1 ? app.GetLineState(currentLine - 1) : 0; var startPos = 0; if ((state & ProbeLexer.State_InsideComment) != 0) { var index = lineText.IndexOf("*/"); if (index < 0) return false; startPos = index + 2; } if (startPos + 1 > location.CharPosition) return false; var parser = new TokenParser.Parser(app.GetLineText(currentLine)); parser.ReturnComments = true; parser.ReturnWhiteSpace = true; if (startPos > 0) parser.SetOffset(startPos); while (parser.Read()) { if (parser.Position.LinePos > location.CharPosition || parser.EndOfFile) { if (parser.TokenType == TokenParser.TokenType.Comment || parser.TokenType == TokenParser.TokenType.StringLiteral) { return false; } return true; } } if (parser.TokenType == TokenParser.TokenType.Comment || parser.TokenType == TokenParser.TokenType.StringLiteral) { return false; } return true; }
private bool IndentNextLine(string lineText) { var parser = new TokenParser.Parser(lineText); var first = true; var startsWithCase = false; TokenParser.TokenType type = TokenParser.TokenType.Unknown; string text = ""; while (parser.Read()) { type = parser.TokenType; text = parser.TokenText; if (first && type == TokenParser.TokenType.Word && text == "case") startsWithCase = true; if (first) first = false; } if (type == TokenParser.TokenType.Operator && text == "{") return true; if (startsWithCase && type == TokenParser.TokenType.Operator && text == ":") return true; return false; }
private ParseState ParseFunctionSigFromSource() { var startPos = _source.Length; var parser = new TokenParser.Parser(_source.ToString()); var retVal = ParseState.NotEnoughSource; // Find the last token before startPos. while (startPos > 0) { var newStartPos = 0; parser.ResetPosition(); while (parser.Position.Offset < startPos) { newStartPos = parser.Position.Offset; if (!parser.Read()) break; } startPos = newStartPos; if ((retVal = ParseFunctionSigFromSource(startPos)) == ParseState.Found) return retVal; } return retVal; }
private ParseState ParseFunctionSigFromSource(int startPos) { var parser = new TokenParser.Parser(_source.ToString().Substring(startPos)); var lastTokenText = ""; TokenParser.TokenType lastTokenType = TokenParser.TokenType.Unknown; _funcName = ""; _commaCount = 0; while (parser.Read()) { if (parser.TokenText == "(") { if (!ParseNestable(parser, ")", true)) { if (lastTokenType == TokenParser.TokenType.Word) { _funcName = lastTokenText; return ParseState.Found; } return ParseState.BadSyntax; } } else if (parser.TokenText == ";") { return ParseState.BadSyntax; } else if (parser.TokenText == ",") { _commaCount++; } lastTokenText = parser.TokenText; lastTokenType = parser.TokenType; } return ParseState.NotEnoughSource; }