csp-lang 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
csp_lang-0.1.0/LICENSE ADDED
@@ -0,0 +1,190 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ Copyright 2026 Muhammad Abubakar Siddique Ansari
179
+
180
+ Licensed under the Apache License, Version 2.0 (the "License");
181
+ you may not use this file except in compliance with the License.
182
+ You may obtain a copy of the License at
183
+
184
+ http://www.apache.org/licenses/LICENSE-2.0
185
+
186
+ Unless required by applicable law or agreed to in writing, software
187
+ distributed under the License is distributed on an "AS IS" BASIS,
188
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
189
+ See the License for the specific language governing permissions and
190
+ limitations under the License.
@@ -0,0 +1,275 @@
1
+ Metadata-Version: 2.4
2
+ Name: csp_lang
3
+ Version: 0.1.0
4
+ Summary: Custom Syntax for Python Language -- CSPLang
5
+ Author-email: Muhammad Abubakar Siddique Ansari <ansaricodes@gmail.com>
6
+ Project-URL: Homepage, https://github.com/Ansari-Codes/custom-syntax-for-python.git
7
+ Requires-Python: >=3.5
8
+ Description-Content-Type: text/markdown
9
+ License-File: LICENSE
10
+ Dynamic: license-file
11
+
12
+ # CSPLang – Custom Syntax for Python Language
13
+
14
+ **CSPLang** is a compact custom syntax designed for Python. It’s a toy language that works by transforming each line of CSP code into Python code, then executing it. The focus is on **writing less code but doing more work**.
15
+
16
+ Think about it this way:
17
+ > What if you run real python, but write it in a bit different way?
18
+
19
+ Basically, CSP doesn’t block you from using Python’s full ecosystem; it just gives you a syntactic sugar wrapper so your loops, functions, conditionals, and variables can be written in a shorter or more “DSL-like” style.
20
+
21
+ ---
22
+
23
+ ## Developer
24
+
25
+ I am **Muhammad Abubakar Siddique Ansari**, a passionate developer in **Data Science and AI**. I love creating utilities, exploring new programming ideas, and building simple yet powerful tools.
26
+
27
+ I am currently (2026) a **1st-year ICS student at KIPS College**, Punjab – Pakistan.
28
+ Portfolio: [https://ansari-codes.github.io/portfolio](https://ansari-codes.github.io/portfolio)
29
+
30
+ ---
31
+
32
+ ## Installation
33
+
34
+ 1. Clone the repo:
35
+ ```powershell
36
+ git clone https://github.com/Ansari-Codes/custom-syntax-for-python.git
37
+ cd custom-syntax-for-python
38
+ pip install -e .
39
+ ```
40
+
41
+ 2. Via pip:
42
+ ```powershell
43
+ pip install csp_lang
44
+ ```
45
+
46
+ 3. Pip installation using git:
47
+ ```powershell
48
+ pip install git+https://github.com/Ansari-Codes/custom-syntax-for-python.git
49
+ ```
50
+
51
+ ---
52
+
53
+ ## Key Principles
54
+
55
+ 1. **Compact Syntax:** Write less code for the same Python functionality.
56
+ 2. **Readable & Straightforward:** Easy to understand even if you are new to Python.
57
+ 3. **Direct Python Integration:** Most Python functions, utilities, and modules work without changes.
58
+
59
+ ---
60
+
61
+ ## Syntax Overview
62
+
63
+ ### 1. Comments
64
+
65
+ Single-line and multi-line comments are supported:
66
+
67
+ ```python
68
+ # Single-line comment
69
+
70
+ %
71
+ This is a
72
+ multi-line comment
73
+ %
74
+ ```
75
+
76
+ ### 2. Built-in Python Functions
77
+
78
+ Python functions and utilities work as-is.
79
+
80
+ ```python
81
+ print(10) # Works exactly like Python
82
+ len([1,2,3]) # Python’s len function
83
+ ```
84
+
85
+ ### 3. Variables
86
+
87
+ Use `<-` as the assignment operator:
88
+
89
+ ```r
90
+ name <- "Muhammad"
91
+ age <- 15
92
+ x <- 5 + 3
93
+ ```
94
+
95
+ ### 4. Conditionals
96
+
97
+ CSP replaces `if`, `elif`, and `else` with a simple, readable syntax:
98
+
99
+ ```python
100
+ x <- 5
101
+
102
+ %
103
+ IMPORTANT: Don;t use comments after colon of the conditions
104
+ EXAMPLE:
105
+ 1. Correct code:
106
+ x>0:
107
+ 2. Buggy code:
108
+ x>0: #comment
109
+ %
110
+
111
+ # if x > 0
112
+ x > 0:
113
+ print("x is positive")
114
+ # elif x == 5
115
+ : x == 5:
116
+ print("x is exactly 5")
117
+ # else
118
+ :
119
+ print("other")
120
+ ```
121
+
122
+ > The `:` indicates the start of a condition block, and `:` alone is treated as `else`.
123
+
124
+ ### 5. Loops
125
+
126
+ #### While Loop
127
+
128
+ Use `>>` for while loops:
129
+
130
+ ```python
131
+
132
+ %
133
+ IMPORTANT: Don;t use comments after colon of the condition
134
+ EXAMPLE:
135
+ 1. Correct code:
136
+ x > 0:
137
+ 2. Buggy code:
138
+ x > 0: #comment
139
+ %
140
+
141
+ x <- 3
142
+ >> x > 0:
143
+ print(x)
144
+ x <- x - 1
145
+ ```
146
+
147
+ #### For Loop
148
+
149
+ Use `=>` with `:` replacing `in`:
150
+
151
+ ```python
152
+
153
+ %
154
+ IMPORTANT: Don;t use comments after colon of the i:iterable:
155
+ EXAMPLE:
156
+ 1. Correct code:
157
+ x:range(5):
158
+
159
+ 2. Buggy code:
160
+ x:range(5): #comment
161
+ %
162
+
163
+ => i:[1,2,3]:
164
+ print(i)
165
+
166
+ => j:range(5):
167
+ print(j)
168
+ ```
169
+
170
+ > `i` is the loop variable, and `iterable` can be any Python iterable.
171
+
172
+ ### 6. Functions
173
+
174
+ Functions are defined using `$` and `[]` instead of `def` and `()`:
175
+
176
+ ```python
177
+
178
+ %
179
+ IMPORTANT: Don;t use comments after colon of the functio definition
180
+ EXAMPLE:
181
+ 1. Correct code:
182
+ $add[a, b]:
183
+
184
+ 2. Buggy code:
185
+ $add[a, b]: #comment
186
+ %
187
+
188
+ $add[a, b]:
189
+ -> a + b # return statement
190
+
191
+ $greet[name="User"]:
192
+ print(f"Hello {name}")
193
+ print(add(1, 1))
194
+ ```
195
+
196
+ Call functions normally:
197
+
198
+ ```python
199
+ print(add(2, 3))
200
+ greet()
201
+ greet("Muhammad")
202
+ ```
203
+
204
+ ### 7. Imports
205
+
206
+ Import modules as in Python:
207
+
208
+ ```python
209
+ import math as mt
210
+ from math import sqrt
211
+ ```
212
+
213
+ If you have tqdm installed, for example:
214
+ ```python
215
+ from tqdm import tqdm
216
+ from time import sleep
217
+ => i:tqdm(range(30)):
218
+ sleep(0.1)
219
+ ```
220
+
221
+ > Currently, importing other `.csp` files is not supported.
222
+
223
+ ---
224
+
225
+ ## File Format
226
+
227
+ CSP files use the `.csp` extension.
228
+
229
+ ---
230
+
231
+ ## CLI Usage
232
+
233
+ You can run CSP programs or transpile them to Python:
234
+
235
+ ```bash
236
+ # Run directly
237
+ csp run program.csp
238
+
239
+ # Transpile to Python file
240
+ csp transpile program.csp -o program.py
241
+ python program.py
242
+
243
+ # run tests
244
+ csp test
245
+ ```
246
+
247
+ ---
248
+
249
+ ## Example Program
250
+
251
+ ```python
252
+ x <- 3
253
+ $fun[a]:
254
+ print(f"Start {a}")
255
+ >> a > 0:
256
+ => i:[1,2]:
257
+ print("Loop", i)
258
+ a <- a - 1
259
+ -> "done"
260
+
261
+ print(fun(x))
262
+ ```
263
+
264
+ Output:
265
+
266
+ ```
267
+ Start 3
268
+ Loop 1
269
+ Loop 2
270
+ Loop 1
271
+ Loop 2
272
+ Loop 1
273
+ Loop 2
274
+ done
275
+ ```
@@ -0,0 +1,264 @@
1
+ # CSPLang – Custom Syntax for Python Language
2
+
3
+ **CSPLang** is a compact custom syntax designed for Python. It’s a toy language that works by transforming each line of CSP code into Python code, then executing it. The focus is on **writing less code but doing more work**.
4
+
5
+ Think about it this way:
6
+ > What if you run real python, but write it in a bit different way?
7
+
8
+ Basically, CSP doesn’t block you from using Python’s full ecosystem; it just gives you a syntactic sugar wrapper so your loops, functions, conditionals, and variables can be written in a shorter or more “DSL-like” style.
9
+
10
+ ---
11
+
12
+ ## Developer
13
+
14
+ I am **Muhammad Abubakar Siddique Ansari**, a passionate developer in **Data Science and AI**. I love creating utilities, exploring new programming ideas, and building simple yet powerful tools.
15
+
16
+ I am currently (2026) a **1st-year ICS student at KIPS College**, Punjab – Pakistan.
17
+ Portfolio: [https://ansari-codes.github.io/portfolio](https://ansari-codes.github.io/portfolio)
18
+
19
+ ---
20
+
21
+ ## Installation
22
+
23
+ 1. Clone the repo:
24
+ ```powershell
25
+ git clone https://github.com/Ansari-Codes/custom-syntax-for-python.git
26
+ cd custom-syntax-for-python
27
+ pip install -e .
28
+ ```
29
+
30
+ 2. Via pip:
31
+ ```powershell
32
+ pip install csp_lang
33
+ ```
34
+
35
+ 3. Pip installation using git:
36
+ ```powershell
37
+ pip install git+https://github.com/Ansari-Codes/custom-syntax-for-python.git
38
+ ```
39
+
40
+ ---
41
+
42
+ ## Key Principles
43
+
44
+ 1. **Compact Syntax:** Write less code for the same Python functionality.
45
+ 2. **Readable & Straightforward:** Easy to understand even if you are new to Python.
46
+ 3. **Direct Python Integration:** Most Python functions, utilities, and modules work without changes.
47
+
48
+ ---
49
+
50
+ ## Syntax Overview
51
+
52
+ ### 1. Comments
53
+
54
+ Single-line and multi-line comments are supported:
55
+
56
+ ```python
57
+ # Single-line comment
58
+
59
+ %
60
+ This is a
61
+ multi-line comment
62
+ %
63
+ ```
64
+
65
+ ### 2. Built-in Python Functions
66
+
67
+ Python functions and utilities work as-is.
68
+
69
+ ```python
70
+ print(10) # Works exactly like Python
71
+ len([1,2,3]) # Python’s len function
72
+ ```
73
+
74
+ ### 3. Variables
75
+
76
+ Use `<-` as the assignment operator:
77
+
78
+ ```r
79
+ name <- "Muhammad"
80
+ age <- 15
81
+ x <- 5 + 3
82
+ ```
83
+
84
+ ### 4. Conditionals
85
+
86
+ CSP replaces `if`, `elif`, and `else` with a simple, readable syntax:
87
+
88
+ ```python
89
+ x <- 5
90
+
91
+ %
92
+ IMPORTANT: Don;t use comments after colon of the conditions
93
+ EXAMPLE:
94
+ 1. Correct code:
95
+ x>0:
96
+ 2. Buggy code:
97
+ x>0: #comment
98
+ %
99
+
100
+ # if x > 0
101
+ x > 0:
102
+ print("x is positive")
103
+ # elif x == 5
104
+ : x == 5:
105
+ print("x is exactly 5")
106
+ # else
107
+ :
108
+ print("other")
109
+ ```
110
+
111
+ > The `:` indicates the start of a condition block, and `:` alone is treated as `else`.
112
+
113
+ ### 5. Loops
114
+
115
+ #### While Loop
116
+
117
+ Use `>>` for while loops:
118
+
119
+ ```python
120
+
121
+ %
122
+ IMPORTANT: Don;t use comments after colon of the condition
123
+ EXAMPLE:
124
+ 1. Correct code:
125
+ x > 0:
126
+ 2. Buggy code:
127
+ x > 0: #comment
128
+ %
129
+
130
+ x <- 3
131
+ >> x > 0:
132
+ print(x)
133
+ x <- x - 1
134
+ ```
135
+
136
+ #### For Loop
137
+
138
+ Use `=>` with `:` replacing `in`:
139
+
140
+ ```python
141
+
142
+ %
143
+ IMPORTANT: Don;t use comments after colon of the i:iterable:
144
+ EXAMPLE:
145
+ 1. Correct code:
146
+ x:range(5):
147
+
148
+ 2. Buggy code:
149
+ x:range(5): #comment
150
+ %
151
+
152
+ => i:[1,2,3]:
153
+ print(i)
154
+
155
+ => j:range(5):
156
+ print(j)
157
+ ```
158
+
159
+ > `i` is the loop variable, and `iterable` can be any Python iterable.
160
+
161
+ ### 6. Functions
162
+
163
+ Functions are defined using `$` and `[]` instead of `def` and `()`:
164
+
165
+ ```python
166
+
167
+ %
168
+ IMPORTANT: Don;t use comments after colon of the functio definition
169
+ EXAMPLE:
170
+ 1. Correct code:
171
+ $add[a, b]:
172
+
173
+ 2. Buggy code:
174
+ $add[a, b]: #comment
175
+ %
176
+
177
+ $add[a, b]:
178
+ -> a + b # return statement
179
+
180
+ $greet[name="User"]:
181
+ print(f"Hello {name}")
182
+ print(add(1, 1))
183
+ ```
184
+
185
+ Call functions normally:
186
+
187
+ ```python
188
+ print(add(2, 3))
189
+ greet()
190
+ greet("Muhammad")
191
+ ```
192
+
193
+ ### 7. Imports
194
+
195
+ Import modules as in Python:
196
+
197
+ ```python
198
+ import math as mt
199
+ from math import sqrt
200
+ ```
201
+
202
+ If you have tqdm installed, for example:
203
+ ```python
204
+ from tqdm import tqdm
205
+ from time import sleep
206
+ => i:tqdm(range(30)):
207
+ sleep(0.1)
208
+ ```
209
+
210
+ > Currently, importing other `.csp` files is not supported.
211
+
212
+ ---
213
+
214
+ ## File Format
215
+
216
+ CSP files use the `.csp` extension.
217
+
218
+ ---
219
+
220
+ ## CLI Usage
221
+
222
+ You can run CSP programs or transpile them to Python:
223
+
224
+ ```bash
225
+ # Run directly
226
+ csp run program.csp
227
+
228
+ # Transpile to Python file
229
+ csp transpile program.csp -o program.py
230
+ python program.py
231
+
232
+ # run tests
233
+ csp test
234
+ ```
235
+
236
+ ---
237
+
238
+ ## Example Program
239
+
240
+ ```python
241
+ x <- 3
242
+ $fun[a]:
243
+ print(f"Start {a}")
244
+ >> a > 0:
245
+ => i:[1,2]:
246
+ print("Loop", i)
247
+ a <- a - 1
248
+ -> "done"
249
+
250
+ print(fun(x))
251
+ ```
252
+
253
+ Output:
254
+
255
+ ```
256
+ Start 3
257
+ Loop 1
258
+ Loop 2
259
+ Loop 1
260
+ Loop 2
261
+ Loop 1
262
+ Loop 2
263
+ done
264
+ ```
@@ -0,0 +1,78 @@
1
+ import re
2
+
3
+ def transpile(code: str) -> str:
4
+ # 1. UNIVERSAL STRING EXTRACTION (Handling \`)
5
+ strings = []
6
+
7
+ def save_string(match):
8
+ # match.group(1) contains the content inside the backticks
9
+ content = match.group(1)
10
+
11
+ # Unescape the backticks for Python: \` -> `
12
+ content = content.replace(r'\`', '`')
13
+
14
+ # Escape quotes to ensure they work inside Python's triple quotes
15
+ content = content.replace('"', '\\"').replace("'", "\\'")
16
+
17
+ placeholder = f"__STR_VAL_{len(strings)}__"
18
+ strings.append(f'"""{content}"""')
19
+ return placeholder
20
+
21
+ # REGEX EXPLANATION:
22
+ # ` : Match opening backtick
23
+ # ( : Start capture group
24
+ # (?: : Non-capturing group for choices
25
+ # \\. : Match any escaped character (e.g., \`)
26
+ # | : OR
27
+ # [^`] : Match any character that is NOT a backtick
28
+ # )* : Repeat zero or more times
29
+ # ) : End capture group
30
+ # ` : Match closing backtick
31
+ backtick_pattern = r'`((?:\\.|[^`])*)`'
32
+
33
+ code_hidden = re.sub(backtick_pattern, save_string, code, flags=re.DOTALL)
34
+
35
+ py_lines = []
36
+ skip_multiline = False
37
+
38
+ for line in code_hidden.splitlines():
39
+ raw_line = line.rstrip()
40
+ line_stripped = raw_line.strip()
41
+
42
+ # Handle % comments
43
+ if line_stripped.startswith("%"):
44
+ if line_stripped.endswith("%") and len(line_stripped) > 1:
45
+ continue
46
+ else:
47
+ skip_multiline = not skip_multiline
48
+ continue
49
+ if skip_multiline or line_stripped.startswith(("//", "#")):
50
+ continue
51
+
52
+ indent = re.match(r'\s*', raw_line).group()
53
+ line = line_stripped
54
+
55
+ # --- Standard Logic Transpilation ---
56
+ if line.startswith(":") and line.endswith(":") and line != ":":
57
+ line = "elif " + line[1:-1].strip() + ":"
58
+ elif line == ":":
59
+ line = "else:"
60
+
61
+ line = re.sub(r'^\$(\w+)\[(.*)\]:$', r'def \1(\2):', line)
62
+ line = re.sub(r'^>>\s*(.+):$', r'while \1:', line)
63
+ line = re.sub(r'^=>\s*(\w+)\s*:\s*(.+):$', r'for \1 in \2:', line)
64
+ line = re.sub(r'(\w+)\s*<-\s*(.+)', r'\1 = \2', line)
65
+ line = re.sub(r'^->\s*(.+)', r'return \1', line)
66
+
67
+ if line.endswith(":") and not line.startswith(("if ", "elif ", "else:", "while ", "for ", "def ")):
68
+ line = "if " + line[:-1].strip() + ":"
69
+
70
+ py_lines.append(indent + line)
71
+
72
+ final_python = "\n".join(py_lines)
73
+
74
+ # 2. RESTORE STRINGS
75
+ for i, s in enumerate(strings):
76
+ final_python = final_python.replace(f"__STR_VAL_{i}__", s)
77
+
78
+ return final_python
@@ -0,0 +1,108 @@
1
+ #!/usr/bin/env python3
2
+ import argparse
3
+ from pathlib import Path
4
+ from .Transpiler import transpile
5
+ from .Transpiler import transpile
6
+
7
+ def test():
8
+ sources = [
9
+ "x <- 5\ny <- x + 2\nz <- y * 3\nprint(x, y, z)",
10
+ "_var <- 10\nanotherVar <- _var + 5\nprint(anotherVar)",
11
+ "x <- 2\nx > 0:\n print('x>0')\n: x == 2:\n print('x==2')\n:\n print('other')",
12
+ "y <- 5\ny < 5:\n print('y<5')\n:\n print('y>=5')",
13
+ "x <- 3\n>> x > 0:\n print(x)\n x <- x - 1",
14
+ "y <- 2\n>> y > 0:\n z <- y * 2\n print(z)\n y <- y - 1",
15
+ "=> i:[]:\n print(i)",
16
+ "=> j:[1,2,3]:\n print(j)",
17
+ "=> k:range(3):\n print(k)",
18
+ "$add[a, b]:\n -> a + b\nprint(add(2,3))",
19
+ "$default_args[a=1, b=2]:\n -> a * b\nprint(default_args())\nprint(default_args(3,4))",
20
+ "x <- 2\n>> x > 0:\n y <- x\n >> y > 0:\n print(x, y)\n y <- y - 1\n x <- x - 1",
21
+ "a <- 3\na > 0:\n print('outer')\n: a == 3:\n print('middle')\n >> i in [1,2]:\n print(i)\n:\n print('other')",
22
+ "% This is a\nmultiline comment\n%\nx <- 10\n// single line comment\ny <- 5\n# another comment\nprint(x + y)",
23
+ "$compute[a, b]:\n result <- a + b\n -> result\nprint(compute(2,5))",
24
+ "_x <- 1\n_y_2 <- 3\nz3 <- _x + _y_2\nprint(z3)",
25
+ "% Complex test %\nx <- 5\n>> x > 0:\n y <- x\n y > 2:\n print('y>2')\n :\n print('y<=2')\n x <- x - 1\n$func[a=1, b=2]:\n -> a*b\nprint(func())\nprint(func(3,4))",
26
+ "x <- 3\n>> x > 0:\n y <- x\n >> y > 0:\n y % 2 == 0:\n print(x, y, 'even')\n else:\n print(x, y, 'odd')\n y <- y - 1\n x <- x - 1",
27
+ "$sum_squares[a=1, b=3]:\n total <- 0\n => i:range(a, b+1):\n total <- total + i*i\n -> total\nprint(sum_squares())\nprint(sum_squares(2,4))",
28
+ "n <- 5\nn > 0:\n n == 5:\n print('five')\n : n == 4:\n print('four')\n :\n print('other')\nelse:\n print('zero or negative')",
29
+ "$factorial[n]:\n result <- 1\n >> n > 1:\n result <- result * n\n n <- n - 1\n -> result\nprint(factorial(5))",
30
+ "% This is a\nmultiline comment\n%\nx <- 2\n% single-line comment %\ny <- 3\nprint(x + y)",
31
+ "$matrix_sum[matrix]:\n total <- 0\n => row:matrix:\n => val:row:\n total <- total + val\n -> total\nprint(matrix_sum([[1,2],[3,4]]))",
32
+ "nums <- [1,2,3,4,5]\n=> n:nums:\n n % 2 == 0:\n print(n, 'even')\n :\n print(n, 'odd')",
33
+ "$square[x]:\n -> x*x\n$square_sum[a, b]:\n -> square(a) + square(b)\nprint(square_sum(2,3))",
34
+ "x <- 5\n>> x > 0:\n x % 2 == 0:\n pass\n :\n print(x)\n x <- x - 1",
35
+ "a <- 2\n>> a > 0:\n b <- 2\n >> b > 0:\n a == b:\n print('match')\n :\n print('no match')\n b <- b - 1\n a <- a - 1",
36
+ "print(f`This \nis {type(3)} \nmutliline\nWhile Loop:\nx <- 0\n>> x < 10:\n print(x)\n x <- x + 1`)",
37
+ "x <- `outer \`inner\` value`\nprint(x)", # type: ignore
38
+ "% This is mutliline without close\nprint(10)"
39
+ ]
40
+
41
+ passed = 0
42
+ failed = []
43
+ print("===== Starting Test =====")
44
+ for i, source in enumerate(sources):
45
+ print(f"-------- Test #{i + 1} -------- ")
46
+ print(source)
47
+ python_code = transpile(source)
48
+ print("--- Generated Python:\n")
49
+ print(python_code)
50
+ print("\n--- Output:\n")
51
+ try:
52
+ g = {}
53
+ exec(python_code, g)
54
+ passed += 1
55
+ print("Successful!")
56
+ except Exception as e:
57
+ print("Error!", str(e))
58
+ failed.append(i + 1)
59
+ print(f"Total Passed (out of {len(sources)}):", passed)
60
+ print("Failed Tests:", failed)
61
+
62
+ def cmd_run(file_path: str):
63
+ """Transpile CSP file and execute as Python"""
64
+ path = Path(file_path)
65
+ if not path.is_file():
66
+ print(f"Error: file '{file_path}' not found.")
67
+ return
68
+ with open(path, 'r', encoding='utf-8') as f:
69
+ code = f.read()
70
+ py_code = transpile(code)
71
+ try:
72
+ exec(py_code, globals())
73
+ except Exception as e:
74
+ print(f"Runtime Error: {e}")
75
+
76
+ def cmd_transpile(file_path: str, output: str):
77
+ path = Path(file_path)
78
+ if not path.is_file():
79
+ print(f"Error: file '{file_path}' not found.")
80
+ return
81
+ with open(path, 'r', encoding='utf-8') as f:
82
+ code = f.read()
83
+ py_code = transpile(code)
84
+ out_path = Path(output)
85
+ with open(out_path, 'w', encoding='utf-8') as f:
86
+ f.write(py_code)
87
+ print(f"Transpiled Python written to {out_path}")
88
+
89
+ def main():
90
+ parser = argparse.ArgumentParser(description="CSP - Custom Syntax for Python")
91
+ subparsers = parser.add_subparsers(dest="command", required=True)
92
+ run_parser = subparsers.add_parser("run", help="Run a CSP program directly")
93
+ run_parser.add_argument("file", help="CSP source file (.csp)")
94
+ transpile_parser = subparsers.add_parser("transpile", help="Transpile CSP (*.csp) to Python (*.py)")
95
+ transpile_parser.add_argument("file", help="CSP source file (.csp)")
96
+ transpile_parser.add_argument("-o", "--output", required=True, help="Output Python file (.py)")
97
+ subparsers.add_parser("test", help="Runs mutliple tests of CSP")
98
+ args, unknown = parser.parse_known_args()
99
+ if args.command is None and len(unknown) == 1:
100
+ cmd_run(unknown[0])
101
+ elif args.command == "test":
102
+ test()
103
+ elif args.command == "run":
104
+ cmd_run(args.file)
105
+ elif args.command == "transpile":
106
+ cmd_transpile(args.file, args.output)
107
+ else:
108
+ parser.print_help()
@@ -0,0 +1,275 @@
1
+ Metadata-Version: 2.4
2
+ Name: csp_lang
3
+ Version: 0.1.0
4
+ Summary: Custom Syntax for Python Language -- CSPLang
5
+ Author-email: Muhammad Abubakar Siddique Ansari <ansaricodes@gmail.com>
6
+ Project-URL: Homepage, https://github.com/Ansari-Codes/custom-syntax-for-python.git
7
+ Requires-Python: >=3.5
8
+ Description-Content-Type: text/markdown
9
+ License-File: LICENSE
10
+ Dynamic: license-file
11
+
12
+ # CSPLang – Custom Syntax for Python Language
13
+
14
+ **CSPLang** is a compact custom syntax designed for Python. It’s a toy language that works by transforming each line of CSP code into Python code, then executing it. The focus is on **writing less code but doing more work**.
15
+
16
+ Think about it this way:
17
+ > What if you run real python, but write it in a bit different way?
18
+
19
+ Basically, CSP doesn’t block you from using Python’s full ecosystem; it just gives you a syntactic sugar wrapper so your loops, functions, conditionals, and variables can be written in a shorter or more “DSL-like” style.
20
+
21
+ ---
22
+
23
+ ## Developer
24
+
25
+ I am **Muhammad Abubakar Siddique Ansari**, a passionate developer in **Data Science and AI**. I love creating utilities, exploring new programming ideas, and building simple yet powerful tools.
26
+
27
+ I am currently (2026) a **1st-year ICS student at KIPS College**, Punjab – Pakistan.
28
+ Portfolio: [https://ansari-codes.github.io/portfolio](https://ansari-codes.github.io/portfolio)
29
+
30
+ ---
31
+
32
+ ## Installation
33
+
34
+ 1. Clone the repo:
35
+ ```powershell
36
+ git clone https://github.com/Ansari-Codes/custom-syntax-for-python.git
37
+ cd custom-syntax-for-python
38
+ pip install -e .
39
+ ```
40
+
41
+ 2. Via pip:
42
+ ```powershell
43
+ pip install csp_lang
44
+ ```
45
+
46
+ 3. Pip installation using git:
47
+ ```powershell
48
+ pip install git+https://github.com/Ansari-Codes/custom-syntax-for-python.git
49
+ ```
50
+
51
+ ---
52
+
53
+ ## Key Principles
54
+
55
+ 1. **Compact Syntax:** Write less code for the same Python functionality.
56
+ 2. **Readable & Straightforward:** Easy to understand even if you are new to Python.
57
+ 3. **Direct Python Integration:** Most Python functions, utilities, and modules work without changes.
58
+
59
+ ---
60
+
61
+ ## Syntax Overview
62
+
63
+ ### 1. Comments
64
+
65
+ Single-line and multi-line comments are supported:
66
+
67
+ ```python
68
+ # Single-line comment
69
+
70
+ %
71
+ This is a
72
+ multi-line comment
73
+ %
74
+ ```
75
+
76
+ ### 2. Built-in Python Functions
77
+
78
+ Python functions and utilities work as-is.
79
+
80
+ ```python
81
+ print(10) # Works exactly like Python
82
+ len([1,2,3]) # Python’s len function
83
+ ```
84
+
85
+ ### 3. Variables
86
+
87
+ Use `<-` as the assignment operator:
88
+
89
+ ```r
90
+ name <- "Muhammad"
91
+ age <- 15
92
+ x <- 5 + 3
93
+ ```
94
+
95
+ ### 4. Conditionals
96
+
97
+ CSP replaces `if`, `elif`, and `else` with a simple, readable syntax:
98
+
99
+ ```python
100
+ x <- 5
101
+
102
+ %
103
+ IMPORTANT: Don;t use comments after colon of the conditions
104
+ EXAMPLE:
105
+ 1. Correct code:
106
+ x>0:
107
+ 2. Buggy code:
108
+ x>0: #comment
109
+ %
110
+
111
+ # if x > 0
112
+ x > 0:
113
+ print("x is positive")
114
+ # elif x == 5
115
+ : x == 5:
116
+ print("x is exactly 5")
117
+ # else
118
+ :
119
+ print("other")
120
+ ```
121
+
122
+ > The `:` indicates the start of a condition block, and `:` alone is treated as `else`.
123
+
124
+ ### 5. Loops
125
+
126
+ #### While Loop
127
+
128
+ Use `>>` for while loops:
129
+
130
+ ```python
131
+
132
+ %
133
+ IMPORTANT: Don;t use comments after colon of the condition
134
+ EXAMPLE:
135
+ 1. Correct code:
136
+ x > 0:
137
+ 2. Buggy code:
138
+ x > 0: #comment
139
+ %
140
+
141
+ x <- 3
142
+ >> x > 0:
143
+ print(x)
144
+ x <- x - 1
145
+ ```
146
+
147
+ #### For Loop
148
+
149
+ Use `=>` with `:` replacing `in`:
150
+
151
+ ```python
152
+
153
+ %
154
+ IMPORTANT: Don;t use comments after colon of the i:iterable:
155
+ EXAMPLE:
156
+ 1. Correct code:
157
+ x:range(5):
158
+
159
+ 2. Buggy code:
160
+ x:range(5): #comment
161
+ %
162
+
163
+ => i:[1,2,3]:
164
+ print(i)
165
+
166
+ => j:range(5):
167
+ print(j)
168
+ ```
169
+
170
+ > `i` is the loop variable, and `iterable` can be any Python iterable.
171
+
172
+ ### 6. Functions
173
+
174
+ Functions are defined using `$` and `[]` instead of `def` and `()`:
175
+
176
+ ```python
177
+
178
+ %
179
+ IMPORTANT: Don;t use comments after colon of the functio definition
180
+ EXAMPLE:
181
+ 1. Correct code:
182
+ $add[a, b]:
183
+
184
+ 2. Buggy code:
185
+ $add[a, b]: #comment
186
+ %
187
+
188
+ $add[a, b]:
189
+ -> a + b # return statement
190
+
191
+ $greet[name="User"]:
192
+ print(f"Hello {name}")
193
+ print(add(1, 1))
194
+ ```
195
+
196
+ Call functions normally:
197
+
198
+ ```python
199
+ print(add(2, 3))
200
+ greet()
201
+ greet("Muhammad")
202
+ ```
203
+
204
+ ### 7. Imports
205
+
206
+ Import modules as in Python:
207
+
208
+ ```python
209
+ import math as mt
210
+ from math import sqrt
211
+ ```
212
+
213
+ If you have tqdm installed, for example:
214
+ ```python
215
+ from tqdm import tqdm
216
+ from time import sleep
217
+ => i:tqdm(range(30)):
218
+ sleep(0.1)
219
+ ```
220
+
221
+ > Currently, importing other `.csp` files is not supported.
222
+
223
+ ---
224
+
225
+ ## File Format
226
+
227
+ CSP files use the `.csp` extension.
228
+
229
+ ---
230
+
231
+ ## CLI Usage
232
+
233
+ You can run CSP programs or transpile them to Python:
234
+
235
+ ```bash
236
+ # Run directly
237
+ csp run program.csp
238
+
239
+ # Transpile to Python file
240
+ csp transpile program.csp -o program.py
241
+ python program.py
242
+
243
+ # run tests
244
+ csp test
245
+ ```
246
+
247
+ ---
248
+
249
+ ## Example Program
250
+
251
+ ```python
252
+ x <- 3
253
+ $fun[a]:
254
+ print(f"Start {a}")
255
+ >> a > 0:
256
+ => i:[1,2]:
257
+ print("Loop", i)
258
+ a <- a - 1
259
+ -> "done"
260
+
261
+ print(fun(x))
262
+ ```
263
+
264
+ Output:
265
+
266
+ ```
267
+ Start 3
268
+ Loop 1
269
+ Loop 2
270
+ Loop 1
271
+ Loop 2
272
+ Loop 1
273
+ Loop 2
274
+ done
275
+ ```
@@ -0,0 +1,10 @@
1
+ LICENSE
2
+ README.md
3
+ pyproject.toml
4
+ csp/Transpiler.py
5
+ csp/csp.py
6
+ csp_lang.egg-info/PKG-INFO
7
+ csp_lang.egg-info/SOURCES.txt
8
+ csp_lang.egg-info/dependency_links.txt
9
+ csp_lang.egg-info/entry_points.txt
10
+ csp_lang.egg-info/top_level.txt
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ csp = csp.csp:main
@@ -0,0 +1 @@
1
+ csp
@@ -0,0 +1,25 @@
1
+ [project]
2
+ name = "csp_lang"
3
+ version = "0.1.0"
4
+ description = "Custom Syntax for Python Language -- CSPLang"
5
+ authors = [
6
+ { name = "Muhammad Abubakar Siddique Ansari", email = "ansaricodes@gmail.com" }
7
+ ]
8
+ readme = "README.md"
9
+ requires-python = ">=3.5"
10
+ dependencies = []
11
+
12
+ [project.urls]
13
+ Homepage = "https://github.com/Ansari-Codes/custom-syntax-for-python.git"
14
+
15
+ [tool.setuptools]
16
+ packages = ["csp"]
17
+ include-package-data = true
18
+
19
+ [build-system]
20
+ requires = ["setuptools>=61.0", "wheel"]
21
+
22
+ build-backend = "setuptools.build_meta"
23
+
24
+ [project.scripts]
25
+ csp = "csp.csp:main"
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+