Exemplo n.º 1
0
// Get the current parser and text to parse
std::string Parse(void)
{
	std::string doc_block;
	const Parser *p;
	int found, curLine, foundLine;
	char *buffer;

	if(!(p = getCurrentParser()))
	{
		MessageBox(NULL, TEXT("Unrecognized language type."), NPP_PLUGIN_NAME, MB_OK|MB_ICONERROR);
		return std::string("");
	}

	// External parsers are simple enough since they don't need any text to parse
	if(p->external)
		return FormatFunctionBlock(p, &p->pd, NULL); 

	// Get the text until a closing parenthesis. Find '(' first
	if((found = findNext("(")) == -1)
	{
		MessageBox(NULL, TEXT("Error: Cannot parse function definition. Make sure the cursor is on the line directly above the function or method definition."), NPP_PLUGIN_NAME, MB_OK|MB_ICONERROR);
		return std::string("");
	}

	// Do some sanity checking. Make sure curline <= found <= curline+2
	curLine = SendScintilla(SCI_LINEFROMPOSITION, SendScintilla(SCI_GETCURRENTPOS));
	foundLine = SendScintilla(SCI_LINEFROMPOSITION, found);
	if(foundLine < curLine || foundLine > curLine + 2)
	{
		MessageBox(NULL, TEXT("Error: Cannot parse function definition. Make sure the cursor is on the line directly above the function or method definition."), NPP_PLUGIN_NAME, MB_OK|MB_ICONERROR);
		return std::string("");
	}

	// Find the matching closing brace
	if((found = SendScintilla(SCI_BRACEMATCH, found, 0)) == -1)
	{
		MessageBox(NULL, TEXT("Error: Cannot parse function definition. Make sure the cursor is on the line directly above the function or method definition."), NPP_PLUGIN_NAME, MB_OK|MB_ICONERROR);
		return std::string("");
	}

	buffer = getRange(SendScintilla(SCI_GETCURRENTPOS), found + 1);
	doc_block = FormatFunctionBlock(p, &p->pd, buffer);
	delete[] buffer;

	// I don't think there is currently a case where callback() will return a zero length string,
	// but check it just in case we decide to for the future.
	if(doc_block.length() == 0)
	{
		MessageBox(NULL, TEXT("Error: Cannot parse function definition. Make sure the cursor is on the line directly above the function or method definition."), NPP_PLUGIN_NAME, MB_OK|MB_ICONERROR);
		return std::string("");
	}

	return doc_block;
}
Exemplo n.º 2
0
void handleNotification(SCNotification *notifyCode)
{
	static bool do_newline = false;
	NotifyHeader nh = notifyCode->nmhdr;
	int ch = notifyCode->ch;

	switch(nh.code)
	{
	case SCN_UPDATEUI: // Now is when we can check to see if we do the commenting
		if(do_newline)
		{
			do_newline = false;
			if(!updateScintilla()) return;
			doxyItNewLine();
		}
		break;
	case SCN_CHARADDED:
		// Set a flag so that all line endings can trigger the commenting
		if((ch == '\r' || ch == '\n') && do_active_commenting) do_newline = true;
		break;
	case NPPN_READY:
		InitializeParsers();
		configLoad();
		getCurrentParser(true);
		break;
	case NPPN_SHUTDOWN:
		configSave();
		CleanUpParsers();
		break;
	case NPPN_BUFFERACTIVATED:
	case NPPN_LANGCHANGED:
		// Don't actually need the parser here, but this forces it to updates the current reference
		getCurrentParser(true);
		break;
	}
	return;
}
Exemplo n.º 3
0
const ParserDefinition *getCurrentParserDefinition(void)
{
	const Parser *p = getCurrentParser();

	return (p ? &p->pd : NULL);
}
Exemplo n.º 4
0
const ParserSettings *getCurrentParserSettings(void)
{
	const Parser *p = getCurrentParser();
	return (p ? &p->ps : nullptr);
}