@@ -1001,135 +1001,6 @@ class cppfront
1001
1001
}
1002
1002
1003
1003
1004
- // -----------------------------------------------------------------------
1005
- //
1006
- // A StringLiteral could include captures
1007
- //
1008
- auto expand_string_literal (token const & n) -> std::string
1009
- {
1010
- assert (n.type () == lexeme::StringLiteral);
1011
-
1012
- auto text = std::string_view (n);
1013
- auto length = n.length ();
1014
- assert (std::ssize (text) == length);
1015
-
1016
- assert (length >= 2 );
1017
- assert (text.back () == ' "' );
1018
-
1019
- auto pos = 0 ;
1020
- auto ret = std::string{}; // the return string we're going to build
1021
-
1022
- // Skip prefix to first non-" character
1023
- while (pos < length && text[pos] != ' "' ) {
1024
- ++pos;
1025
- }
1026
- assert (pos < length && text[pos] == ' "' );
1027
- ++pos;
1028
- auto current_start = pos; // the current offset before which the string has been into ret
1029
- auto first = true ;
1030
-
1031
- auto add_plus = [&]{
1032
- if (!first) {
1033
- ret += " + " ;
1034
- }
1035
- first = false ;
1036
- };
1037
-
1038
- // Now we're on the first character of the string itself
1039
- for ( ; pos < length && (text[pos] != ' "' || text[pos-1 ] == ' \\ ' ); ++pos )
1040
- {
1041
- // Find the next )$
1042
- if (text[pos] == ' $' && text[pos-1 ] == ' )' )
1043
- {
1044
- // Scan back to find the matching (
1045
- auto paren_depth = 1 ;
1046
- auto open = pos - 2 ;
1047
-
1048
- // "next" in the string is the "last" one encountered in the backwards scan
1049
- auto last_nonwhitespace = ' \0 ' ;
1050
-
1051
- for ( ; text[open] != ' "' || (open > current_start && text[open-1 ] != ' \\ ' ); --open)
1052
- {
1053
- if (text[open] == ' )' ) {
1054
- ++paren_depth;
1055
- }
1056
- else if (text[open] == ' (' ) {
1057
- --paren_depth;
1058
- if (paren_depth == 0 ) {
1059
- break ;
1060
- }
1061
- }
1062
- else if (
1063
- (text[open] == ' +' && text[open - 1 ] == ' +' ) ||
1064
- (text[open] == ' -' && text[open - 1 ] == ' -' )
1065
- )
1066
- {
1067
- errors.emplace_back (
1068
- source_position ( n.position ().lineno , n.position ().colno + pos ),
1069
- " a string interpolation expression may not contain ++ or --"
1070
- );
1071
- return {};
1072
- }
1073
- else if (
1074
- (text[open] == ' *' || text[open] == ' &' || text[open] == ' ~' ) &&
1075
- !isspace (text[open - 1 ]) &&
1076
- !isalnum (last_nonwhitespace) && last_nonwhitespace != ' ('
1077
- )
1078
- {
1079
- errors.emplace_back (
1080
- source_position ( n.position ().lineno , n.position ().colno + pos ),
1081
- " a string interpolation expression may not contain unary & * or ~"
1082
- );
1083
- return {};
1084
- }
1085
-
1086
- if (!std::isspace (text[open])) {
1087
- last_nonwhitespace = text[open];
1088
- }
1089
- }
1090
- if (text[open] == ' "' )
1091
- {
1092
- errors.emplace_back (
1093
- source_position ( n.position ().lineno , n.position ().colno + pos ),
1094
- " no matching ( for string interpolation ending in )$"
1095
- );
1096
- return {};
1097
- }
1098
- assert (text[open] == ' (' );
1099
-
1100
- // 'open' is now at the matching (
1101
-
1102
- // Put the next non-empty non-interpolated chunk straight into ret
1103
- if (open != current_start) {
1104
- add_plus ();
1105
- ret += ' "' ;
1106
- ret += text.substr (current_start, open - current_start);
1107
- ret += ' "' ;
1108
- }
1109
-
1110
- // Then put interpolated chunk into ret
1111
- add_plus ();
1112
- ret += " cpp2::to_string" ;
1113
- ret += text.substr (open, pos - open);
1114
-
1115
- current_start = pos+1 ;
1116
- }
1117
- }
1118
-
1119
- // Now we should be on the the final " closing the string
1120
- assert (pos == length-1 && text[pos] == ' "' );
1121
-
1122
- // Put the final non-interpolated chunk straight into ret
1123
- if (first || current_start < std::ssize (text)-1 ) {
1124
- add_plus ();
1125
- ret += ' "' ;
1126
- ret += text.substr (current_start);
1127
- }
1128
-
1129
- return ret;
1130
- }
1131
-
1132
-
1133
1004
// -----------------------------------------------------------------------
1134
1005
//
1135
1006
auto emit (token const & n, bool is_qualified = false , source_position pos = {}) -> void
@@ -1147,9 +1018,9 @@ class cppfront
1147
1018
if (n == " new" ) {
1148
1019
printer.print_cpp2 (" cpp2_new" , pos);
1149
1020
}
1150
- else if (n.type () == lexeme::StringLiteral) {
1151
- printer.print_cpp2 ( expand_string_literal (n), pos );
1152
- }
1021
+ // else if (n.type() == lexeme::StringLiteral) {
1022
+ // printer.print_cpp2( expand_string_literal(n, errors ), pos );
1023
+ // }
1153
1024
else {
1154
1025
printer.print_cpp2 (n, pos);
1155
1026
}
0 commit comments