Skip to content

Commit

Permalink
Add support for parsing strings with multiple prefixes.
Browse files Browse the repository at this point in the history
Co-authored-by: Thirumalai Shaktivel <Thirumalai-Shaktivel@users.noreply.github.com>
  • Loading branch information
akshanshbhatt and Thirumalai-Shaktivel committed Jul 29, 2022
1 parent 4e1a222 commit 8abef30
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/lpython/parser/semantics.h
Original file line number Diff line number Diff line change
Expand Up @@ -683,9 +683,14 @@ static inline ast_t *PREFIX_STRING(Allocator &al, Location &l, char *prefix, cha
Vec<expr_t *> exprs;
exprs.reserve(al, 4);
ast_t *tmp = nullptr;
// Assuming prefix has only one character.
prefix[0] = tolower(prefix[0]);
if (strcmp(prefix, "f") == 0) {
if (strcmp(prefix, "U") == 0 ) {
return make_ConstantStr_t(al, l, s, nullptr);
}
for (size_t i = 0; i < strlen(prefix); i++) {
prefix[i] = tolower(prefix[i]);
}
if (strcmp(prefix, "f") == 0 || strcmp(prefix, "fr") == 0
|| strcmp(prefix, "rf") == 0) {
std::string str = std::string(s);
std::string s1 = "\"";
std::string id;
Expand Down Expand Up @@ -729,7 +734,8 @@ static inline ast_t *PREFIX_STRING(Allocator &al, Location &l, char *prefix, cha
}
}
tmp = make_JoinedStr_t(al, l, exprs.p, exprs.size());
} else if (strcmp(prefix, "b") == 0) {
} else if (strcmp(prefix, "b") == 0 || strcmp(prefix, "br") == 0
|| strcmp(prefix, "rb") == 0) {
std::string str = std::string(s);
size_t start_pos = 0;
while((start_pos = str.find("\n", start_pos)) != std::string::npos) {
Expand Down

0 comments on commit 8abef30

Please sign in to comment.