| 926 | } |
| 927 | |
| 928 | static void parseRepositoryItem( SyntaxDefinition& def, const std::string& name, |
| 929 | const nlohmann::json& item ) { |
| 930 | std::vector<SyntaxPattern> ptrns; |
| 931 | if ( item.contains( "match" ) || item.contains( "begin" ) ) { |
| 932 | ptrns.emplace_back( parsePattern( item ) ); |
| 933 | } else if ( item.contains( "patterns" ) && item["patterns"].is_array() ) { |
| 934 | const auto& patterns = item["patterns"]; |
| 935 | for ( const auto& pattern : patterns ) { |
| 936 | if ( pattern.size() == 1 && pattern.contains( "comment" ) ) |
| 937 | continue; |
| 938 | if ( !( pattern.contains( "match" ) || pattern.contains( "begin" ) ) && |
| 939 | pattern.contains( "patterns" ) && pattern["patterns"].is_array() ) { |
| 940 | // Maybe do this recursive later, not a very common pattern |
| 941 | const auto& subPatterns = pattern["patterns"]; |
| 942 | for ( const auto& subPattern : subPatterns ) { |
| 943 | if ( subPattern.size() == 1 && subPattern.contains( "comment" ) ) |
| 944 | continue; |
| 945 | ptrns.emplace_back( parsePattern( subPattern ) ); |
| 946 | } |
| 947 | } else |
| 948 | ptrns.emplace_back( parsePattern( pattern ) ); |
| 949 | } |
| 950 | } else if ( item.is_array() ) { |
| 951 | for ( const auto& pattern : item ) |
| 952 | ptrns.emplace_back( parsePattern( pattern ) ); |
| 953 | } |
| 954 | |
| 955 | if ( item.contains( "repository" ) && item["repository"].is_object() ) { |
| 956 | for ( const auto& [iname, iitem] : item["repository"].items() ) { |
| 957 | parseRepositoryItem( def, iname, iitem ); |
| 958 | } |
| 959 | } |
| 960 | |
| 961 | auto rname( name ); |
| 962 | def.addRepository( std::move( rname ), std::move( ptrns ) ); |
| 963 | }; |
| 964 | |
| 965 | static SyntaxDefinition loadLanguage( const nlohmann::json& json ) { |
| 966 | SyntaxDefinition def; |
no test coverage detected