MCPcopy Create free account
hub / github.com/FastLED/FastLED / on_token

Method on_token

src/fl/stl/json.cpp.hpp:520–613  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

518 JsonValidator() FL_NOEXCEPT : mExpectKey(false), mExpectValue(false), mExpectColon(false), mDepth(0) {}
519
520 ParseState on_token(JsonToken token, const fl::span<const char>& value) override {
521 (void)value; // Suppress unused parameter warning
522
523 // Recursion depth check
524 if (mDepth > MAX_JSON_DEPTH) {
525 FL_ERROR("JSON parser: FATAL - recursion depth exceeded " << MAX_JSON_DEPTH);
526 return ParseState::ERROR;
527 }
528
529 switch (token) {
530 case JsonToken::LBRACE:
531 mBracketStack.push_back('{');
532 mDepth++;
533 mExpectKey = true;
534 mExpectValue = false;
535 return ParseState::KEEP_GOING;
536
537 case JsonToken::RBRACE:
538 if (mBracketStack.empty() || mBracketStack.back() != '{') {
539 return ParseState::ERROR; // Unmatched closing brace
540 }
541 mBracketStack.pop_back();
542 mDepth--;
543 mExpectKey = false;
544 return ParseState::KEEP_GOING;
545
546 case JsonToken::LBRACKET:
547 mBracketStack.push_back('[');
548 mDepth++;
549 mExpectValue = true;
550 return ParseState::KEEP_GOING;
551
552 case JsonToken::RBRACKET:
553 if (mBracketStack.empty() || mBracketStack.back() != '[') {
554 return ParseState::ERROR; // Unmatched closing bracket
555 }
556 mBracketStack.pop_back();
557 mDepth--;
558 mExpectValue = false;
559 return ParseState::KEEP_GOING;
560
561 case JsonToken::COLON:
562 if (!mExpectColon) {
563 return ParseState::ERROR; // Unexpected colon
564 }
565 mExpectColon = false;
566 mExpectValue = true;
567 return ParseState::KEEP_GOING;
568
569 case JsonToken::STRING:
570 if (!mBracketStack.empty() && mBracketStack.back() == '{' && mExpectKey) {
571 // This is an object key
572 mExpectKey = false;
573 mExpectColon = true;
574 } else if (mExpectValue || mBracketStack.empty()) {
575 // This is a value
576 mExpectValue = false;
577 } else {

Callers

nothing calls this directly

Calls 4

push_backMethod · 0.45
emptyMethod · 0.45
backMethod · 0.45
pop_backMethod · 0.45

Tested by

no test coverage detected