From 50d8e71b9fb77778d2f7b15af2099c63cb7b5c15 Mon Sep 17 00:00:00 2001 From: Niels Lohmann Date: Wed, 30 Sep 2026 09:45:36 +0200 Subject: [PATCH] Correct the parser comments on recursion and skip_to_state_evaluation The class documentation called the parser a recursive descent parser, but sax_parse_internal() is a loop that keeps the open containers on an explicit stack. The comment at the end of an array and of an object said the flag is set to false while the code below it sets it to true. Describe what the code does instead. Comments only; behavior, the public API and the ABI are unchanged. Part of #5712 Signed-off-by: Niels Lohmann --- include/nlohmann/detail/input/parser.hpp | 13 ++++++++----- single_include/nlohmann/json.hpp | 13 ++++++++----- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/include/nlohmann/detail/input/parser.hpp b/include/nlohmann/detail/input/parser.hpp index 5fec57a70..54eb443c7 100644 --- a/include/nlohmann/detail/input/parser.hpp +++ b/include/nlohmann/detail/input/parser.hpp @@ -54,7 +54,8 @@ using parser_callback_t = /*! @brief syntax analysis -This class implements a recursive descent parser. +This class implements an iterative parser that keeps the open containers on +an explicit stack and reports what it reads as SAX events. */ template class parser @@ -439,8 +440,9 @@ class parser // We are done with this array. Before we can parse a // new value, we need to evaluate the new state first. - // By setting skip_to_state_evaluation to false, we - // are effectively jumping to the beginning of this if. + // By setting skip_to_state_evaluation to true, the next + // iteration skips parsing a value and evaluates the + // enclosing state directly. JSON_ASSERT(!states.empty()); states.pop_back(); skip_to_state_evaluation = true; @@ -500,8 +502,9 @@ class parser // We are done with this object. Before we can parse a // new value, we need to evaluate the new state first. - // By setting skip_to_state_evaluation to false, we - // are effectively jumping to the beginning of this if. + // By setting skip_to_state_evaluation to true, the next + // iteration skips parsing a value and evaluates the + // enclosing state directly. JSON_ASSERT(!states.empty()); states.pop_back(); skip_to_state_evaluation = true; diff --git a/single_include/nlohmann/json.hpp b/single_include/nlohmann/json.hpp index 76925282a..04c06617b 100644 --- a/single_include/nlohmann/json.hpp +++ b/single_include/nlohmann/json.hpp @@ -17132,7 +17132,8 @@ using parser_callback_t = /*! @brief syntax analysis -This class implements a recursive descent parser. +This class implements an iterative parser that keeps the open containers on +an explicit stack and reports what it reads as SAX events. */ template class parser @@ -17517,8 +17518,9 @@ class parser // We are done with this array. Before we can parse a // new value, we need to evaluate the new state first. - // By setting skip_to_state_evaluation to false, we - // are effectively jumping to the beginning of this if. + // By setting skip_to_state_evaluation to true, the next + // iteration skips parsing a value and evaluates the + // enclosing state directly. JSON_ASSERT(!states.empty()); states.pop_back(); skip_to_state_evaluation = true; @@ -17578,8 +17580,9 @@ class parser // We are done with this object. Before we can parse a // new value, we need to evaluate the new state first. - // By setting skip_to_state_evaluation to false, we - // are effectively jumping to the beginning of this if. + // By setting skip_to_state_evaluation to true, the next + // iteration skips parsing a value and evaluates the + // enclosing state directly. JSON_ASSERT(!states.empty()); states.pop_back(); skip_to_state_evaluation = true;