Skip to content

Commit 581f272

Browse files
Add str.strip() to asr -> asr
1 parent b3eb3fe commit 581f272

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

src/lpython/semantics/python_ast_to_asr.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4296,6 +4296,20 @@ class BodyVisitor : public CommonVisitor<BodyVisitor> {
42964296
args.push_back(al, arg);
42974297
tmp = make_call_helper(al, fn_div, current_scope, args, "_lpython_str_lstrip", x.base.base.loc);
42984298
return;
4299+
} else if (std::string(at->m_attr) == std::string("strip")) {
4300+
if(args.size() != 0) {
4301+
throw SemanticError("str.srtrip() takes no arguments",
4302+
x.base.base.loc);
4303+
}
4304+
ASR::symbol_t *fn_div = resolve_intrinsic_function(x.base.base.loc, "_lpython_str_strip");
4305+
Vec<ASR::call_arg_t> args;
4306+
args.reserve(al, 1);
4307+
ASR::call_arg_t arg;
4308+
arg.loc = x.base.base.loc;
4309+
arg.m_value = se;
4310+
args.push_back(al, arg);
4311+
tmp = make_call_helper(al, fn_div, current_scope, args, "_lpython_str_strip", x.base.base.loc);
4312+
return;
42994313
}
43004314
}
43014315
handle_attribute(se, at->m_attr, x.base.base.loc, eles);

src/runtime/lpython_builtin.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -626,7 +626,7 @@ def _lpython_str_capitalize(x: str) -> str:
626626
return x
627627

628628
@overload
629-
def _lpython_str_lower(x: str) ->str:
629+
def _lpython_str_lower(x: str) -> str:
630630
res: str
631631
res = ""
632632
i:str
@@ -652,3 +652,10 @@ def _lpython_str_lstrip(x: str) -> str:
652652
while ind < len(x) and x[ind] == ' ':
653653
ind += 1
654654
return x[ind :len(x)]
655+
656+
@overload
657+
def _lpython_str_strip(x: str) -> str:
658+
res :str
659+
res = _lpython_str_lstrip(x)
660+
res = _lpython_str_rstrip(res)
661+
return res

0 commit comments

Comments
 (0)