| 963 | }; |
| 964 | |
| 965 | static SyntaxDefinition loadLanguage( const nlohmann::json& json ) { |
| 966 | SyntaxDefinition def; |
| 967 | |
| 968 | try { |
| 969 | def.setLanguageName( json.value( "name", "" ) ); |
| 970 | |
| 971 | if ( json.contains( "patterns" ) && json["patterns"].is_array() ) { |
| 972 | const auto& patterns = json["patterns"]; |
| 973 | for ( const auto& pattern : patterns ) |
| 974 | def.addPattern( parsePattern( pattern ) ); |
| 975 | } |
| 976 | |
| 977 | if ( json.contains( "repository" ) && json["repository"].is_object() ) { |
| 978 | const auto& repository = json["repository"]; |
| 979 | for ( const auto& [name, item] : repository.items() ) |
| 980 | parseRepositoryItem( def, name, item ); |
| 981 | } |
| 982 | |
| 983 | if ( ( json.contains( "$schema" ) && json["$schema"].is_string() && |
| 984 | String::contains( json.value( "$schema", "" ), "tmlanguage.json" ) ) || |
| 985 | json.contains( "scopeName" ) /* assume tmlanguage */ ) { |
| 986 | return loadTextMateLanguage( json, def ); |
| 987 | } |
| 988 | |
| 989 | if ( json.contains( "lsp_name" ) && json["lsp_name"].is_string() ) |
| 990 | def.setLSPName( json["lsp_name"].get<std::string>() ); |
| 991 | |
| 992 | if ( json.contains( "files" ) ) { |
| 993 | if ( json["files"].is_array() ) { |
| 994 | const auto& files = json["files"]; |
| 995 | for ( const auto& file : files ) { |
| 996 | def.addFileType( file ); |
| 997 | } |
| 998 | } else if ( json["files"].is_string() ) { |
| 999 | def.addFileType( json["files"].get<std::string>() ); |
| 1000 | } |
| 1001 | } |
| 1002 | |
| 1003 | def.setComment( json.value( "comment", "" ) ); |
| 1004 | |
| 1005 | if ( json.contains( "symbols" ) ) { |
| 1006 | if ( json["symbols"].is_array() ) { |
| 1007 | const auto& symbols = json["symbols"]; |
| 1008 | for ( const auto& symbol : symbols ) { |
| 1009 | for ( auto& el : symbol.items() ) { |
| 1010 | def.addSymbol( el.key(), el.value() ); |
| 1011 | } |
| 1012 | } |
| 1013 | } else if ( json["symbols"].is_object() ) { |
| 1014 | for ( const auto& [key, value] : json["symbols"].items() ) { |
| 1015 | def.addSymbol( key, value ); |
| 1016 | } |
| 1017 | } |
| 1018 | } |
| 1019 | |
| 1020 | if ( json.contains( "headers" ) && json["headers"].is_array() ) { |
| 1021 | const auto& headers = json["headers"]; |
| 1022 | std::vector<std::string> hds; |
no test coverage detected