| 401 | } |
| 402 | |
| 403 | static void patternToCPP( std::string& buf, const SyntaxPattern& pattern, |
| 404 | const SyntaxDefinition& def ) { |
| 405 | bool allowReduce = ( ( pattern.patterns.size() == 1 && pattern.typesNames.size() <= 1 && |
| 406 | pattern.endTypesNames.empty() ) || |
| 407 | ( pattern.patterns.size() <= 3 && pattern.typesNames.size() <= 1 && |
| 408 | pattern.endTypesNames.empty() && |
| 409 | pattern.matchType == SyntaxPatternMatchType::LuaPattern ) ) && |
| 410 | !pattern.isApplyEndPatternLast(); |
| 411 | bool setType = allowReduce && pattern.matchType != SyntaxPatternMatchType::LuaPattern; |
| 412 | bool addPatternType = pattern.matchType != SyntaxPatternMatchType::LuaPattern || |
| 413 | ( pattern.patterns.size() == 2 && pattern.patterns[0] == "include" ); |
| 414 | bool allowSkip = allowReduce; |
| 415 | buf += "{ " + join( pattern.patterns ) + ", " + |
| 416 | join( pattern.typesNames, true, allowReduce, setType ) + |
| 417 | join( pattern.endTypesNames, true, false, setType, allowSkip, true ) + |
| 418 | str( pattern.syntax, ", ", "", false ); |
| 419 | if ( addPatternType && pattern.syntax.empty() ) { |
| 420 | if ( pattern.matchType == SyntaxPatternMatchType::RegEx ) |
| 421 | buf += ", \"\", SyntaxPatternMatchType::RegEx"; |
| 422 | else if ( pattern.matchType == SyntaxPatternMatchType::Parser ) |
| 423 | buf += ", \"\", SyntaxPatternMatchType::Parser"; |
| 424 | else if ( pattern.matchType == SyntaxPatternMatchType::LuaPattern ) |
| 425 | buf += ", \"\", SyntaxPatternMatchType::LuaPattern"; |
| 426 | } else if ( addPatternType ) { |
| 427 | if ( pattern.matchType == SyntaxPatternMatchType::RegEx ) |
| 428 | buf += ", SyntaxPatternMatchType::RegEx"; |
| 429 | else if ( pattern.matchType == SyntaxPatternMatchType::Parser ) |
| 430 | buf += ", SyntaxPatternMatchType::Parser"; |
| 431 | else if ( pattern.matchType == SyntaxPatternMatchType::LuaPattern ) |
| 432 | buf += ", SyntaxPatternMatchType::LuaPattern"; |
| 433 | } |
| 434 | if ( pattern.hasContentScope() ) { |
| 435 | const auto& patterns = def.getRepository( pattern.contentScopeRepoHash ); |
| 436 | buf += ", {\n"; |
| 437 | for ( const auto& ptrn : patterns.patterns ) |
| 438 | patternToCPP( buf, ptrn, def ); |
| 439 | buf += "\n}"; |
| 440 | } |
| 441 | |
| 442 | if ( pattern.isApplyEndPatternLast() ) { |
| 443 | if ( !pattern.hasContentScope() ) |
| 444 | buf = ", {}"; |
| 445 | buf += ", SyntaxPattern::IsApplyEndPatternLast"; |
| 446 | } |
| 447 | |
| 448 | buf += " },\n"; |
| 449 | } |
| 450 | |
| 451 | std::pair<std::string, std::string> SyntaxDefinitionManager::toCPP( const SyntaxDefinition& def ) { |
| 452 | const auto patternsToCPP = [&]( std::string& buf, const std::vector<SyntaxPattern>& patterns ) { |