-
Notifications
You must be signed in to change notification settings - Fork 165
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[asr->python] add string visitors #2588
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -573,6 +573,58 @@ class ASRToLpythonVisitor : public ASR::BaseVisitor<ASRToLpythonVisitor> | |||
s += "len(" + s + ")"; | ||||
} | ||||
|
||||
void visit_StringItem(const ASR::StringItem_t &x) { | ||||
std::string r = ""; | ||||
visit_expr(*x.m_arg); | ||||
r += s; | ||||
r += "["; | ||||
visit_expr(*x.m_idx); | ||||
r += s; | ||||
r += "]"; | ||||
s = r; | ||||
} | ||||
|
||||
void visit_StringSection(const ASR::StringSection_t &x) { | ||||
std::string r = ""; | ||||
visit_expr(*x.m_arg); | ||||
r += s; | ||||
if (x.m_start) { | ||||
r += "["; | ||||
visit_expr(*x.m_start); | ||||
r += s; | ||||
} | ||||
if (x.m_end) { | ||||
r += ":"; | ||||
visit_expr(*x.m_end); | ||||
r += s; | ||||
} | ||||
if (x.m_step) { | ||||
r += ":"; | ||||
visit_expr(*x.m_step); | ||||
r += s; | ||||
r += "]"; | ||||
} else { | ||||
r += "]"; | ||||
} | ||||
s = r; | ||||
} | ||||
|
||||
void visit_StringFormat(const ASR::StringFormat_t &x) { | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does LPython represents There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, I added these because there is an entry for Line 305 in 7aa7084
Do you think we should keep it? Thanks There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, we have an entry in ASR.asdl, but LPython doesn't utilise it yet. |
||||
std::string r = ""; | ||||
visit_expr(*x.m_fmt); | ||||
r += s; | ||||
r += ".format("; | ||||
for (size_t i = 0; i < x.n_args; i++) { | ||||
visit_expr(*x.m_args[i]); | ||||
r += s; | ||||
if (i < x.n_args - 1) { | ||||
r += ", "; | ||||
} | ||||
} | ||||
r += ")"; | ||||
s = r; | ||||
} | ||||
|
||||
void visit_IfExp(const ASR::IfExp_t &x) { | ||||
std::string r; | ||||
visit_expr(*x.m_body); | ||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggested this changes because of the following cases:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Leave comment for proper understanding of code.