13#include <QtCore/qfile.h>
14#include <QtCore/qregularexpression.h>
15#include <QtCore/qtextstream.h>
23using namespace Qt::StringLiterals;
138 bool is_formatting_command {
false };
139} cmds[] = { {
"a",
CMD_A,
true },
141 {
"b",
CMD_B,
true },
146 {
"c",
CMD_C,
true },
154 {
"e",
CMD_E,
true },
179 {
"i",
CMD_I,
true },
252
253
254
255
258 qsizetype colonPos = link.indexOf(
':');
259 QString cleaned{link};
260 cleaned.replace(
"\\#"_L1,
"#"_L1);
261 if ((colonPos == -1) || (!link.startsWith(
"file:") && !link.startsWith(
"mailto:")))
263 return cleaned.mid(colonPos + 1).simplified();
273 while (cmds[i].name) {
274 s_utilities
.cmdHash.insert(cmds[i].name, cmds[i].no);
277 Location::internalError(QStringLiteral(
"command %1 missing").arg(i));
283 const auto &outputFormats = config.getOutputFormats();
284 for (
const auto &format : outputFormats)
285 DocParser::s_quoting = DocParser::s_quoting
290 DocParser::file_resolver = &file_resolver;
294
295
296
297
298
299
300
301
303 const QSet<QString> &metaCommandSet,
const QSet<QString> &possibleTopics)
307 m_inputLength = m_input.size();
308 m_cachedLocation = docPrivate->m_start_loc;
309 m_cachedPosition = 0;
310 m_private = docPrivate;
314 m_paragraphState = OutsideParagraph;
315 m_inTableHeader =
false;
316 m_inTableRow =
false;
317 m_inTableItem =
false;
318 m_indexStartedParagraph =
false;
324 m_openedCommands.push(CMD_OMIT);
328 Atom *currentLinkAtom =
nullptr;
330 QStack<
bool> preprocessorSkipping;
331 int numPreprocessorSkipping = 0;
337 QString codeLanguage;
339 while (m_position < m_inputLength) {
340 QChar ch = m_input.at(m_position);
342 switch (ch.unicode()) {
345 m_backslashPosition = m_position;
347 while (m_position < m_inputLength) {
348 ch = m_input.at(m_position);
349 if (ch.isLetterOrNumber()) {
356 m_endPosition = m_position;
357 if (cmdStr.isEmpty()) {
358 if (m_position < m_inputLength) {
359 QChar nextCh = m_input.at(m_position);
360 if (nextCh ==
'\\') {
361 appendEscapedIdentifier();
362 }
else if (nextCh.isSpace()) {
365 appendChar(QLatin1Char(
' '));
368 appendChar(m_input.at(m_position++));
385 m_private->m_params.insert(p1);
389 appendAtom(Atom(Atom::CodeBad,
390 getCode(CMD_BADCODE, marker, getMetaCommandArgument(cmdStr))));
397 location().warning(QStringLiteral(
"'\\bold' is deprecated. Use '\\b'"));
404 enterPara(Atom::BriefLeft, Atom::BriefRight);
408 p1 = untabifyEtc(getArgument(ArgumentParsingOptions::Verbatim));
409 marker = CodeMarker::markerForCode(p1);
410 appendAtom(
Atom(
Atom::C, marker->markedUpCode(p1,
nullptr, location())));
414 enterPara(Atom::CaptionLeft, Atom::CaptionRight);
418 codeLanguage = getLanguageArgument(&marker);
422 appendAtom(Atom(Atom::Code, getCode(CMD_CODE, marker, getMetaCommandArgument(cmdStr)), codeLanguage));
426 appendAtom(Atom(Atom::Qml,
427 getCode(CMD_QML, CodeMarker::markerForLanguage(QLatin1String(
"QML")),
428 getMetaCommandArgument(cmdStr))));
433 if (!isBlankLine()) {
434 if (isLeftBraceAhead()) {
435 enterPara(Atom::DetailsSummaryLeft, Atom::DetailsSummaryRight);
437 location().warning(u"Expected '{' when parsing \\%1 argument"_s.arg(cmdName(cmd)));
438 std::ignore = getRestOfLine();
441 m_openedCommands.push(cmd);
450 p1 = getArgument(ArgumentParsingOptions::Verbatim);
452 m_openedCommands.push(cmd);
464 if (isCode(m_lastAtom) && m_lastAtom->string().endsWith(
"\n\n"))
469 QString arg = getOptionalArgument();
476 if (isCode(m_lastAtom) && m_lastAtom->string().endsWith(
"\n\n"))
479 int indent = arg.toInt();
480 for (
int i = 0; i < indent; ++i)
482 appendToCode(
"...\n");
486 if (!preprocessorSkipping.empty()) {
487 if (preprocessorSkipping.top()) {
488 --numPreprocessorSkipping;
490 ++numPreprocessorSkipping;
492 preprocessorSkipping.top() = !preprocessorSkipping.top();
493 (
void)getRestOfLine();
494 if (numPreprocessorSkipping)
495 skipToNextPreprocessorCommand();
498 QStringLiteral(
"Unexpected '\\%1'").arg(cmdName(
CMD_ELSE)));
508 if (closeCommand(cmd)) {
514 if (preprocessorSkipping.size() > 0) {
515 if (preprocessorSkipping.pop())
516 --numPreprocessorSkipping;
517 (
void)getRestOfLine();
518 if (numPreprocessorSkipping)
519 skipToNextPreprocessorCommand();
522 QStringLiteral(
"Unexpected '\\%1'").arg(cmdName(
CMD_ENDIF)));
526 if (closeCommand(cmd)) {
532 if (closeCommand(cmd)) {
540 if (closeCommand(cmd)) {
542 if (m_openedLists.top().isStarted()) {
543 appendAtom(Atom(Atom::ListItemRight, m_openedLists.top().styleString()));
544 appendAtom(Atom(Atom::ListRight, m_openedLists.top().styleString()));
553 if (closeCommand(cmd)) {
560 QStringLiteral(
"Unexpected '\\%1'").arg(cmdName(
CMD_ENDRAW)));
575 if (closeCommand(cmd)) {
581 if (closeCommand(cmd)) {
587 if (openCommand(cmd)) {
594 if (isLeftBracketAhead())
595 p2 = getBracketedArgument();
598 appendAtom(Atom(Atom::AnnotatedList, getArgument(), p2));
602 appendAtom(Atom(Atom::SinceList, getRestOfLine().simplified()));
606 if (isLeftBracketAhead())
607 p2 = getBracketedArgument();
610 QString arg1 = getArgument();
611 QString arg2 = getOptionalArgument();
614 appendAtom(Atom(Atom::GeneratedList, arg1, p2));
617 if (m_openedCommands.top() == CMD_TABLE) {
620 m_inTableHeader =
true;
622 if (m_openedCommands.contains(CMD_TABLE))
623 location().warning(QStringLiteral(
"Cannot use '\\%1' within '\\%2'")
625 cmdName(m_openedCommands.top())));
628 QStringLiteral(
"Cannot use '\\%1' outside of '\\%2'")
633 location().warning(QStringLiteral(
634 "'\\i' is deprecated. Use '\\e' for italic or '\\li' for list item"));
644 preprocessorSkipping.push(!Tokenizer::isTrue(getRestOfLine()));
645 if (preprocessorSkipping.top())
646 ++numPreprocessorSkipping;
647 if (numPreprocessorSkipping)
648 skipToNextPreprocessorCommand();
655 enterPara(Atom::ImportantLeft, Atom::ImportantRight);
659 QString fileName = getArgument();
660 QStringList parameters;
662 if (isLeftBraceAhead()) {
663 identifier = getArgument();
664 while (isLeftBraceAhead() && parameters.size() < 9)
665 parameters << getArgument();
667 identifier = getRestOfLine();
669 include(fileName, identifier, parameters);
676 if (m_paragraphState == OutsideParagraph) {
678 m_indexStartedParagraph =
true;
681 if (m_indexStartedParagraph
684 m_indexStartedParagraph =
false;
690 insertKeyword(getRestOfLine());
693 if (m_openedCommands.top() != CMD_TOC) {
694 location().warning(
"Command '\\%1' outside of '\\%2'"_L1
695 .arg(cmdName(cmd), cmdName(CMD_TOC)));
701 if (isLeftBracketAhead())
702 p2 = getBracketedArgument();
706 appendAtom(LinkAtom(p1, p2, location()));
708 if (isLeftBraceAhead()) {
713 appendAtom(Atom(Atom::String, cleanLink(p1)));
722 if (openCommand(cmd))
727 if (openCommand(cmd)) {
730 appendAtom(LinkAtom(p1, {}, location()));
732 skipSpacesOrOneEndl();
736 if (openCommand(cmd)) {
738 m_openedLists.push(OpenedList(location(), getOptionalArgument()));
748 enterPara(Atom::NoteLeft, Atom::NoteRight);
750 case CMD_NOTRANSLATE:
754 location().warning(QStringLiteral(
"'\\o' is deprecated. Use '\\li'"));
758 if (m_openedCommands.top() == CMD_LIST) {
759 if (m_openedLists.top().isStarted())
760 appendAtom(Atom(Atom::ListItemRight, m_openedLists.top().styleString()));
762 appendAtom(Atom(Atom::ListLeft, m_openedLists.top().styleString()));
763 m_openedLists.top().next();
764 appendAtom(Atom(Atom::ListItemNumber, m_openedLists.top().numberString()));
765 appendAtom(Atom(Atom::ListItemLeft, m_openedLists.top().styleString()));
767 }
else if (m_openedCommands.top() == CMD_TABLE) {
770 if (isLeftBraceAhead()) {
772 if (isLeftBraceAhead())
776 if (!m_inTableHeader && !m_inTableRow) {
778 QStringLiteral(
"Missing '\\%1' or '\\%2' before '\\%3'")
783 }
else if (m_inTableItem) {
785 m_inTableItem =
false;
788 appendAtom(Atom(Atom::TableItemLeft, p1, p2));
789 m_inTableItem =
true;
792 QStringLiteral(
"Command '\\%1' outside of '\\%2' and '\\%3'")
801 if (!m_private->m_enumItemList.contains(p1))
802 m_private->m_enumItemList.append(p1);
803 if (!m_private->m_omitEnumItemList.contains(p1))
804 m_private->m_omitEnumItemList.append(p1);
805 skipSpacesOrOneEndl();
807 while (m_position < m_inputLength && !isBlankLine()) {
809 if (qsizetype pos = m_position; pos < m_input.size()
810 && m_input.at(pos++).unicode() ==
'\\') {
812 while (pos < m_input.size() && m_input[pos].isLetterOrNumber())
813 nextCmdStr += m_input[pos++];
815 if (nextCmd == cmd || nextCmd ==
CMD_VALUE)
824 p1 = getRestOfLine();
825 if (openCommand(cmd))
829 if (closeCommand(cmd)) {
841 QString rest = getRestOfLine();
846 if (cmd == CMD_PRINTLINE)
847 appendToCode(m_quoter.quoteLine(location(), cmdStr, rest), atomType, codeLanguage);
848 else if (cmd == CMD_PRINTTO)
849 appendToCode(m_quoter.quoteTo(location(), cmdStr, rest), atomType, codeLanguage);
851 appendToCode(m_quoter.quoteUntil(location(), cmdStr, rest), atomType, codeLanguage);
855 if (openCommand(cmd)) {
863 codeLanguage = getLanguageArgument(&marker);
866 QString fileName = getArgument();
872 marker = CodeMarker::markerForFileName(fileName);
874 quoteFromFile(fileName, marker);
876 appendAtom(Atom(Atom::Code, m_quoter.quoteTo(location(), cmdStr, QString()), codeLanguage));
883 p1 = getRestOfLine();
885 location().warning(QStringLiteral(
"Missing format name after '\\%1'")
893 if (m_openedCommands.top() == CMD_TABLE) {
895 if (isLeftBraceAhead())
896 p1 = getArgument(ArgumentParsingOptions::Verbatim);
901 if (m_openedCommands.contains(CMD_TABLE))
902 location().warning(QStringLiteral(
"Cannot use '\\%1' within '\\%2'")
904 cmdName(m_openedCommands.top())));
906 location().warning(QStringLiteral(
"Cannot use '\\%1' outside of '\\%2'")
926 if (openCommand(cmd)) {
933 QString rest = getRestOfLine();
938 m_quoter.quoteLine(location(), cmdStr, rest);
943 QString rest = getRestOfLine();
948 m_quoter.quoteTo(location(), cmdStr, rest);
953 QString rest = getRestOfLine();
958 m_quoter.quoteUntil(location(), cmdStr, rest);
963 startFormat(p1, cmd);
967 codeLanguage = getLanguageArgument(&marker);
970 QString snippet = getArgument();
971 QString identifier = getRestOfLine();
978 marker = CodeMarker::markerForFileName(snippet);
980 quoteFromFile(snippet, marker);
981 appendToCode(m_quoter.quoteSnippet(location(), identifier), marker->atomType(), codeLanguage);
992 p1 = getOptionalArgument();
993 p2 = getOptionalArgument();
994 if (openCommand(cmd)) {
996 appendAtom(Atom(Atom::TableLeft, p1, p2));
997 m_inTableHeader =
false;
998 m_inTableRow =
false;
999 m_inTableItem =
false;
1003 location().report(
"\\%1 is deprecated and will be removed in a future version."_L1.arg(cmdName(cmd)));
1004 if (isLeftBraceAhead())
1008 if (m_openedCommands.top() == CMD_TABLE && !m_inTableItem) {
1009 location().warning(
"Found a \\target command outside table item in a table.\n"
1010 "Move the \\target inside the \\li to resolve this warning.");
1012 insertTarget(getRestOfLine());
1016 enterPara(Atom::TitleLeft, Atom::TitleRight);
1020 if (m_paragraphState != InSingleLineParagraph)
1024 if (openCommand(cmd)) {
1030 if (closeCommand(cmd)) {
1048 uint unicodeChar = p1.toUInt(&ok, 0);
1049 if (!ok || (unicodeChar == 0x0000) || (unicodeChar > 0xFFFE))
1051 QStringLiteral(
"Invalid Unicode character '%1' specified with '%2'")
1059 if (m_openedLists.top().style() == OpenedList::Value) {
1062 if (p1.startsWith(QLatin1String(
"[since "))
1063 && p1.endsWith(QLatin1String(
"]"))) {
1064 p2 = p1.mid(7, p1.size() - 8);
1067 if (!m_private->m_enumItemList.contains(p1))
1068 m_private->m_enumItemList.append(p1);
1070 m_openedLists.top().next();
1074 if (!p2.isEmpty()) {
1081 skipSpacesOrOneEndl();
1090 enterPara(Atom::WarningLeft, Atom::WarningRight);
1096 if (metaCommandSet.contains(cmdStr)) {
1100 QString bracketedArg;
1101 const bool isDeprecation = cmdStr ==
"deprecated"_L1
1102 || cmdStr ==
"obsolete"_L1;
1103 m_private->m_metacommandsUsed.insert(cmdStr);
1104 if (isDeprecation ? isLeftBracketAhead(0) : isLeftBracketAhead())
1105 bracketedArg = getBracketedArgument();
1106 if (isDeprecation) {
1111 if (m_position < m_inputLength && m_input.at(m_position) != u'\n')
1112 enterPara(Atom::DeprecatedLeft, Atom::DeprecatedRight);
1114 arg = getMetaCommandArgument(cmdStr);
1117 if (possibleTopics.contains(cmdStr)) {
1118 if (!cmdStr.endsWith(QLatin1String(
"propertygroup")))
1121 }
else if (s_utilities
.macroHash.contains(cmdStr)) {
1123 QStringList macroArgs;
1124 int numPendingFi = 0;
1125 int numFormatDefs = 0;
1126 for (
auto it = macro.m_otherDefs.constBegin();
1127 it != macro.m_otherDefs.constEnd(); ++it) {
1128 if (it.key() !=
"match") {
1129 if (numFormatDefs == 0)
1130 macroArgs = getMacroArguments(cmdStr, macro);
1132 expandMacro(*it, macroArgs);
1134 if (it == macro.m_otherDefs.constEnd()) {
1142 while (numPendingFi-- > 0)
1145 if (!macro.m_defaultDef.isEmpty()) {
1146 if (numFormatDefs > 0) {
1147 macro.m_defaultDefLocation.warning(
1148 QStringLiteral(
"Macro cannot have both "
1149 "format-specific and qdoc-"
1150 "syntax definitions"));
1152 QString expanded = expandMacroToString(cmdStr, macro);
1153 m_input.replace(m_backslashPosition,
1154 m_endPosition - m_backslashPosition, expanded);
1155 m_inputLength = m_input.size();
1156 m_position = m_backslashPosition;
1159 }
else if (isAutoLinkString(cmdStr)) {
1162 if (!cmdStr.endsWith(
"propertygroup")) {
1165 location().warning(QStringLiteral(
"Unknown command '\\%1'").arg(cmdStr),
1166 detailsUnknownCommand(metaCommandSet, cmdStr));
1177 qsizetype dashCount = 1;
1181 while ((m_position < m_inputLength) && (m_input.at(m_position) ==
'-')) {
1186 if (dashCount == 3) {
1188 const QChar emDash(8212);
1190 }
else if (dashCount == 2) {
1192 const QChar enDash(8211);
1198 for (qsizetype i = 0; i < dashCount; ++i)
1207 if (m_paragraphState != InBraceDelimitedParagraph)
1216 auto format = m_pendingFormats.find(m_braceDepth);
1217 if (format == m_pendingFormats.end()) {
1218 if (m_paragraphState == InBraceDelimitedParagraph) {
1228 if (m_indexStartedParagraph)
1233 if (currentLinkAtom && currentLinkAtom->string().endsWith(
"::")) {
1237 currentLinkAtom->concatenateString(suffix);
1239 currentLinkAtom =
nullptr;
1243 m_pendingFormats.erase(format);
1249 if (m_position + 2 < m_inputLength)
1250 if (m_input.at(m_position + 1) ==
'/')
1251 if (m_input.at(m_position + 2) ==
'!') {
1254 if (m_input.at(m_position - 1) ==
'\n')
1270 if (m_paragraphState == OutsideParagraph) {
1282 && (m_paragraphState == InSingleLineParagraph || isBlankLine())) {
1295 qsizetype startPos = m_position;
1297 bool autolink = (!m_pendingFormats.isEmpty() &&
1299 || m_paragraphState == InSingleLineParagraph ?
1300 false : isAutoLinkString(m_input, m_position);
1301 if (m_position == startPos) {
1302 if (!ch.isSpace()) {
1307 QString word = m_input.mid(startPos, m_position - startPos);
1309 if (s_ignoreWords.contains(word) || word.startsWith(QString(
"__")))
1324 if (m_openedCommands.top() == CMD_LEGALESE) {
1326 m_openedCommands.pop();
1329 if (m_openedCommands.top() != CMD_OMIT) {
1331 QStringLiteral(
"Missing '\\%1'").arg(endCmdName(m_openedCommands.top())));
1332 }
else if (preprocessorSkipping.size() > 0) {
1333 location().warning(QStringLiteral(
"Missing '\\%1'").arg(cmdName(
CMD_ENDIF)));
1337 appendAtom(Atom(Atom::SectionRight, QString::number(m_currentSection)));
1345
1346
1349 while (!m_openedInputs.isEmpty() && m_openedInputs.top() <= m_position) {
1350 m_cachedLocation.pop();
1351 m_cachedPosition = m_openedInputs.pop();
1353 while (m_cachedPosition < m_position)
1354 m_cachedLocation.advance(m_input.at(m_cachedPosition++));
1355 return m_cachedLocation;
1358QString
DocParser::detailsUnknownCommand(
const QSet<QString> &metaCommandSet,
const QString &str)
1360 QSet<QString> commandSet = metaCommandSet;
1362 while (cmds[i].name !=
nullptr) {
1363 commandSet.insert(cmds[i].name);
1367 return "Maybe you meant '\\%1'?"_L1.arg(suggestName(str, commandSet));
1371
1372
1373
1374
1375
1376
1377
1379 const QString &cmdString,
const QString &previousDefinition)
1381 if (duplicateDefinition.isEmpty()) {
1382 location.warning(
"Expected an argument for \\%1"_L1.arg(cmdString));
1385 "Duplicate %3 name '%1'. The previous occurrence is here: %2"_L1
1386 .arg(duplicateDefinition, previousDefinition, cmdString));
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404void DocParser::insertTarget(
const QString &target)
1406 if (target.isEmpty() || m_targetMap.contains(target))
1407 return warnAboutEmptyOrPreexistingTarget(location(), target,
1408 s_utilities.cmdHash.key(CMD_TARGET), m_targetMap[target].toString());
1410 m_targetMap.insert(target, location());
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431void DocParser::insertKeyword(
const QString &keyword)
1433 if (keyword.isEmpty() || m_targetMap.contains(keyword))
1434 return warnAboutEmptyOrPreexistingTarget(location(), keyword,
1435 s_utilities.cmdHash.key(CMD_KEYWORD), m_targetMap[keyword].toString());
1437 m_targetMap.insert(keyword, location());
1444void DocParser::include(
const QString &fileName,
const QString &identifier,
const QStringList ¶meters)
1447 location().fatal(QStringLiteral(
"Too many nested '\\%1's").arg(cmdName(
CMD_INCLUDE)));
1448 QString filePath = Config::instance().getIncludeFilePath(fileName);
1449 if (filePath.isEmpty()) {
1450 location().warning(QStringLiteral(
"Cannot find qdoc include file '%1'").arg(fileName));
1452 QFile inFile(filePath);
1453 if (!inFile.open(QFile::ReadOnly)) {
1455 QStringLiteral(
"Cannot open qdoc include file '%1'").arg(filePath));
1457 location().push(fileName);
1458 QTextStream inStream(&inFile);
1459 QString includedContent = inStream.readAll();
1462 if (identifier.isEmpty()) {
1463 expandArgumentsInString(includedContent, parameters);
1464 m_input.insert(m_position, includedContent);
1465 m_inputLength = m_input.size();
1466 m_openedInputs.push(m_position + includedContent.size());
1468 auto isSnippetMarker = [&identifier](QStringView trimmedLine) ->
bool {
1469 if (!trimmedLine.startsWith(QLatin1String(
"//!")))
1471 auto bracketStart = trimmedLine.indexOf(QLatin1Char(
'['));
1472 auto bracketEnd = trimmedLine.indexOf(QLatin1Char(
']'));
1473 if (bracketStart < 0 || bracketEnd <= bracketStart)
1475 auto name = trimmedLine.mid(bracketStart + 1, bracketEnd - bracketStart - 1)
1477 return name == identifier;
1480 QStringList lineBuffer = includedContent.split(QLatin1Char(
'\n'));
1481 qsizetype bufLen{lineBuffer.size()};
1483 QStringView trimmedLine;
1484 for (i = 0; i < bufLen; ++i) {
1485 trimmedLine = QStringView{lineBuffer[i]}.trimmed();
1486 if (isSnippetMarker(trimmedLine))
1489 if (i < bufLen - 1) {
1493 QStringLiteral(
"Cannot find '%1' in '%2'").arg(identifier, filePath));
1498 trimmedLine = QStringView{lineBuffer[i]}.trimmed();
1499 if (isSnippetMarker(trimmedLine))
1502 result += lineBuffer[i] + QLatin1Char(
'\n');
1504 }
while (i < bufLen);
1506 expandArgumentsInString(result, parameters);
1507 if (result.isEmpty()) {
1508 location().warning(QStringLiteral(
"Empty qdoc snippet '%1' in '%2'")
1509 .arg(identifier, filePath));
1511 m_input.insert(m_position, result);
1512 m_inputLength = m_input.size();
1513 m_openedInputs.push(m_position + result.size());
1520void DocParser::startFormat(
const QString &format,
int cmd)
1524 for (
const auto &item : std::as_const(m_pendingFormats)) {
1525 if (item == format) {
1526 location().warning(QStringLiteral(
"Cannot nest '\\%1' commands").arg(cmdName(cmd)));
1533 if (isLeftBraceAhead()) {
1534 skipSpacesOrOneEndl();
1535 m_pendingFormats.insert(m_braceDepth, format);
1539 const auto &arg{getArgument()};
1544 m_indexStartedParagraph =
false;
1553 int outer = m_openedCommands.top();
1556 if ((cmd == CMD_COMPARESWITH || cmd == CMD_TOC)
1557 && m_openedCommands.contains(cmd)) {
1558 location().warning(u"Cannot nest '\\%1' commands"_s.arg(cmdName(cmd)));
1575 m_openedCommands.push(cmd);
1578 QStringLiteral(
"Can't use '\\%1' in '\\%2'").arg(cmdName(cmd), cmdName(outer)));
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660inline bool DocParser::isAutoLinkString(
const QString &word)
1662 qsizetype start = 0;
1663 return isAutoLinkString(word, start) && (start == word.size());
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687bool DocParser::isAutoLinkString(
const QString &word, qsizetype &curPos)
1689 qsizetype len = word.size();
1690 qsizetype startPos = curPos;
1691 int numUppercase = 0;
1692 int numLowercase = 0;
1693 int numStrangeSymbols = 0;
1695 while (curPos < len) {
1696 unsigned char latin1Ch = word.at(curPos).toLatin1();
1697 if (islower(latin1Ch)) {
1700 }
else if (isupper(latin1Ch)) {
1701 if (curPos > startPos)
1704 }
else if (isdigit(latin1Ch)) {
1705 if (curPos > startPos)
1709 }
else if (latin1Ch ==
'_' || latin1Ch ==
'@') {
1710 ++numStrangeSymbols;
1712 }
else if ((latin1Ch ==
':') && (curPos < len - 1)
1713 && (word.at(curPos + 1) == QLatin1Char(
':'))) {
1714 ++numStrangeSymbols;
1716 }
else if (latin1Ch ==
'(') {
1717 if ((curPos < len - 1) && (word.at(curPos + 1) == QLatin1Char(
')'))) {
1718 ++numStrangeSymbols;
1728 return ((numUppercase >= 1 && numLowercase >= 2) || (numStrangeSymbols > 0 && (numUppercase + numLowercase >= 1)));
1733 if (endCmdFor(m_openedCommands.top()) == endCmd && m_openedCommands.size() > 1) {
1734 m_openedCommands.pop();
1737 bool contains =
false;
1738 QStack<
int> opened2 = m_openedCommands;
1739 while (opened2.size() > 1) {
1748 while (endCmdFor(m_openedCommands.top()) != endCmd && m_openedCommands.size() > 1) {
1750 QStringLiteral(
"Missing '\\%1' before '\\%2'")
1751 .arg(endCmdName(m_openedCommands.top()), cmdName(endCmd)));
1752 m_openedCommands.pop();
1755 location().warning(QStringLiteral(
"Unexpected '\\%1'").arg(cmdName(endCmd)));
1766 m_currentSection =
static_cast<
Doc::
Sections>(unit);
1769 endSection(unit, cmd);
1772 appendAtom(Atom(Atom::SectionLeft, QString::number(unit)));
1775 m_private
->extra->m_tableOfContentsLevels.append(unit);
1776 enterPara(Atom::SectionHeadingLeft, Atom::SectionHeadingRight, QString::number(unit));
1777 m_currentSection = unit;
1783 appendAtom(Atom(Atom::SectionRight, QString::number(m_currentSection)));
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1801 const Location imageLocation = location();
1819 const QString imageFileName = getArgument();
1821 bool hasAltTextArgument{
false};
1822 if (isLeftBraceAhead()) {
1823 hasAltTextArgument =
true;
1824 imageText = getArgument();
1826 imageText = getRestOfLine();
1829 if (imageText.length() > 1) {
1830 if (imageText.front() ==
'"' && imageText.back() ==
'"') {
1831 imageText.removeFirst();
1832 imageText.removeLast();
1836 if (!hasAltTextArgument && imageText.isEmpty()
1837 && Config::instance().reportMissingAltTextForImages()) {
1838 imageLocation.report(
1839 "\\%1 %2 is without a textual description, "
1840 "QDoc will not generate an alt text for the image."_L1.arg(cmdName(cmd))
1841 .arg(imageFileName));
1843 appendAtom(
Atom(imageAtom, imageFileName));
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1862 const QString cmd{
"overload"};
1865 m_private->m_metacommandsUsed.insert(cmd);
1866 QString overloadArgument = isBlankLine() ? getMetaCommandArgument(cmd) : getRestOfLine();
1871 if (overloadArgument.trimmed() ==
"primary")
1872 overloadArgument =
"__qdoc_primary_overload__"_L1;
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1892 auto line_comment = [
this]() ->
bool {
1894 if (m_position + 2 > m_inputLength)
1896 if (m_input[m_position].unicode() ==
'/') {
1897 if (m_input[m_position + 1].unicode() ==
'/') {
1898 if (m_input[m_position + 2].unicode() ==
'!') {
1906 auto skip_everything_until_newline = [
this]() ->
void {
1907 while (m_position < m_inputLength && m_input[m_position] !=
'\n')
1913 while (m_position < m_inputLength && m_input[m_position] !=
'\n') {
1916 bool skipMe =
false;
1918 if (m_input[m_position] ==
'{') {
1919 target = getArgument();
1920 if (isLeftBraceAhead()) {
1921 str = getArgument();
1925 if (target.endsWith(
"::"))
1931 target = getArgument();
1932 str = cleanLink(target);
1933 if (target == QLatin1String(
"and") || target == QLatin1String(
"."))
1939 also << LinkAtom(target, {}, location())
1948 skip_everything_until_newline();
1950 if (m_position < m_inputLength && m_input[m_position] ==
',') {
1953 skip_everything_until_newline();
1954 skipSpacesOrOneEndl();
1955 }
else if (m_position >= m_inputLength || m_input[m_position] !=
'\n') {
1956 location().warning(QStringLiteral(
"Missing comma in '\\%1'").arg(cmdName(
CMD_SA)));
1970 if (ch == QLatin1Char(
' ')) {
1971 if (!atom->string().endsWith(QLatin1Char(
' ')))
1972 atom->appendChar(QLatin1Char(
' '));
1974 atom->appendChar(ch);
1977void DocParser::appendWord(
const QString &word)
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997void DocParser::appendEscapedIdentifier()
1999 Q_ASSERT(m_position < m_inputLength);
2000 Q_ASSERT(m_input.at(m_position) ==
'\\');
2005 while (m_position < m_inputLength && m_input.at(m_position).isLetterOrNumber()) {
2006 identifier += m_input.at(m_position);
2011 if (!identifier.isEmpty()) {
2016 if (m_position + 1 < m_inputLength && m_input.at(m_position) ==
'\r' && m_input.at(m_position + 1) ==
'\n')
2019 appendChar(QLatin1Char(
'\\'));
2023void DocParser::appendToCode(
const QString &markedCode)
2025 if (!isCode(m_lastAtom)) {
2029 m_lastAtom->concatenateString(markedCode);
2033
2034
2035
2036
2037
2038void DocParser::appendToCode(
const QString &markedCode,
Atom::
AtomType defaultType,
const QString &language)
2040 if (!isCode(m_lastAtom)) {
2041 appendAtom(
Atom(defaultType, markedCode, language));
2044 m_lastAtom->concatenateString(markedCode);
2050 if (m_paragraphState != OutsideParagraph)
2061 const bool inValueList = !m_openedLists.isEmpty()
2062 && m_openedLists.top().style() == OpenedList::Value;
2066 if (!inValueList || !isAdmonition)
2070 appendAtom(
Atom(leftType, string));
2071 m_indexStartedParagraph =
false;
2072 m_pendingParagraphLeftType = leftType;
2073 m_pendingParagraphRightType = rightType;
2074 m_pendingParagraphString = string;
2076 m_paragraphState = InSingleLineParagraph;
2078 m_paragraphState = InBraceDelimitedParagraph;
2080 m_paragraphState = InMultiLineParagraph;
2082 skipSpacesOrOneEndl();
2087 if (m_paragraphState == OutsideParagraph)
2089 if (!m_pendingFormats.isEmpty() || (m_paragraphState == InBraceDelimitedParagraph && m_braceDepth > 0)) {
2090 location().warning(u"Missing '}'"_s);
2091 m_pendingFormats.clear();
2107 appendAtom(Atom(m_pendingParagraphRightType, m_pendingParagraphString));
2110 m_paragraphState = OutsideParagraph;
2111 m_indexStartedParagraph =
false;
2112 m_pendingParagraphRightType =
Atom::Nop;
2113 m_pendingParagraphString.clear();
2119 if (m_openedLists.isEmpty()) {
2120 m_openedLists.push(OpenedList(OpenedList::Value));
2132 if (!m_openedLists.isEmpty() && (m_openedLists.top().style() == OpenedList::Value)) {
2137 m_openedLists.pop();
2143 if (m_inTableItem) {
2146 m_inTableItem =
false;
2148 if (m_inTableHeader) {
2150 m_inTableHeader =
false;
2154 m_inTableRow =
false;
2159
2160
2161
2162
2176 auto maybe_resolved_file{(*file_resolver).resolve(filename)};
2177 if (!maybe_resolved_file) {
2186 QString details =
std::transform_reduce(
2187 (*file_resolver).get_search_directories().cbegin(),
2188 (*file_resolver).get_search_directories().cend(),
2189 u"Searched directories:"_s,
2191 [](
const DirectoryPath &directory_path) -> QString {
return u' ' + directory_path.value(); }
2194 location().warning(u"Cannot find file to quote from: %1"_s.arg(filename), details);
2211 marker = CodeMarker::markerForFileName(QString{});
2212 m_quoter.quoteFromFile(filename, QString{}, marker->markedUpCode(QString{},
nullptr, location()));
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242bool DocParser::expandMacro(ArgumentParsingOptions options)
2244 Q_ASSERT(m_input[m_position].unicode() ==
'\\');
2246 if (options == ArgumentParsingOptions::Verbatim)
2250 qsizetype backslashPos = m_position++;
2251 while (m_position < m_input.size() && m_input[m_position].isLetterOrNumber())
2252 cmdStr += m_input[m_position++];
2254 m_endPosition = m_position;
2255 if (!cmdStr.isEmpty()) {
2256 if (s_utilities
.macroHash.contains(cmdStr)) {
2258 if (!macro.m_defaultDef.isEmpty()) {
2259 QString expanded = expandMacroToString(cmdStr, macro);
2260 m_input.replace(backslashPos, m_position - backslashPos, expanded);
2261 m_inputLength = m_input.size();
2262 m_position = backslashPos;
2265 location().warning(
"Macro '%1' does not have a default definition"_L1.arg(cmdStr));
2269 m_position = backslashPos;
2270 if (options != ArgumentParsingOptions::MacroArguments
2271 || cmd ==
NOT_A_CMD || !cmds[cmd].is_formatting_command) {
2272 location().warning(
"Unknown macro '%1'"_L1.arg(cmdStr));
2276 }
else if (m_input[m_position].isSpace()) {
2278 }
else if (m_input[m_position].unicode() ==
'\\') {
2280 m_input.remove(m_position--, 1);
2286void DocParser::expandMacro(
const QString &def,
const QStringList &args)
2288 if (args.isEmpty()) {
2293 for (
int j = 0; j < def.size(); ++j) {
2294 if (
int paramNo = def[j].unicode(); paramNo >= 1 && paramNo <= args.length()) {
2295 if (!rawString.isEmpty()) {
2301 rawString += def[j];
2304 if (!rawString.isEmpty())
2309QString
DocParser::expandMacroToString(
const QString &name,
const Macro ¯o)
2311 const QString &def{macro.m_defaultDef};
2315 rawString = macro.m_defaultDef;
2317 QStringList args{getMacroArguments(name, macro)};
2319 for (
int j = 0; j < def.size(); ++j) {
2320 int paramNo = def[j].unicode();
2321 rawString += (paramNo >= 1 && paramNo <= args.length()) ? args[paramNo - 1] : def[j];
2324 QString matchExpr{macro.m_otherDefs.value(
"match")};
2325 if (matchExpr.isEmpty())
2329 QRegularExpression re(matchExpr);
2330 int capStart = (re.captureCount() > 0) ? 1 : 0;
2332 QRegularExpressionMatch match;
2333 while ((match = re.match(rawString, i)).hasMatch()) {
2334 for (
int c = capStart; c <= re.captureCount(); ++c)
2335 result += match.captured(c);
2336 i = match.capturedEnd();
2344 QString name = getOptionalArgument();
2346 if (name ==
"section1") {
2348 }
else if (name ==
"section2") {
2350 }
else if (name ==
"section3") {
2352 }
else if (name ==
"section4") {
2354 }
else if (name.isEmpty()) {
2357 location().warning(QStringLiteral(
"Invalid section '%1'").arg(name));
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372QString
DocParser::getBracedArgument(ArgumentParsingOptions options)
2376 if (m_position < m_input.size() && m_input[m_position] ==
'{') {
2378 while (m_position < m_input.size() && delimDepth >= 0) {
2379 switch (m_input[m_position].unicode()) {
2382 arg += QLatin1Char(
'{');
2387 if (delimDepth >= 0)
2388 arg += QLatin1Char(
'}');
2392 if (!expandMacro(options))
2393 arg += m_input[m_position++];
2396 if (m_input[m_position].isSpace() && options != ArgumentParsingOptions::Verbatim)
2399 arg += m_input[m_position];
2404 location().warning(QStringLiteral(
"Missing '}'"));
2406 m_endPosition = m_position;
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426QString
DocParser::getArgument(ArgumentParsingOptions options)
2428 skipSpacesOrOneEndl();
2431 qsizetype startPos = m_position;
2432 QString arg = getBracedArgument(options);
2433 if (arg.isEmpty()) {
2434 while ((m_position < m_input.size())
2435 && ((delimDepth > 0) || ((delimDepth == 0) && !m_input[m_position].isSpace()))) {
2436 switch (m_input[m_position].unicode()) {
2441 arg += m_input[m_position];
2448 if (m_position == startPos || delimDepth >= 0) {
2449 arg += m_input[m_position];
2454 if (!expandMacro(options))
2455 arg += m_input[m_position++];
2458 arg += m_input[m_position];
2462 m_endPosition = m_position;
2463 if ((arg.size() > 1) && (QString(
".,:;!?").indexOf(m_input[m_position - 1]) != -1)
2464 && !arg.endsWith(
"...")) {
2465 arg.truncate(arg.size() - 1);
2468 if (arg.size() > 2 && m_input.mid(m_position - 2, 2) ==
"'s") {
2469 arg.truncate(arg.size() - 2);
2473 return arg.simplified();
2477
2478
2479
2480
2481
2482QString
DocParser::getBracketedArgument()
2486 skipSpacesOrOneEndl();
2487 if (m_position < m_input.size() && m_input[m_position] ==
'[') {
2489 while (m_position < m_input.size() && delimDepth >= 0) {
2490 switch (m_input[m_position].unicode()) {
2493 arg += QLatin1Char(
'[');
2498 if (delimDepth >= 0)
2499 arg += QLatin1Char(
']');
2503 arg += m_input[m_position];
2507 arg += m_input[m_position];
2512 location().warning(QStringLiteral(
"Missing ']'"));
2518
2519
2520
2521
2522
2523
2524
2528 if (isLeftBracketAhead(0)) {
2529 value = getBracketedArgument();
2530 *marker = markerForLanguage(value);
2535 return value.toLower();
2539
2540
2541
2542
2543
2544QStringList
DocParser::getMacroArguments(
const QString &name,
const Macro ¯o)
2548 if (macro
.numParams == 1 || isLeftBraceAhead()) {
2549 args << getArgument(ArgumentParsingOptions::MacroArguments);
2551 location().warning(QStringLiteral(
"Macro '\\%1' invoked with too few"
2552 " arguments (expected %2, got %3)")
2563
2564
2565
2566
2569 skipSpacesOrOneEndl();
2570 const bool nextIsCommand = m_position + 1 < m_input.size() && m_input[m_position] ==
'\\'
2571 && m_input[m_position + 1].isLetterOrNumber();
2572 const bool nextIsComment = m_position + 2 < m_input.size() && m_input[m_position] ==
'/'
2573 && m_input[m_position + 1] ==
'/' && m_input[m_position + 2] ==
'!';
2574 if (nextIsCommand || nextIsComment) {
2577 return getArgument();
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2598 auto atLineEnd = [
this]() ->
bool {
2599 return m_position >= m_inputLength || m_input[m_position] ==
'\n'
2600 || m_input[m_position] ==
'\r';
2603 auto lineHasTrailingBackslash = [
this, &atLineEnd](
bool trailingBackslash) ->
bool {
2604 while (!atLineEnd()) {
2605 if (m_input[m_position] ==
'\\' && !trailingBackslash) {
2606 trailingBackslash =
true;
2610 trailingBackslash =
false;
2614 return trailingBackslash;
2617 QString rest_of_line;
2619 bool trailing_backslash{
false };
2620 bool return_simplified_string{
false };
2622 for (qsizetype start_position = m_position; m_position < m_inputLength; ++m_position) {
2623 trailing_backslash = lineHasTrailingBackslash(trailing_backslash);
2625 if (!rest_of_line.isEmpty())
2626 rest_of_line += QLatin1Char(
' ');
2627 rest_of_line += m_input.sliced(start_position, m_position - start_position);
2629 if (trailing_backslash) {
2630 rest_of_line.truncate(rest_of_line.lastIndexOf(
'\\'));
2631 return_simplified_string =
true;
2634 if (m_position < m_inputLength && m_input[m_position] ==
'\r')
2636 if (m_position < m_inputLength && m_input[m_position] ==
'\n')
2639 if (!trailing_backslash)
2642 while (m_position < m_inputLength
2643 && (m_input[m_position] ==
'\r' || m_input[m_position] ==
'\n'))
2646 start_position = m_position;
2649 if (return_simplified_string)
2650 return rest_of_line.simplified();
2652 return rest_of_line.trimmed();
2656
2657
2658
2659
2660QString
DocParser::getMetaCommandArgument(
const QString &cmdStr)
2664 qsizetype begin = m_position;
2667 while (m_position < m_input.size() && (m_input[m_position] !=
'\n' || parenDepth > 0)) {
2668 if (m_input.at(m_position) ==
'(')
2670 else if (m_input.at(m_position) ==
')')
2672 else if (m_input.at(m_position) ==
'\\' && expandMacro(ArgumentParsingOptions::Default))
2676 if (m_position == m_input.size() && parenDepth > 0) {
2678 location().warning(QStringLiteral(
"Unbalanced parentheses in '%1'").arg(cmdStr));
2681 QString t = m_input.mid(begin, m_position - begin).simplified();
2689 QRegularExpression rx(
"\\\\" + cmdName(endCmd) +
"\\b");
2691 auto match = rx.match(m_input, m_position);
2693 if (!match.hasMatch()) {
2694 location().warning(QStringLiteral(
"Missing '\\%1'").arg(cmdName(endCmd)));
2695 m_position = m_input.size();
2697 qsizetype end = match.capturedStart();
2698 t = m_input.mid(m_position, end - m_position);
2699 m_position = match.capturedEnd();
2704void DocParser::expandArgumentsInString(QString &str,
const QStringList &args)
2711 while (j < str.size()) {
2712 if (str[j] ==
'\\' && j < str.size() - 1 && (paramNo = str[j + 1].digitValue()) >= 1
2713 && paramNo <= args.size()) {
2714 const QString &r = args[paramNo - 1];
2715 str.replace(j, 2, r);
2716 j += qMin(1, r.size());
2724
2725
2726
2727
2728
2729
2732 QString code = untabifyEtc(getUntilEnd(cmd));
2733 expandArgumentsInString(code, argStr.split(
" ", Qt::SkipEmptyParts));
2735 int indent = indentLevel(code);
2736 code = dedent(indent, code);
2739 if (!marker && !m_private->m_topics.isEmpty()
2740 && m_private->m_topics[0].m_topic.startsWith(
"qml")) {
2741 auto qmlMarker = CodeMarker::markerForLanguage(
"QML");
2742 marker = (qmlMarker && qmlMarker->recognizeCode(code)) ? qmlMarker :
nullptr;
2744 if (marker ==
nullptr)
2745 marker = CodeMarker::markerForCode(code);
2746 return marker->markedUpCode(code,
nullptr, location());
2751 qsizetype i = m_position;
2753 while (i < m_inputLength && m_input[i].isSpace()) {
2754 if (m_input[i] ==
'\n')
2764 qsizetype i = m_position;
2766 while (i < m_inputLength && m_input[i].isSpace() && numEndl < 2) {
2768 if (m_input[i] ==
'\n')
2772 return numEndl < 2 && i < m_inputLength && m_input[i] ==
'{';
2775bool DocParser::isLeftBracketAhead(
int maxNewlines)
2778 qsizetype i = m_position;
2780 while (i < m_inputLength && m_input[i].isSpace() && numEndl < 2) {
2782 if (m_input[i] ==
'\n')
2786 return numEndl <= maxNewlines && i < m_inputLength && m_input[i] ==
'[';
2790
2791
2794 while ((m_position < m_input.size()) && m_input[m_position].isSpace()
2795 && (m_input[m_position].unicode() !=
'\n'))
2800
2801
2804 qsizetype firstEndl = -1;
2805 while (m_position < m_input.size() && m_input[m_position].isSpace()) {
2806 QChar ch = m_input[m_position];
2808 if (firstEndl == -1) {
2809 firstEndl = m_position;
2811 m_position = firstEndl;
2821 while (m_position < m_inputLength && m_input[m_position].isSpace())
2825void DocParser::skipToNextPreprocessorCommand()
2827 QRegularExpression rx(
"\\\\(?:" + cmdName(CMD_IF) + QLatin1Char(
'|') + cmdName(CMD_ELSE)
2828 + QLatin1Char(
'|') + cmdName(CMD_ENDIF) +
")\\b");
2829 auto match = rx.match(m_input, m_position + 1);
2831 if (!match.hasMatch())
2832 m_position = m_input.size();
2834 m_position = match.capturedStart();
2887 return cmds[cmd].name;
2892 return cmdName(endCmdFor(cmd));
2898 result.reserve(str.size());
2901 for (
const auto &character : str) {
2902 if (character == QLatin1Char(
'\r'))
2904 if (character == QLatin1Char(
'\t')) {
2905 result += &
" "[column % s_tabSize];
2906 column = ((column / s_tabSize) + 1) * s_tabSize;
2909 if (character == QLatin1Char(
'\n')) {
2910 while (result.endsWith(QLatin1Char(
' ')))
2912 result += character;
2916 result += character;
2920 while (result.endsWith(
"\n\n"))
2921 result.truncate(result.size() - 1);
2922 while (result.startsWith(QLatin1Char(
'\n')))
2923 result = result.mid(1);
2930 int minIndent = INT_MAX;
2933 for (
const auto &character : str) {
2934 if (character ==
'\n') {
2937 if (character !=
' ' && column < minIndent)
2953 for (
const auto &character : str) {
2954 if (character == QLatin1Char(
'\n')) {
2958 if (column >= level)
2959 result += character;
2967
2968
2976
2977
2987
2988
2989
2990
2993 CodeMarker *marker = CodeMarker::markerForLanguage(language.toLower());
2995 if (!marker && !s_allowedLanguages.contains(language, Qt::CaseInsensitive))
2996 location().warning(QStringLiteral(
"Unrecognized markup language '%1'").arg(language));
3002
3003
3004
3005
3006
3007
3008
3009
3012 static auto take_while = [](QStringView input,
auto predicate) {
3013 QStringView::size_type end{0};
3015 while (end < input.size() &&
std::invoke(predicate, input[end]))
3018 return std::make_tuple(input.sliced(0, end), input.sliced(end));
3021 static auto peek = [](QStringView input, QChar c) {
3022 return !input.empty() && input.first() == c;
3025 static auto skip_one = [](QStringView input) {
3026 if (input.empty())
return std::make_tuple(QStringView{}, input);
3027 else return std::make_tuple(input.sliced(0, 1), input.sliced(1));
3030 static auto enclosed = [](QStringView input, QChar open, QChar close) {
3031 if (!peek(input, open))
return std::make_tuple(QStringView{}, input);
3033 auto [opened, without_open] = skip_one(input);
3034 auto [parsed, remaining] = take_while(without_open, [close](QChar c){
return c != close; });
3036 if (remaining.empty())
return std::make_tuple(QStringView{}, input);
3038 auto [closed, without_close] = skip_one(remaining);
3040 return std::make_tuple(parsed.trimmed(), without_close);
3043 static auto one_of = [](
auto first,
auto second) {
3044 return [first, second](QStringView input) {
3045 auto [parsed, remaining] =
std::invoke(first, input);
3047 if (parsed.empty())
return std::invoke(second, input);
3048 else return std::make_tuple(parsed, remaining);
3052 static auto collect = [](QStringView input,
auto parser) {
3053 QStringList collected{};
3056 auto [parsed, remaining] =
std::invoke(parser, input);
3058 if (parsed.empty())
break;
3059 collected.append(parsed.toString());
3067 static auto spaces = [](QStringView input) {
3068 return take_while(input, [](QChar c){
return c.isSpace(); });
3071 static auto word = [](QStringView input) {
3072 return take_while(input, [](QChar c){
return !c.isSpace(); });
3075 static auto parse_argument = [](QStringView input) {
3076 auto [_, without_spaces] = spaces(input);
3079 [](QStringView input){
return enclosed(input,
'{',
'}'); },
3084 const QString cmd{DocParser::cmdName(CMD_COMPARESWITH)};
3088 QStringList segments = collect(atom->string(), parse_argument);
3090 QString categoryString;
3091 if (!segments.isEmpty())
3092 categoryString = segments.takeFirst();
3093 auto category = comparisonCategoryFromString(categoryString.toStdString());
3095 if (category == ComparisonCategory::None) {
3096 location.warning(u"Invalid argument to \\%1 command: `%2`"_s.arg(cmd, categoryString),
3097 u"Valid arguments are `strong`, `weak`, `partial`, or `equality`."_s);
3101 if (segments.isEmpty()) {
3102 location.warning(u"Missing argument to \\%1 command."_s.arg(cmd),
3103 u"Provide at least one type name, or a list of types separated by spaces."_s);
3108 segments.removeDuplicates();
3109 atom->setString(segments.join(QLatin1Char(
';')));
3113 priv->m_metacommandsUsed.insert(cmd);
3116 const auto end{priv
->extra->m_comparesWithMap.cend()};
3117 priv
->extra->m_comparesWithMap.insert(end, category, text);
#define ATOM_FORMATTING_TELETYPE
#define ATOM_FORMATTING_UNDERLINE
#define ATOM_FORMATTING_NOTRANSLATE
#define ATOM_FORMATTING_SPAN
#define ATOM_FORMATTING_SUBSCRIPT
#define ATOM_FORMATTING_BOLD
#define ATOM_FORMATTING_TRADEMARK
#define ATOM_FORMATTING_ITALIC
#define ATOM_FORMATTING_LINK
#define ATOM_FORMATTING_SUPERSCRIPT
#define ATOM_FORMATTING_INDEX
#define ATOM_FORMATTING_UICONTROL
#define ATOM_FORMATTING_PARAMETER
The Atom class is the fundamental unit for representing documents internally.
AtomType type() const
Return the type of this atom.
AtomType
\value AnnotatedList \value AutoLink \value BaseName \value BriefLeft \value BriefRight \value C \val...
void chopString()
\also string()
virtual Atom::AtomType atomType() const
The Config class contains the configuration variables for controlling how qdoc produces documentation...
static QStringList s_allowedLanguages
static QStringList s_ignoreWords
void parse(const QString &source, DocPrivate *docPrivate, const QSet< QString > &metaCommandSet, const QSet< QString > &possibleTopics)
Parse the source string to build a Text data structure in docPrivate.
static int endCmdFor(int cmd)
static void initialize(const Config &config, FileResolver &file_resolver)
void addAlso(const Text &also)
CommandMap m_metaCommandMap
static void quoteFromFile(const Location &location, Quoter "er, ResolvedFile resolved_file, CodeMarker *marker=nullptr)
Encapsulate the logic that QDoc uses to find files whose path is provided by the user and that are re...
The Location class provides a way to mark a location in a file.
static Text subText(const Atom *begin, const Atom *end=nullptr)
Text splitAtFirst(Atom::AtomType start)
Splits the current Text from start to end into a new Text object.
Text & operator=(const Text &text)
#define CONFIG_IGNOREWORDS
#define CONFIG_CODELANGUAGES
#define CONFIG_QUOTINGINFORMATION
std::pair< QString, QString > ArgPair
static void warnAboutEmptyOrPreexistingTarget(const Location &location, const QString &duplicateDefinition, const QString &cmdString, const QString &previousDefinition)
static void processComparesWithCommand(DocPrivate *priv, const Location &location)
static QString cleanLink(const QString &link)
Returns a cleaned version of the given link text.
Combined button and popup list for selecting options.
QHash_QString_Macro macroHash
QHash_QString_int cmdHash
Simple structure used by the Doc and DocParser classes.