* @brief Recursive-descent parser for a small proto3 subset (messages, scalars, nested types). */
| 318 | * @brief Recursive-descent parser for a small proto3 subset (messages, scalars, nested types). |
| 319 | */ |
| 320 | class Parser { |
| 321 | public: |
| 322 | Parser(const QString& src, QString& packageOut, QVector<DataModel::ProtoMessage>& outMessages); |
| 323 | |
| 324 | bool parseFile(ParseError& err); |
| 325 | |
| 326 | private: |
| 327 | bool accept(Tok t); |
| 328 | bool expect(Tok t, const QString& what, ParseError& err); |
| 329 | void advance(); |
| 330 | void skipToSemicolon(); |
| 331 | void skipBlock(); |
| 332 | void skipOptionList(); |
| 333 | |
| 334 | bool parseMessage(const QString& parentQualified, |
| 335 | DataModel::ProtoMessage& out, |
| 336 | ParseError& err, |
| 337 | int depth); |
| 338 | bool parseField(DataModel::ProtoMessage& msg, ParseError& err); |
| 339 | bool parseOneof(DataModel::ProtoMessage& msg, ParseError& err); |
| 340 | bool parseMap(DataModel::ProtoMessage& msg, ParseError& err); |
| 341 | bool parseEnumBody(ParseError& err); |
| 342 | bool parseFieldTag(int& tag, ParseError& err); |
| 343 | int tryParseMessageBodyKeyword(DataModel::ProtoMessage& out, ParseError& err, int depth); |
| 344 | |
| 345 | static constexpr int kMaxMessageNestingDepth = 64; |
| 346 | static constexpr int kMaxProtoFieldTag = 536870911; |
| 347 | |
| 348 | Lexer m_lexer; |
| 349 | Token m_cur; |
| 350 | QString& m_packageOut; |
| 351 | QVector<DataModel::ProtoMessage>& m_messages; |
| 352 | }; |
| 353 | |
| 354 | /** |
| 355 | * @brief Constructs the parser over a proto3 source buffer; primes the lookahead token. |