// PlainScalar void Scanner::ScanPlainScalar() { std::string scalar; // set up the scanning parameters ScanScalarParams params; params.end = (InFlowContext() ? Exp::EndScalarInFlow() : Exp::EndScalar()) || (Exp::BlankOrBreak() + Exp::Comment()); params.eatEnd = false; params.indent = (InFlowContext() ? 0 : GetTopIndent() + 1); params.fold = FOLD_FLOW; params.eatLeadingWhitespace = true; params.trimTrailingSpaces = true; params.chomp = STRIP; params.onDocIndicator = BREAK; params.onTabInIndentation = THROW; // insert a potential simple key InsertPotentialSimpleKey(); Mark mark = INPUT.mark(); scalar = ScanScalar(INPUT, params); // can have a simple key only if we ended the scalar by starting a new line m_simpleKeyAllowed = params.leadingSpaces; m_canBeJSONFlow = false; // finally, check and see if we ended on an illegal character //if(Exp::IllegalCharInScalar.Matches(INPUT)) // throw ParserException(INPUT.mark(), ErrorMsg::CHAR_IN_SCALAR); Token token(Token::PLAIN_SCALAR, mark); token.value = scalar; m_tokens.push(token); }
// AnchorOrAlias void Scanner::ScanAnchorOrAlias() { bool alias; std::string name; // insert a potential simple key InsertPotentialSimpleKey(); m_simpleKeyAllowed = false; m_canBeJSONFlow = false; // eat the indicator Mark mark = INPUT.mark(); char indicator = INPUT.get(); alias = (indicator == Keys::Alias); // now eat the content while(INPUT && Exp::Anchor().Matches(INPUT)) name += INPUT.get(); // we need to have read SOMETHING! if(name.empty()) throw ParserException(INPUT.mark(), alias ? ErrorMsg::ALIAS_NOT_FOUND : ErrorMsg::ANCHOR_NOT_FOUND); // and needs to end correctly if(INPUT && !Exp::AnchorEnd().Matches(INPUT)) throw ParserException(INPUT.mark(), alias ? ErrorMsg::CHAR_IN_ALIAS : ErrorMsg::CHAR_IN_ANCHOR); // and we're done Token token(alias ? Token::ALIAS : Token::ANCHOR, mark); token.value = name; m_tokens.push(token); }
// FlowStart void Scanner::ScanFlowStart() { // flows can be simple keys InsertPotentialSimpleKey(); m_simpleKeyAllowed = true; m_canBeJSONFlow = false; // eat Mark mark = INPUT.mark(); char ch = INPUT.get(); FLOW_MARKER flowType = (ch == Keys::FlowSeqStart ? FLOW_SEQ : FLOW_MAP); m_flows.push(flowType); Token::TYPE type = (flowType == FLOW_SEQ ? Token::FLOW_SEQ_START : Token::FLOW_MAP_START); m_tokens.push(Token(type, mark)); }
// Tag void Scanner::ScanTag() { // insert a potential simple key InsertPotentialSimpleKey(); m_simpleKeyAllowed = false; m_canBeJSONFlow = false; Token token(Token::TAG, INPUT.mark()); // eat the indicator INPUT.get(); if(INPUT && INPUT.peek() == Keys::VerbatimTagStart){ std::string tag = ScanVerbatimTag(INPUT); token.value = tag; token.data = Tag::VERBATIM; } else { bool canBeHandle; token.value = ScanTagHandle(INPUT, canBeHandle); if(!canBeHandle && token.value.empty()) token.data = Tag::NON_SPECIFIC; else if(token.value.empty()) token.data = Tag::SECONDARY_HANDLE; else token.data = Tag::PRIMARY_HANDLE; // is there a suffix? if(canBeHandle && INPUT.peek() == Keys::Tag) { // eat the indicator INPUT.get(); token.params.push_back(ScanTagSuffix(INPUT)); token.data = Tag::NAMED_HANDLE; } } m_tokens.push(token); }
// QuotedScalar void Scanner::ScanQuotedScalar() { std::string scalar; // peek at single or double quote (don't eat because we need to preserve (for // the time being) the input position) char quote = INPUT.peek(); bool single = (quote == '\''); // setup the scanning parameters ScanScalarParams params; RegEx end = (single ? RegEx(quote) && !Exp::EscSingleQuote() : RegEx(quote)); params.end = &end; params.eatEnd = true; params.escape = (single ? '\'' : '\\'); params.indent = 0; params.fold = FOLD_FLOW; params.eatLeadingWhitespace = true; params.trimTrailingSpaces = false; params.chomp = CLIP; params.onDocIndicator = THROW; // insert a potential simple key InsertPotentialSimpleKey(); Mark mark = INPUT.mark(); // now eat that opening quote INPUT.get(); // and scan scalar = ScanScalar(INPUT, params); m_simpleKeyAllowed = false; m_canBeJSONFlow = true; Token token(Token::NON_PLAIN_SCALAR, mark); token.value = scalar; m_tokens.push(token); }