@@ -933,17 +933,18 @@ auto lex_line(
933
933
// G any Cpp1-and-Cpp2 keyword
934
934
// G one of: 'import' 'module' 'export' 'is' 'as'
935
935
// G
936
- auto do_is_keyword = [&](std::regex const & r) {
937
- std::cmatch m;
938
- if (std::regex_search (&line[i], m, r)) {
939
- assert (m.position (0 ) == 0 );
936
+ auto do_is_keyword = [&](std::vector<std::string_view> const & r) {
937
+ auto m = std::find_if (r.begin (), r.end (), [&](std::string_view s) {
938
+ return std::string_view (line).substr (unsafe_narrow<std::size_t >(i)).starts_with (s);
939
+ });
940
+ if (m != r.end ()) {
940
941
// If we matched and what's next is EOL or a non-identifier char, we matched!
941
942
if (
942
- i+m[ 0 ]. length ( ) == std::ssize (line) // EOL
943
- || !is_identifier_continue (line[i+m[ 0 ]. length ( )]) // non-identifier char
943
+ i+std::ssize (*m ) == std::ssize (line) // EOL
944
+ || !is_identifier_continue (line[unsafe_narrow<std:: size_t >(i)+ std::size (*m )]) // non-identifier char
944
945
)
945
946
{
946
- return static_cast <int >(m[ 0 ]. length ( ));
947
+ return static_cast <int >(std::ssize (*m ));
947
948
}
948
949
}
949
950
return 0 ;
@@ -955,46 +956,46 @@ auto lex_line(
955
956
// reserve all the ones Cpp1 has both for compatibility and to not give up a keyword
956
957
// Some keywords like "delete" and "union" are not in this list because we reject them elsewhere
957
958
// Cpp2 also adds a couple, notably "is" and "as"
958
- const auto keys = std::regex (
959
- " ^ alignas|^ alignof|^ asm|^as|^ auto| "
960
- " ^ bool|^ break| "
961
- " ^ case|^ catch|^ char16_t|^ char32_t|^ char8_t|^ char|^ co_await|^ co_return| "
962
- " ^ co_yield|^ concept|^ const_cast|^ consteval|^ constexpr|^ constinit|^ const|^ continue| "
963
- " ^ decltype|^ default|^ double|^do|^ dynamic_cast| "
964
- " ^ else|^ enum|^ explicit|^ export|^ extern| "
965
- " ^ float|^ for|^ friend| "
966
- " ^ goto| "
967
- " ^if|^ import|^ inline|^ int|^is| "
968
- " ^ long| "
969
- " ^ module|^ mutable| "
970
- " ^ namespace|^ noexcept| "
971
- " ^ operator| "
972
- " ^ private|^ protected|^ public| "
973
- " ^ register|^ reinterpret_cast|^ requires|^ return| "
974
- " ^ short|^ signed|^ sizeof|^ static_assert|^ static_cast|^ static|^ switch| "
975
- " ^ template|^ this|^ thread_local|^ throws|^ throw|^ try|^ typedef|^ typeid|^ typename| "
976
- " ^ unsigned|^ using| "
977
- " ^ virtual|^ void|^ volatile| "
978
- " ^ wchar_t|^ while"
979
- ) ;
959
+ static const auto keys = std::vector<std::string_view>{
960
+ " alignas" , " alignof" , " asm" , " as " , " auto" ,
961
+ " bool" , " break" ,
962
+ " case" , " catch" , " char16_t" , " char32_t" , " char8_t" , " char" , " co_await" , " co_return" ,
963
+ " co_yield" , " concept" , " const_cast" , " consteval" , " constexpr" , " constinit" , " const" , " continue" ,
964
+ " decltype" , " default" , " double" , " do " , " dynamic_cast" ,
965
+ " else" , " enum" , " explicit" , " export" , " extern" ,
966
+ " float" , " for" , " friend" ,
967
+ " goto" ,
968
+ " if " , " import" , " inline" , " int" , " is " ,
969
+ " long" ,
970
+ " module" , " mutable" ,
971
+ " namespace" , " noexcept" ,
972
+ " operator" ,
973
+ " private" , " protected" , " public" ,
974
+ " register" , " reinterpret_cast" , " requires" , " return" ,
975
+ " short" , " signed" , " sizeof" , " static_assert" , " static_cast" , " static" , " switch" ,
976
+ " template" , " this" , " thread_local" , " throws" , " throw" , " try" , " typedef" , " typeid" , " typename" ,
977
+ " unsigned" , " using" ,
978
+ " virtual" , " void" , " volatile" ,
979
+ " wchar_t" , " while"
980
+ } ;
980
981
981
982
return do_is_keyword (keys);
982
983
};
983
984
984
985
auto peek_is_cpp2_fundamental_type_keyword = [&]
985
986
{
986
- const auto keys = std::regex (
987
- " ^i8|^ i16|^ i32|^ i64|^ longdouble|^ longlong|^u8|^ u16|^ u32|^ u64|^ ulong|^ ulonglong|^ ushort"
988
- ) ;
987
+ static const auto keys = std::vector<std::string_view>{
988
+ " i8 " , " i16" , " i32" , " i64" , " longdouble" , " longlong" , " u8 " , " u16" , " u32" , " u64" , " ulong" , " ulonglong" , " ushort"
989
+ } ;
989
990
990
991
return do_is_keyword (keys);
991
992
};
992
993
993
994
auto peek_is_cpp1_multi_token_fundamental_keyword = [&]
994
995
{
995
- const auto multi_keys = std::regex (
996
- " ^ char16_t|^ char32_t|^ char8_t|^ char|^ double|^ float|^ int|^ long|^ short|^ signed|^ unsigned"
997
- ) ;
996
+ static const auto multi_keys = std::vector<std::string_view>{
997
+ " char16_t" , " char32_t" , " char8_t" , " char" , " double" , " float" , " int" , " long" , " short" , " signed" , " unsigned"
998
+ } ;
998
999
return do_is_keyword (multi_keys);
999
1000
};
1000
1001
0 commit comments