Skip to content

Commit f40f524

Browse files
committed
Fix merge conflicts
1 parent 670b12f commit f40f524

File tree

105 files changed

+1064
-185
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

105 files changed

+1064
-185
lines changed

integration_tests/test_str_attributes.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,17 @@ def is_ascii():
276276
s = "123 45 6"
277277
assert s.isascii() == True
278278

279+
280+
def isspace():
281+
assert "\n".isspace() == True
282+
assert " ".isspace() == True
283+
assert "\r".isspace() == True
284+
285+
s:str = " "
286+
assert s.isspace() == True
287+
s: str = "a"
288+
assert s.isspace() == False
289+
279290
def check():
280291
capitalize()
281292
lower()
@@ -290,5 +301,6 @@ def check():
290301
is_upper()
291302
is_decimal()
292303
is_ascii()
304+
isspace()
293305

294306
check()

src/lpython/semantics/python_ast_to_asr.cpp

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6651,7 +6651,7 @@ class BodyVisitor : public CommonVisitor<BodyVisitor> {
66516651
/*
66526652
String Validation Methods i.e all "is" based functions are handled here
66536653
*/
6654-
std::vector<std::string> validation_methods{"lower", "upper", "decimal", "ascii"}; // Database of validation methods supported
6654+
std::vector<std::string> validation_methods{"lower", "upper", "decimal", "ascii","space"}; // Database of validation methods supported
66556655
std::string method_name = attr_name.substr(2);
66566656

66576657
if(std::find(validation_methods.begin(),validation_methods.end(), method_name) == validation_methods.end()) {
@@ -6919,7 +6919,7 @@ class BodyVisitor : public CommonVisitor<BodyVisitor> {
69196919
* islower() method is limited to English Alphabets currently
69206920
* TODO: We can support other characters from Unicode Library
69216921
*/
6922-
std::vector<std::string> validation_methods{"lower", "upper", "decimal", "ascii"}; // Database of validation methods supported
6922+
std::vector<std::string> validation_methods{"lower", "upper", "decimal", "ascii","space"}; // Database of validation methods supported
69236923
std::string method_name = attr_name.substr(2);
69246924
if(std::find(validation_methods.begin(),validation_methods.end(), method_name) == validation_methods.end()) {
69256925
throw SemanticError("String method not implemented: " + attr_name, loc);
@@ -6999,6 +6999,22 @@ class BodyVisitor : public CommonVisitor<BodyVisitor> {
69996999
tmp = ASR::make_LogicalConstant_t(al, loc, is_ascii,
70007000
ASRUtils::TYPE(ASR::make_Logical_t(al, loc, 4)));
70017001
return;
7002+
} else if(attr_name == "isspace") {
7003+
/*
7004+
* Specification:
7005+
Return true if all characters in the input string are considered whitespace characters,
7006+
as defined by the std::isspace function. Return false otherwise.
7007+
*/
7008+
bool is_space = true;
7009+
for (char i : s_var) {
7010+
if (!std::isspace(static_cast<unsigned char>(i))) {
7011+
is_space = false;
7012+
break;
7013+
}
7014+
}
7015+
tmp = ASR::make_LogicalConstant_t(al, loc, is_space,
7016+
ASRUtils::TYPE(ASR::make_Logical_t(al, loc, 4)));
7017+
return;
70027018
} else {
70037019
throw SemanticError("'str' object has no attribute '" + attr_name + "'", loc);
70047020
}

src/lpython/semantics/python_comptime_eval.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,8 @@ struct PythonIntrinsicProcedures {
9292
{"_lpython_str_islower", {m_builtin, &not_implemented}},
9393
{"_lpython_str_isupper", {m_builtin, &not_implemented}},
9494
{"_lpython_str_isdecimal", {m_builtin, &not_implemented}},
95-
{"_lpython_str_isascii", {m_builtin, &not_implemented}}
95+
{"_lpython_str_isascii", {m_builtin, &not_implemented}},
96+
{"_lpython_str_isspace", {m_builtin, &not_implemented}}
9697
};
9798
}
9899

src/runtime/lpython_builtin.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -858,6 +858,15 @@ def _lpython_str_isascii(s: str) -> bool:
858858
return False
859859
return True
860860

861+
@overload
862+
def _lpython_str_isspace(s:str) -> bool:
863+
ch:str
864+
for ch in s:
865+
if ch != ' ' and ch != '\t' and ch != '\n' and ch != '\r' and ch != '\f' and ch != '\v':
866+
return False
867+
return True
868+
869+
861870
def list(s: str) -> list[str]:
862871
l: list[str] = []
863872
i: i32

tests/reference/asr-array_01_decl-39cf894.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,17 @@
55
"infile_hash": "3dff59bab7475d254ce0470065c11e797e52a5b2a3d7546acc0e6705",
66
"outfile": null,
77
"outfile_hash": null,
8+
<<<<<<< HEAD
9+
"stdout": null,
10+
"stdout_hash": null,
11+
"stderr": "asr-array_01_decl-39cf894.stderr",
12+
"stderr_hash": "5155e10cd4958bdda66178e2ed1b6faed6f415ff1cf3ff78e45f9cbb",
13+
"returncode": 2
14+
=======
815
"stdout": "asr-array_01_decl-39cf894.stdout",
916
"stdout_hash": "24b1d1f4774489a87a82c51c4f4a797ca363f7efdb011e42936fc6b9",
1017
"stderr": null,
1118
"stderr_hash": null,
1219
"returncode": 0
20+
>>>>>>> main
1321
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
warning: The module 'numpy' located in $DIR/src/bin/../runtime/lpython_intrinsic_numpy.py cannot be loaded
2+
--> tests/../integration_tests/array_01_decl.py:2:1
3+
|
4+
2 | from numpy import empty, int16, int32, int64, float32, float64, complex64, complex128
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ imported here
6+
7+
warning: The module 'lpython_builtin' located in $DIR/src/bin/../runtime/lpython_builtin.py cannot be loaded
8+
--> $DIR/src/bin/../runtime/lpython_intrinsic_numpy.py:364:12
9+
|
10+
364 | return x1 % x2
11+
| ^^^^^^^ imported here
12+
13+
semantic error: The symbol '_lpython_floordiv' not found in the module 'lpython_builtin'
14+
--> $DIR/src/bin/../runtime/lpython_builtin.py:209:15
15+
|
16+
209 | if (n_ - (n_ // 2)*2) == 0:
17+
| ^^^^^^^
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
warning: The module 'numpy' located in $DIR/src/bin/../runtime/lpython_intrinsic_numpy.py cannot be loaded
2+
--> tests/../integration_tests/array_02_decl.py:2:1
3+
|
4+
2 | from numpy import empty, int32, int64, float32, float64, complex64, complex128
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ imported here
6+
7+
warning: The module 'lpython_builtin' located in $DIR/src/bin/../runtime/lpython_builtin.py cannot be loaded
8+
--> $DIR/src/bin/../runtime/lpython_intrinsic_numpy.py:364:12
9+
|
10+
364 | return x1 % x2
11+
| ^^^^^^^ imported here
12+
13+
semantic error: The symbol '_lpython_floordiv' not found in the module 'lpython_builtin'
14+
--> $DIR/src/bin/../runtime/lpython_builtin.py:209:15
15+
|
16+
209 | if (n_ - (n_ // 2)*2) == 0:
17+
| ^^^^^^^

tests/reference/asr-arrays_01-a617b64.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@
88
"stdout": null,
99
"stdout_hash": null,
1010
"stderr": "asr-arrays_01-a617b64.stderr",
11-
"stderr_hash": "b8317c7306f747ceefa8557c06f2a0b4a8a4bd7ae805bb494fca6ef2",
11+
"stderr_hash": "ddb2640e06012a8ab9efe1bc1dbe130321fb96721ce3fd749813c988",
1212
"returncode": 2
1313
}
Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,17 @@
1-
semantic error: Type mismatch in procedure call; the types must be compatible
2-
--> tests/errors/arrays_01.py:15:9
3-
|
4-
15 | [i8(214), i8(157), i8(3), i8(146)])
5-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type mismatch (passed argument type is list[i8] but required type is i8[4])
6-
|
7-
9 | a : i8[4] = empty(4, dtype=int8)
8-
| ^^^^^ type mismatch (passed argument type is list[i8] but required type is i8[4])
1+
warning: The module 'numpy' located in $DIR/src/bin/../runtime/lpython_intrinsic_numpy.py cannot be loaded
2+
--> tests/errors/arrays_01.py:2:1
3+
|
4+
2 | from numpy import empty, int8
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ imported here
6+
7+
warning: The module 'lpython_builtin' located in $DIR/src/bin/../runtime/lpython_builtin.py cannot be loaded
8+
--> $DIR/src/bin/../runtime/lpython_intrinsic_numpy.py:364:12
9+
|
10+
364 | return x1 % x2
11+
| ^^^^^^^ imported here
12+
13+
semantic error: The symbol '_lpython_floordiv' not found in the module 'lpython_builtin'
14+
--> $DIR/src/bin/../runtime/lpython_builtin.py:209:15
15+
|
16+
209 | if (n_ - (n_ // 2)*2) == 0:
17+
| ^^^^^^^

tests/reference/asr-arrays_02-da94458.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@
88
"stdout": null,
99
"stdout_hash": null,
1010
"stderr": "asr-arrays_02-da94458.stderr",
11-
"stderr_hash": "dc0e5be7cd6de7395421aedf1ce11977206f3e35bb7cba271aed8992",
11+
"stderr_hash": "b7b907310495016dfb487fccb13739865174dda44541ade08931bae9",
1212
"returncode": 2
1313
}

0 commit comments

Comments
 (0)