Skip to content
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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

khushi-411
Copy link
Contributor

  • add tests

Copy link
Collaborator

@Thirumalai-Shaktivel Thirumalai-Shaktivel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, please add tests

Comment on lines +591 to +608
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 += "]";
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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 += "]";
}
r += "[";
if (x.m_start) {
visit_expr(*x.m_start);
r += s;
}
r += ":";
if (x.m_end) {
visit_expr(*x.m_end);
r += s;
}
if (x.m_step) {
r += ":";
visit_expr(*x.m_step);
r += s;
}
r += "]";

I suggested this changes because of the following cases:

s: str = "12345"
print(s[:])
print(s[3:])
print(s[3:4:])

s = r;
}

void visit_StringFormat(const ASR::StringFormat_t &x) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does LPython represents StringFormat in the ASR? (If we don't support, let's implement this later? )
I think we don't properly support f-strings yet.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I added these because there is an entry for StringFormat. Here:

| StringFormat(expr fmt, expr* args, string_format_kind kind, ttype type, expr? value)

Do you think we should keep it? Thanks

Copy link
Collaborator

Choose a reason for hiding this comment

The 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.
So, I think let's remove it for now. And handle it correctly once LPython supports f-strings.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants