Defined in header <cparse/Parser.hh>
protected:
unsigned int openScopeDepth() const noexcept;
Returns the current value of the open-scope counter, incremented by enterScope() and decremented by leaveScope().
parse() reads this in Phase 5 when an ios_base::failure EOF fires: if the depth is non-zero, parse() records a Syntax error naming the unterminated scope count and returns false; if zero, EOF is treated as clean and parse() returns true.
Parameters
None.
Return value
The current open-scope depth. Zero after a clean parse where every enterScope had a paired leaveScope.
Exceptions
noexcept.
Notes
Reset to zero at the start of every outermost parse(). Nested parses do not reset — the including grammar legitimately has scopes open around the include point.
Grammars can read this method themselves — for example, to gate a diagnostic that only makes sense at "top level":
if (openScopeDepth() == 0 && encounteredKeywordThatOnlyMakesSenseInsideBlock())
recordError(ParseError::Kind::Syntax, "'break' outside of any block");
See also
- Parser::enterScope — increments the counter; contains the full "why this exists" rationale.
- Parser::leaveScope — decrements the counter.
- Parser::parse — the primary consumer of this value.

