MCPcopy Create free account
hub / github.com/Serial-Studio/Serial-Studio / parseFile

Method parseFile

app/src/DataModel/Importers/ProtoImporter.cpp:708–767  ·  view source on GitHub ↗

* @brief Parses the whole file: syntax, package, top-level message/enum/option entries. */

Source from the content-addressed store, hash-verified

706 * @brief Parses the whole file: syntax, package, top-level message/enum/option entries.
707 */
708bool Parser::parseFile(ParseError& err)
709{
710 while (m_cur.type != Tok::Eof) {
711 if (m_cur.type == Tok::Semi) {
712 advance();
713 continue;
714 }
715
716 if (m_cur.type != Tok::Ident) {
717 err = {m_cur.line, QObject::tr("Unexpected token '%1' at file scope").arg(m_cur.text)};
718 return false;
719 }
720
721 const QString kw = m_cur.text;
722 if (kw == QLatin1String("syntax") || kw == QLatin1String("option")
723 || kw == QLatin1String("import")) {
724 skipToSemicolon();
725 continue;
726 }
727 if (kw == QLatin1String("package")) {
728 advance();
729 QString pkg;
730 while (m_cur.type == Tok::Ident || m_cur.type == Tok::Dot) {
731 pkg += m_cur.text;
732 advance();
733 }
734 m_packageOut = pkg;
735 skipToSemicolon();
736 continue;
737 }
738 if (kw == QLatin1String("enum")) {
739 advance();
740 if (!parseEnumBody(err))
741 return false;
742
743 continue;
744 }
745 if (kw == QLatin1String("service")) {
746 advance();
747 if (m_cur.type == Tok::Ident)
748 advance();
749
750 skipBlock();
751 continue;
752 }
753 if (kw == QLatin1String("message")) {
754 advance();
755 DataModel::ProtoMessage msg;
756 if (!parseMessage(m_packageOut, msg, err, 1))
757 return false;
758
759 m_messages.append(msg);
760 continue;
761 }
762
763 err = {m_cur.line, QObject::tr("Unsupported top-level keyword '%1'").arg(kw)};
764 return false;
765 }

Callers 1

showPreviewMethod · 0.80

Calls 2

parseMessageFunction · 0.85
appendMethod · 0.45

Tested by

no test coverage detected