MCPcopy Create free account
hub / github.com/SpartanJ/eepp / parsePattern

Function parsePattern

src/eepp/ui/doc/syntaxdefinitionmanager.cpp:712–903  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

710}
711
712static SyntaxPattern parsePattern( const nlohmann::json& pattern ) {
713 std::vector<std::string> type;
714 std::vector<std::string> endType;
715 std::vector<std::string> ptrns;
716 std::vector<SyntaxPattern> subPatterns;
717 auto ctype = SyntaxPatternMatchType::LuaPattern;
718 std::string contentTypeName;
719 SyntaxStyleType contentType{ SyntaxStyleEmpty() };
720 std::string syntax;
721 bool applyEndPatternLast{ false };
722
723 const auto fillTypes = []( const nlohmann::json& captures, std::vector<std::string>& type,
724 const nlohmann::json& parent ) {
725 Uint64 totalCaptures = 0;
726 for ( const auto& [capNumStr, _] : captures.items() ) {
727 Uint64 num;
728 if ( String::fromString( num, capNumStr ) )
729 totalCaptures = eemax( totalCaptures, num + 1 );
730 }
731
732 for ( Uint64 i = 0; i < totalCaptures; i++ ) {
733 auto capNumStr = String::toString( i );
734 if ( captures.contains( capNumStr ) && captures[capNumStr].contains( "name" ) ) {
735 auto ctype =
736 TextMateScopeMapper::scopeToType( captures[capNumStr].value( "name", "" ) );
737 if ( i < type.size() )
738 type[i] = ctype;
739 else
740 type.emplace_back( ctype );
741 } else if ( parent.contains( "name" ) ) {
742 auto ctype = TextMateScopeMapper::scopeToType( parent.value( "name", "" ) );
743 if ( i < type.size() )
744 type[i] = ctype;
745 else
746 type.emplace_back( ctype );
747 } else {
748 type.emplace_back( "normal" );
749 }
750 }
751 };
752
753 // Assume TextMate pattern
754 if ( pattern.contains( "name" ) || pattern.contains( "contentName" ) ||
755 pattern.contains( "begin" ) || pattern.contains( "match" ) ) {
756 ctype = SyntaxPatternMatchType::RegEx;
757
758 if ( type.empty() && pattern.contains( "name" ) ) {
759 type.emplace_back( TextMateScopeMapper::scopeToType( pattern.value( "name", "" ) ) );
760 }
761
762 if ( pattern.contains( "contentName" ) ) {
763 contentTypeName = pattern.value( "contentName", "" );
764 contentType = toSyntaxStyleType( TextMateScopeMapper::scopeToType( contentTypeName ) );
765 }
766
767 if ( pattern.contains( "beginCaptures" ) )
768 fillTypes( pattern["beginCaptures"], type, pattern );
769

Callers 2

parseRepositoryItemFunction · 0.85
loadLanguageFunction · 0.85

Calls 11

SyntaxStyleEmptyFunction · 0.85
fromStringFunction · 0.85
eemaxFunction · 0.85
toSyntaxStyleTypeFunction · 0.85
push_backMethod · 0.80
reserveMethod · 0.80
toStringFunction · 0.50
containsMethod · 0.45
valueMethod · 0.45
sizeMethod · 0.45
emptyMethod · 0.45

Tested by

no test coverage detected