MCPcopy Create free account
hub / github.com/codereader/DarkRadiant / parseBlock

Method parseBlock

libs/parser/DefBlockSyntaxParser.h:877–934  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

875
876private:
877 std::vector<DefSyntaxNode::Ptr> parseBlock()
878 {
879 std::vector<DefSyntaxNode::Ptr> headerNodes;
880
881 int nameIndex = -1;
882 int typeIndex = -1;
883
884 // Check the next token
885 while (!_tokIter.isExhausted())
886 {
887 auto token = *_tokIter++;
888
889 switch (token.type)
890 {
891 case DefSyntaxToken::Type::BlockComment:
892 case DefSyntaxToken::Type::EolComment:
893 headerNodes.push_back(std::make_shared<DefCommentSyntax>(token));
894 break;
895 case DefSyntaxToken::Type::Whitespace:
896 headerNodes.push_back(std::make_shared<DefWhitespaceSyntax>(token));
897 break;
898 case DefSyntaxToken::Type::BracedBlock:
899 // The braced block token concludes this decl block
900 return { std::make_shared<DefBlockSyntax>(token, std::move(headerNodes), nameIndex, typeIndex) };
901 case DefSyntaxToken::Type::Token:
902 if (nameIndex == -1)
903 {
904 // No name yet, assume this is the name
905 nameIndex = static_cast<int>(headerNodes.size());
906 headerNodes.emplace_back(std::make_shared<DefNameSyntax>(token));
907 continue;
908 }
909
910 // We already got a first string token, check if this is the second
911 if (typeIndex == -1)
912 {
913 // The first one is the type, change the node type
914 typeIndex = nameIndex;
915 auto oldName = std::static_pointer_cast<DefNameSyntax>(headerNodes.at(typeIndex));
916 headerNodes.at(typeIndex) = std::make_shared<DefTypeSyntax>(oldName->getToken());
917
918 // Append the name to the end of the vector
919 nameIndex = static_cast<int>(headerNodes.size());
920 headerNodes.emplace_back(std::make_shared<DefNameSyntax>(token));
921 continue;
922 }
923
924 rWarning() << "Invalid number of decl block headers, already got a name and type: "
925 << headerNodes.at(typeIndex)->getString() << " "
926 << headerNodes.at(nameIndex)->getString() << std::endl;
927 break;
928 }
929 }
930
931 // We didn't find a well-formed block syntax node here, but we'll
932 // at least return all the tokens we found on the way
933 return headerNodes;
934 }

Callers

nothing calls this directly

Calls 6

moveFunction · 0.85
rWarningFunction · 0.85
isExhaustedMethod · 0.80
push_backMethod · 0.45
sizeMethod · 0.45
getStringMethod · 0.45

Tested by

no test coverage detected