Exemplo n.º 1
0
void QsCodeParser::setQuickDoc(Node *quickNode,
                               const Doc& doc,
                               const QStringList& qtParams,
                               const QStringList& quickParams)
{
    QRegExp quickifyCommand("\\\\" + COMMAND_QUICKIFY + "([^\n]*)(?:\n|$)");

    if (quickNode->type() == Node::Function) {
	FunctionNode *quickFunc = (FunctionNode *) quickNode;
	quickFunc->setOverload(false);
    }

    if (doc.metaCommandsUsed().contains(COMMAND_QUICKIFY)) {
	QString source = doc.source();
	int pos = source.indexOf(quickifyCommand);
	if (pos != -1) {
	    QString quickifiedSource = quickNode->doc().source();
	    if (!qtParams.isEmpty() && qtParams != quickParams)
		renameParameters(quickifiedSource, doc, qtParams,
				  quickParams);
	    applyReplacementList(quickifiedSource, doc);

	    do {
		QString extract = quickifiedSource;
		QString arg = quickifyCommand.cap(1).simplified();
		if (!arg.isEmpty()) {
		    if (arg.startsWith("/") && arg.endsWith("/") &&
			 arg.length() > 2) {
			QString pattern = arg.mid(1, arg.length() - 2);
			extractRegExp(QRegExp(pattern), extract, doc);
		    }
                    else {
			extractTarget(arg, extract, doc);
		    }
		}
		source.replace(pos, quickifyCommand.matchedLength(), extract);
		pos += extract.length();
	    } while ((pos = source.indexOf(quickifyCommand, pos)) != -1);

	    QRegExp quickcodeRegExp(
		    "\\\\" + COMMAND_QUICKCODE + "(.*)\\\\" +
		    COMMAND_ENDQUICKCODE);
	    quickcodeRegExp.setMinimal(true);
	    source.replace(quickcodeRegExp, "");
	}

	Doc quickDoc(doc.location(),
                     doc.location(),
                     source,
                     (CppCodeParser::topicCommands() + topicCommands() +
                      CppCodeParser::otherMetaCommands()) << COMMAND_REPLACE);
	quickNode->setDoc(quickDoc, true);
	processOtherMetaCommands(quickDoc, quickNode);
    }
    else {
	quickNode->setDoc(doc, true);
	processOtherMetaCommands(doc, quickNode);
    }
}
Exemplo n.º 2
0
void QsCodeParser::setQtDoc(Node *quickNode, const Doc& doc)
{
    if (!doc.isEmpty()) {
	Doc quickDoc(doc.location(), doc.location(),
                     quickifiedDoc(doc.source()),
		     CppCodeParser::topicCommands() +
                     CppCodeParser::otherMetaCommands());
	quickNode->setDoc(quickDoc, true);
    }
}
Exemplo n.º 3
0
void QsCodeParser::applyReplacementList(QString& source, const Doc& doc)
{
    QStringList args = doc.metaCommandArgs(COMMAND_REPLACE);
    QStringList::ConstIterator a = args.begin();
    while (a != args.end()) {
	if (replaceRegExp.exactMatch(*a)) {
	    QRegExp before(replaceRegExp.cap(1));
	    before.setMinimal(true);
	    QString after = replaceRegExp.cap(2);

	    if (before.isValid()) {
		int oldLen = source.size();
		source.replace(before, after);

		// this condition is sufficient but not necessary
		if (oldLen == source.size() && !source.contains(after))
		    doc.location().warning(
			    tr("Regular expression '%1' did not match anything")
			    .arg(before.pattern()));
	    }
            else {
		doc.location().warning(
			tr("Invalid regular expression '%1'")
			.arg(before.pattern()));
	    }
	}
        else {
	    doc.location().warning(tr("Bad syntax in '\\%1'")
				    .arg(COMMAND_REPLACE));
	}
	++a;
    }

    QRegExp codeRegExp("\\\\" + COMMAND_CODE + "(.*)\\\\" + COMMAND_ENDCODE);
    codeRegExp.setMinimal(true);

    QRegExp quickcodeRegExp(
	    "\\\\" + COMMAND_QUICKCODE + "(.*)\\\\" + COMMAND_ENDQUICKCODE);
    quickcodeRegExp.setMinimal(true);

    int quickcodePos = doc.source().indexOf(quickcodeRegExp);
    if (quickcodePos != -1) {
	int codePos = source.indexOf(codeRegExp);
	if (codePos == -1) {
	    doc.location().warning(
		    tr("Cannot find any '\\%1' snippet corresponding to '\\%2'")
		    .arg(COMMAND_CODE).arg(COMMAND_QUICKCODE));
	}
        else {
	    source.replace(codeRegExp.pos(1), codeRegExp.cap(1).length(),
			    quickcodeRegExp.cap(1));
	    codePos = codeRegExp.pos(1) + quickcodeRegExp.cap(1).length();

	    if (doc.source().indexOf(quickcodeRegExp, quickcodePos + 1) != -1) {
		doc.location().warning(
			tr("Cannot use '\\%1' twice in a row")
			.arg(COMMAND_QUICKCODE));
	    }
            else if (source.indexOf(codeRegExp, codePos + 1) != -1) {
		doc.location().warning(tr("Ambiguous '\\%1'")
					.arg(COMMAND_QUICKCODE));
	    }
	}
    }
}