curl-programming-lang 1.1.2__tar.gz → 1.2.1__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: curl-programming-lang
3
- Version: 1.1.2
3
+ Version: 1.2.1
4
4
  Summary: Curl is an open-source programming language built on Python technology
5
5
  Author: Ritvik Gautam
6
6
  License: Apache-2.0
@@ -47,6 +47,13 @@ git clone https://github.com/gautamritvik/Curl-Programming.git
47
47
  cd Curl-Programming
48
48
  pip install -e .
49
49
  ```
50
+ ---
51
+
52
+ ## Running the Curl terminal
53
+
54
+ ```
55
+ curlang
56
+ ```
50
57
 
51
58
  ## Running a Curl program
52
59
 
@@ -28,6 +28,13 @@ git clone https://github.com/gautamritvik/Curl-Programming.git
28
28
  cd Curl-Programming
29
29
  pip install -e .
30
30
  ```
31
+ ---
32
+
33
+ ## Running the Curl terminal
34
+
35
+ ```
36
+ curlang
37
+ ```
31
38
 
32
39
  ## Running a Curl program
33
40
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: curl-programming-lang
3
- Version: 1.1.2
3
+ Version: 1.2.1
4
4
  Summary: Curl is an open-source programming language built on Python technology
5
5
  Author: Ritvik Gautam
6
6
  License: Apache-2.0
@@ -47,6 +47,13 @@ git clone https://github.com/gautamritvik/Curl-Programming.git
47
47
  cd Curl-Programming
48
48
  pip install -e .
49
49
  ```
50
+ ---
51
+
52
+ ## Running the Curl terminal
53
+
54
+ ```
55
+ curlang
56
+ ```
50
57
 
51
58
  ## Running a Curl program
52
59
 
@@ -0,0 +1,275 @@
1
+ import sys
2
+ import platform
3
+ import argparse
4
+ from importlib.metadata import version as _pkg_version, PackageNotFoundError
5
+ from lexer import curl_tokenize
6
+ from interpreter import execute
7
+ from parser import Parser
8
+
9
+ try:
10
+ __version__ = _pkg_version("curl-programming-lang")
11
+ except PackageNotFoundError:
12
+ __version__ = "dev"
13
+
14
+ _COPYRIGHT = f"Copyright (c) 2024-2026 Ritvik Gautam. All rights reserved."
15
+
16
+ _LICENSE = """\
17
+ Curl is distributed under the Apache License, Version 2.0.
18
+
19
+ You may obtain a copy of the License at:
20
+ https://www.apache.org/licenses/LICENSE-2.0
21
+
22
+ Unless required by applicable law or agreed to in writing, software
23
+ distributed under the License is distributed on an "AS IS" BASIS,
24
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
25
+
26
+ Full license: https://github.com/gautamritvik/Curl-Programming/blob/main/LICENSE"""
27
+
28
+ _CREDITS = """\
29
+ Curl Programming Language
30
+ Created by Ritvik Gautam
31
+ Built on Python technology
32
+ Source: https://github.com/gautamritvik/Curl-Programming
33
+ PyPI: https://pypi.org/project/curl-programming-lang/"""
34
+
35
+
36
+ def main():
37
+ parser = argparse.ArgumentParser(
38
+ prog="curlang",
39
+ description="Curl programming language interpreter",
40
+ add_help=False,
41
+ )
42
+ parser.add_argument("file", nargs="?", help="Curl source file to run (.curl)")
43
+ parser.add_argument("-c", metavar="cmd", help="Run a single Curl statement")
44
+ parser.add_argument("-V", "--version", action="store_true", help="Show version and exit")
45
+ parser.add_argument("-h", "--help", action="store_true", help="Show this help message and exit")
46
+ parser.add_argument("--license", action="store_true", help="Show license information and exit")
47
+ parser.add_argument("--copyright", action="store_true", help="Show copyright notice and exit")
48
+ parser.add_argument("--credits", action="store_true", help="Show credits and exit")
49
+
50
+ args = parser.parse_args()
51
+
52
+ if args.version:
53
+ print(f"Curl {__version__}")
54
+ return
55
+
56
+ if args.help:
57
+ print(f"Curl {__version__} — command-line options\n")
58
+ parser.print_help()
59
+ return
60
+
61
+ if args.license:
62
+ print(_LICENSE)
63
+ return
64
+
65
+ if args.copyright:
66
+ print(_COPYRIGHT)
67
+ return
68
+
69
+ if args.credits:
70
+ print(_CREDITS)
71
+ return
72
+
73
+ if args.c:
74
+ _run_code(args.c)
75
+ elif args.file:
76
+ run_file(args.file)
77
+ else:
78
+ repl()
79
+
80
+
81
+ def _run_code(code):
82
+ try:
83
+ tokens = curl_tokenize(code)
84
+ ast = Parser(tokens).parse()
85
+ execute(ast)
86
+ except SyntaxError as e:
87
+ print(f"Syntax Error: {e}")
88
+ sys.exit(1)
89
+ except NameError as e:
90
+ print(f"Name Error: {e}")
91
+ sys.exit(1)
92
+ except RuntimeError as e:
93
+ print(f"Runtime Error: {e}")
94
+ sys.exit(1)
95
+ except Exception as e:
96
+ print(f"Error: {e}")
97
+ sys.exit(1)
98
+
99
+
100
+ def run_file(file_path):
101
+ try:
102
+ with open(file_path, "r") as f:
103
+ code = f.read()
104
+ except FileNotFoundError:
105
+ print(f"Error: File not found — '{file_path}'")
106
+ sys.exit(1)
107
+
108
+ try:
109
+ tokens = curl_tokenize(code)
110
+ ast = Parser(tokens).parse()
111
+ execute(ast)
112
+ except KeyboardInterrupt:
113
+ print("\nOperation interrupted by user.")
114
+ print(f"{{You cut off Curl {__version__} while it was trying to work! \U0001f61e}}")
115
+ sys.exit(1)
116
+ except SyntaxError as e:
117
+ print(f"Syntax Error: {e}")
118
+ sys.exit(1)
119
+ except NameError as e:
120
+ print(f"Name Error: {e}")
121
+ sys.exit(1)
122
+ except RuntimeError as e:
123
+ print(f"Runtime Error: {e}")
124
+ sys.exit(1)
125
+ except Exception as e:
126
+ print(f"Error: {e}")
127
+ sys.exit(1)
128
+
129
+ print(f"\n{{You were using Curl {__version__} \U0001f609}}")
130
+
131
+
132
+ def repl():
133
+ try:
134
+ import readline
135
+ except ImportError:
136
+ pass # Windows — basic input still works, just no arrow keys
137
+
138
+ print(f"Curl {__version__} ({platform.system()}) on {sys.platform}")
139
+ print('Type "help", "copyright", "credits" or "license" for more information.')
140
+
141
+ env = {
142
+ "variables": {},
143
+ "functions": {},
144
+ "imports": {},
145
+ "last_input": None,
146
+ }
147
+
148
+ buffer = []
149
+ depth = 0
150
+ in_other_coding = False
151
+
152
+ while True:
153
+ try:
154
+ prompt = "... " if (depth > 0 or in_other_coding) else ">>> "
155
+ line = input(prompt)
156
+ except EOFError:
157
+ print()
158
+ break
159
+ except KeyboardInterrupt:
160
+ print("\nKeyboardInterrupt")
161
+ buffer = []
162
+ depth = 0
163
+ in_other_coding = False
164
+ continue
165
+
166
+ stripped = line.strip()
167
+
168
+ # ── otherCoding raw-code mode ──────────────────────────────────────
169
+ if in_other_coding:
170
+ buffer.append(line)
171
+ if stripped == "}\\":
172
+ in_other_coding = False
173
+ _repl_exec("\n".join(buffer), env)
174
+ buffer = []
175
+ continue
176
+
177
+ # ── top-level REPL commands ────────────────────────────────────────
178
+ if depth == 0:
179
+ if stripped in ("exit", "quit", "exit()", "quit()"):
180
+ print("Goodbye!")
181
+ break
182
+ if stripped == "help":
183
+ _repl_help()
184
+ continue
185
+ if stripped == "license":
186
+ print(_LICENSE)
187
+ continue
188
+ if stripped == "copyright":
189
+ print(_COPYRIGHT)
190
+ continue
191
+ if stripped == "credits":
192
+ print(_CREDITS)
193
+ continue
194
+ if stripped in ("version", "__version__"):
195
+ print(f"Curl {__version__}")
196
+ continue
197
+ if stripped == "":
198
+ continue
199
+
200
+ buffer.append(line)
201
+
202
+ # ── otherCoding opener ─────────────────────────────────────────────
203
+ if depth == 0 and stripped.startswith("otherCoding"):
204
+ in_other_coding = True
205
+ continue
206
+
207
+ # ── block opener: ends with - but not --\ ──────────────────────────
208
+ if stripped.endswith("-") and not stripped.endswith("--\\"):
209
+ depth += 1
210
+ continue
211
+
212
+ # ── block closer(s) ────────────────────────────────────────────────
213
+ closes = stripped.count("--\\")
214
+ if closes:
215
+ depth = max(0, depth - closes)
216
+
217
+ # ── execute when back at depth 0 and line ends with \ ──────────────
218
+ if depth == 0 and stripped.endswith("\\"):
219
+ _repl_exec("\n".join(buffer), env)
220
+ buffer = []
221
+ continue
222
+
223
+ # ── bad input at depth 0 ───────────────────────────────────────────
224
+ if depth == 0:
225
+ print(" Syntax Error: statement must end with \\")
226
+ buffer = []
227
+
228
+
229
+ def _repl_exec(code, env):
230
+ try:
231
+ tokens = curl_tokenize(code)
232
+ ast = Parser(tokens).parse()
233
+ execute(ast, env)
234
+ except SyntaxError as e:
235
+ print(f" Syntax Error: {e}")
236
+ except NameError as e:
237
+ print(f" Name Error: {e}")
238
+ except RuntimeError as e:
239
+ print(f" Runtime Error: {e}")
240
+ except Exception as e:
241
+ print(f" Error: {e}")
242
+
243
+
244
+ def _repl_help():
245
+ print(f"""
246
+ Curl {__version__} — Quick Reference
247
+ ─────────────────────────────────────
248
+ Language syntax:
249
+ pcType{{"text"}}\\ Print to console
250
+ pcAsk{{"prompt?">>}}\\ Ask for input → input{{ans}}
251
+ var{{name, "value"}}\\ Assign a variable
252
+ var{{name}} Reference a variable
253
+ list{{"a"; "b"; "c"}} Create a list
254
+ createFunc{{name}}- Define a function
255
+ ...
256
+ --\\ End a block
257
+ func{{name}}\\ Call a function
258
+ if{{var{{x}} == "y", then}}- Conditional (elif / else supported)
259
+ import{{"math", m}}\\ Import a Python package
260
+ otherCoding{{"Python", Embed code in another language
261
+ ...
262
+ }}\\
263
+
264
+ REPL commands:
265
+ help Show this message
266
+ license Show license information
267
+ copyright Show copyright notice
268
+ credits Show credits
269
+ version Show version
270
+ exit / quit Leave the REPL
271
+ ─────────────────────────────────────""")
272
+
273
+
274
+ if __name__ == "__main__":
275
+ main()
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "curl-programming-lang"
7
- version = "1.1.2"
7
+ version = "1.2.1"
8
8
  description = "Curl is an open-source programming language built on Python technology"
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.7"
@@ -1,179 +0,0 @@
1
- import sys
2
- import platform
3
- from importlib.metadata import version as _pkg_version, PackageNotFoundError
4
- from lexer import curl_tokenize
5
- from interpreter import execute
6
- from parser import Parser
7
-
8
- try:
9
- __version__ = _pkg_version("curl-programming-lang")
10
- except PackageNotFoundError:
11
- __version__ = "dev"
12
-
13
-
14
- def main():
15
- if len(sys.argv) < 2:
16
- repl()
17
- else:
18
- run_file(sys.argv[1])
19
-
20
-
21
- def run_file(file_path):
22
- try:
23
- with open(file_path, "r") as f:
24
- code = f.read()
25
- except FileNotFoundError:
26
- print(f"Error: File not found — '{file_path}'")
27
- sys.exit(1)
28
-
29
- try:
30
- tokens = curl_tokenize(code)
31
- ast = Parser(tokens).parse()
32
- execute(ast)
33
- except KeyboardInterrupt:
34
- print("\nOperation interrupted by user.")
35
- print(f"{{You cut off Curl {__version__} while it was trying to work! \U0001f61e}}")
36
- sys.exit(1)
37
- except SyntaxError as e:
38
- print(f"Syntax Error: {e}")
39
- sys.exit(1)
40
- except NameError as e:
41
- print(f"Name Error: {e}")
42
- sys.exit(1)
43
- except RuntimeError as e:
44
- print(f"Runtime Error: {e}")
45
- sys.exit(1)
46
- except Exception as e:
47
- print(f"Error: {e}")
48
- sys.exit(1)
49
-
50
- print(f"\n{{You were using Curl {__version__} \U0001f609}}")
51
-
52
-
53
- def repl():
54
- # Enables arrow keys (left/right cursor movement) and
55
- # up/down history navigation in the REPL prompt.
56
- try:
57
- import readline
58
- except ImportError:
59
- pass # Windows — basic input still works, just no arrow keys
60
-
61
- print(f"Curl {__version__} ({platform.system()}) on {sys.platform}")
62
- print('Type "help" for more information, "exit" to quit.')
63
-
64
- env = {
65
- "variables": {},
66
- "functions": {},
67
- "imports": {},
68
- "last_input": None,
69
- }
70
-
71
- buffer = []
72
- depth = 0 # how many - blocks deep we are
73
- in_other_coding = False # inside an otherCoding{} raw block
74
-
75
- while True:
76
- try:
77
- prompt = "... " if (depth > 0 or in_other_coding) else ">>> "
78
- line = input(prompt)
79
- except EOFError:
80
- print()
81
- break
82
- except KeyboardInterrupt:
83
- print("\nKeyboardInterrupt")
84
- buffer = []
85
- depth = 0
86
- in_other_coding = False
87
- continue
88
-
89
- stripped = line.strip()
90
-
91
- # ── otherCoding raw-code mode ──────────────────────────────────────
92
- # Collect lines verbatim until the closing }\ on its own line
93
- if in_other_coding:
94
- buffer.append(line)
95
- if stripped == "}\\":
96
- in_other_coding = False
97
- _repl_exec("\n".join(buffer), env)
98
- buffer = []
99
- continue
100
-
101
- # ── top-level REPL commands (only when outside all blocks) ─────────
102
- if depth == 0:
103
- if stripped in ("exit", "quit", "exit()", "quit()"):
104
- print("Goodbye!")
105
- break
106
- if stripped == "help":
107
- _repl_help()
108
- continue
109
- if stripped == "":
110
- continue
111
-
112
- buffer.append(line)
113
-
114
- # ── otherCoding opener (no \ at end, special block syntax) ─────────
115
- if depth == 0 and stripped.startswith("otherCoding"):
116
- in_other_coding = True
117
- continue
118
-
119
- # ── block opener: ends with - but not --\ ──────────────────────────
120
- if stripped.endswith("-") and not stripped.endswith("--\\"):
121
- depth += 1
122
- continue
123
-
124
- # ── block closer(s): count --\ on this line ────────────────────────
125
- closes = stripped.count("--\\")
126
- if closes:
127
- depth = max(0, depth - closes)
128
-
129
- # ── execute when back at depth 0 and line ends with \ ──────────────
130
- if depth == 0 and stripped.endswith("\\"):
131
- _repl_exec("\n".join(buffer), env)
132
- buffer = []
133
- continue
134
-
135
- # ── bad input at depth 0: line didn't end correctly ────────────────
136
- if depth == 0:
137
- print(f" Syntax Error: statement must end with \\")
138
- buffer = []
139
-
140
-
141
- def _repl_exec(code, env):
142
- try:
143
- tokens = curl_tokenize(code)
144
- ast = Parser(tokens).parse()
145
- execute(ast, env)
146
- except SyntaxError as e:
147
- print(f" Syntax Error: {e}")
148
- except NameError as e:
149
- print(f" Name Error: {e}")
150
- except RuntimeError as e:
151
- print(f" Runtime Error: {e}")
152
- except Exception as e:
153
- print(f" Error: {e}")
154
-
155
-
156
- def _repl_help():
157
- print("""
158
- Curl — Quick Reference
159
- ─────────────────────────────
160
- pcType{"text"}\\ Print to console
161
- pcAsk{"prompt?">>}\\ Ask for input (access with input{ans})
162
- var{name, "value"}\\ Create a variable
163
- var{name} Reference a variable
164
- list{"a"; "b"; "c"} Create a list
165
- createFunc{name}- Define a function
166
- ...
167
- --\\ End a block
168
- func{name}\\ Call a function
169
- if{var{x} == "y", then}- Conditional
170
- import{"math", m}\\ Import a Python package
171
- otherCoding{"Python", Embed code in another language
172
- ...
173
- }\\
174
- exit Quit the REPL
175
- ─────────────────────────────""")
176
-
177
-
178
- if __name__ == "__main__":
179
- main()