| 73 | } |
| 74 | |
| 75 | static void updatePatternState( SyntaxDefinition& def, SyntaxPattern& ptrn ) { |
| 76 | if ( ptrn.checkIsRangedMatch() ) |
| 77 | ptrn.flags |= SyntaxPattern::IsRangedMatch; |
| 78 | |
| 79 | if ( ptrn.checkIsIncludePattern() ) { |
| 80 | ptrn.flags |= SyntaxPattern::IsInclude; |
| 81 | |
| 82 | if ( ptrn.checkIsRepositoryInclude() ) { |
| 83 | ptrn.flags |= SyntaxPattern::IsRepositoryInclude; |
| 84 | ptrn.repositoryIdx = def.getRepositoryIndex( ptrn.getRepositoryName() ); |
| 85 | } else if ( ptrn.checkIsRootSelfInclude() ) { |
| 86 | ptrn.flags |= SyntaxPattern::IsRootSelfInclude; |
| 87 | } else if ( ptrn.checkIsSourceInclude() && ptrn.patterns[1].size() > 7 ) { |
| 88 | ptrn.flags |= SyntaxPattern::IsSourceInclude; |
| 89 | |
| 90 | if ( def.getRepositoryName( String::hash( ptrn.patterns[1] ) ).empty() ) { |
| 91 | const auto& lang = |
| 92 | SyntaxDefinitionManager::instance()->getByLanguageNameInsensitive( |
| 93 | std::string_view{ ptrn.patterns[1] }.substr( 7 /* "source." */ ) ); |
| 94 | |
| 95 | auto syntaxRepoName = ptrn.patterns[1]; |
| 96 | auto patterns = lang.getPatterns(); |
| 97 | for ( auto& iptrn : patterns ) { |
| 98 | if ( iptrn.isRepositoryInclude() ) { |
| 99 | iptrn.flags = SyntaxPattern::IsInclude | SyntaxPattern::IsSourceInclude; |
| 100 | iptrn.patterns[1] = String::format( "%s.%s", syntaxRepoName, |
| 101 | iptrn.patterns[1].substr( 1 ) ); |
| 102 | } |
| 103 | } |
| 104 | def.addRepository( std::move( syntaxRepoName ), { std::move( patterns ) } ); |
| 105 | const auto& repos = lang.getRepositories(); |
| 106 | std::vector<std::pair<std::string, std::vector<SyntaxPattern>>> nrepos; |
| 107 | nrepos.reserve( repos.size() ); |
| 108 | for ( const auto& repo : repos ) { |
| 109 | const auto& repoName = lang.getRepositoryName( repo.first ); |
| 110 | auto newRepoName = String::format( "%s.%s", ptrn.patterns[1], repoName ); |
| 111 | auto npatterns = repo.second.patterns; |
| 112 | for ( auto& iptrn : npatterns ) { |
| 113 | if ( iptrn.isRepositoryInclude() ) { |
| 114 | iptrn.flags = SyntaxPattern::IsInclude | SyntaxPattern::IsSourceInclude; |
| 115 | iptrn.patterns[1] = String::format( "%s.%s", ptrn.patterns[1], |
| 116 | iptrn.patterns[1].substr( 1 ) ); |
| 117 | } |
| 118 | } |
| 119 | nrepos.emplace_back( std::move( newRepoName ), npatterns ); |
| 120 | } |
| 121 | } |
| 122 | } else { |
| 123 | Log::warning( "updatePatternState unknown include directive: %s", ptrn.patterns[1] ); |
| 124 | ptrn.flags &= ~SyntaxPattern::IsInclude; |
| 125 | } |
| 126 | } else { |
| 127 | ptrn.flags |= SyntaxPattern::IsPure; |
| 128 | } |
| 129 | |
| 130 | updatePatternRefs( def, ptrn ); |
| 131 | } |
| 132 |
no test coverage detected