@@ -65,6 +65,7 @@ struct PythonIntrinsicProcedures {
65
65
{" _lpython_str_capitalize" , {m_builtin, &eval__lpython_str_capitalize}},
66
66
{" _lpython_str_lower" , {m_builtin, &eval__lpython_str_lower}},
67
67
{" _lpython_str_rstrip" , {m_builtin, &eval__lpython_str_rstrip}},
68
+ {" _lpython_str_lstrip" , {m_builtin, &eval__lpython_str_lstrip}},
68
69
};
69
70
}
70
71
@@ -706,6 +707,22 @@ struct PythonIntrinsicProcedures {
706
707
return ASR::down_cast<ASR::expr_t >(ASR::make_StringConstant_t (al, loc, s2c (al, res), res_type));
707
708
}
708
709
710
+ static ASR::expr_t *eval__lpython_str_lstrip (Allocator &al, const Location &loc, Vec<ASR::expr_t *> &args) {
711
+ LFORTRAN_ASSERT (ASRUtils::all_args_evaluated (args));
712
+ if (args.size () != 0 ) {
713
+ throw SemanticError (" str.lstrip() takes no arguments" , loc);
714
+ }
715
+ ASR::expr_t *arg = args[0 ];
716
+ ASR::ttype_t *arg_type = ASRUtils::expr_type (arg);
717
+ std::string res = ASR::down_cast<ASR::StringConstant_t>(arg)->m_s ;
718
+ int ind = 0 ;
719
+ while (ind < res.size () && res[ind++] == ' ' );
720
+ res = std::string (res.begin () + ind, res.end ());
721
+ ASR::ttype_t *type = ASRUtils::TYPE (ASR::make_Character_t (al, loc,
722
+ 1 , 1 , nullptr , nullptr , 0 ));
723
+ ASR::ttype_t *res_type = ASRUtils::TYPE (ASR::make_StringConstant_t (al, loc, s2c (al, " " ), type));
724
+ return ASR::down_cast<ASR::expr_t >(ASR::make_StringConstant_t (al, loc, s2c (al, res), res_type));
725
+ }
709
726
710
727
}; // ComptimeEval
711
728
0 commit comments