sanskrypt-lang 2.0.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.
@@ -0,0 +1,48 @@
1
+ Metadata-Version: 2.4
2
+ Name: sanskrypt-lang
3
+ Version: 2.0.0
4
+ Summary: A root-based, order-agnostic programming language inspired by Paninian grammar.
5
+ Home-page: https://github.com/yourusername/sanskrypt
6
+ Author: Your Name
7
+ Author-email: your.email@example.com
8
+ Classifier: Programming Language :: Python :: 3
9
+ Classifier: License :: OSI Approved :: MIT License
10
+ Classifier: Operating System :: OS Independent
11
+ Requires-Python: >=3.6
12
+ Description-Content-Type: text/markdown
13
+ Dynamic: author
14
+ Dynamic: author-email
15
+ Dynamic: classifier
16
+ Dynamic: description
17
+ Dynamic: description-content-type
18
+ Dynamic: home-page
19
+ Dynamic: requires-python
20
+ Dynamic: summary
21
+
22
+ # Sanskrypt & EngScript
23
+
24
+ A root-based, order-agnostic programming language parser inspired by Paninian grammar.
25
+
26
+ Sanskrypt replaces hundreds of arbitrary keywords with a minimal set of foundational roots (*Dhatus*), allowing you to construct expressive, self-documenting code. It supports two dialects: the original **Sanskrypt** (using Sanskrit roots) and **EngScript** (mapped to English roots).
27
+
28
+ ## Installation
29
+
30
+ ```bash
31
+ pip install sanskrypt
32
+ ```
33
+
34
+ ## Quick Start
35
+
36
+ ```python
37
+ import sanskrypt
38
+
39
+ code = """
40
+ hold_var n_count v_0
41
+ do_loop n_count < 3
42
+ speak_out n_count
43
+ compute_math n_count n_count + 1
44
+ end
45
+ """
46
+
47
+ sanskrypt.run(code, lang='engscript')
48
+ ```
@@ -0,0 +1,27 @@
1
+ # Sanskrypt & EngScript
2
+
3
+ A root-based, order-agnostic programming language parser inspired by Paninian grammar.
4
+
5
+ Sanskrypt replaces hundreds of arbitrary keywords with a minimal set of foundational roots (*Dhatus*), allowing you to construct expressive, self-documenting code. It supports two dialects: the original **Sanskrypt** (using Sanskrit roots) and **EngScript** (mapped to English roots).
6
+
7
+ ## Installation
8
+
9
+ ```bash
10
+ pip install sanskrypt
11
+ ```
12
+
13
+ ## Quick Start
14
+
15
+ ```python
16
+ import sanskrypt
17
+
18
+ code = """
19
+ hold_var n_count v_0
20
+ do_loop n_count < 3
21
+ speak_out n_count
22
+ compute_math n_count n_count + 1
23
+ end
24
+ """
25
+
26
+ sanskrypt.run(code, lang='engscript')
27
+ ```
@@ -0,0 +1,26 @@
1
+ from .interpreter import Interpreter
2
+
3
+ def run(code, lang='sanskrypt'):
4
+ """
5
+ Executes a string of Sanskrypt or EngScript code.
6
+ :param code: The code string to execute.
7
+ :param lang: 'sanskrypt' or 'engscript'.
8
+ :return: The Interpreter instance (contains .variables).
9
+ """
10
+ interpreter = Interpreter(lang=lang)
11
+ interpreter.execute(code)
12
+ return interpreter
13
+
14
+ def run_file(filepath, lang=None):
15
+ """
16
+ Executes a .skr or .eng file.
17
+ :param filepath: Path to the script.
18
+ :param lang: Forces language parser (auto-detected if None).
19
+ """
20
+ if lang is None:
21
+ lang = 'engscript' if filepath.endswith('.eng') else 'sanskrypt'
22
+
23
+ with open(filepath, 'r', encoding='utf-8') as f:
24
+ code = f.read()
25
+
26
+ return run(code, lang=lang)
@@ -0,0 +1,148 @@
1
+ import re
2
+ import shlex
3
+ import urllib.request
4
+
5
+ class Interpreter:
6
+ def __init__(self, lang='sanskrypt'):
7
+ self.variables = {}
8
+ self.lang = lang.lower()
9
+
10
+ if self.lang == 'engscript':
11
+ self.roots = {
12
+ 'speak': 'io',
13
+ 'hold': 'assign',
14
+ 'compute': 'compute',
15
+ 'do': 'control',
16
+ }
17
+ self.end_marker = 'end'
18
+ else:
19
+ # Default to Sanskrypt
20
+ self.roots = {
21
+ 'vad': 'io',
22
+ 'dhri': 'assign',
23
+ 'gan': 'compute',
24
+ 'kri': 'control',
25
+ }
26
+ self.end_marker = 'iti'
27
+
28
+ def _get_root(self, command):
29
+ for root in self.roots:
30
+ if command.startswith(root):
31
+ return root, command[len(root):]
32
+ return None, None
33
+
34
+ def execute(self, code):
35
+ lines = [l.strip() for l in code.strip().split('\n') if l.strip() and not l.strip().startswith('#')]
36
+ self._execute_block(lines)
37
+
38
+ def _extract_vibhakti(self, args, needs_target=True):
39
+ var_name = None
40
+ val_parts = []
41
+ for arg in args:
42
+ if needs_target and arg.startswith('n_') and var_name is None:
43
+ var_name = arg[2:]
44
+ elif arg.startswith('v_'):
45
+ val_parts.append(arg[2:])
46
+ else:
47
+ if arg.startswith('n_'):
48
+ val_parts.append(arg[2:])
49
+ else:
50
+ val_parts.append(arg)
51
+
52
+ if needs_target and var_name is None and val_parts:
53
+ var_name = val_parts[0]
54
+ val_parts = val_parts[1:]
55
+
56
+ val_expr = " ".join(val_parts) if val_parts else None
57
+ return var_name, val_expr
58
+
59
+ def _execute_block(self, lines):
60
+ pc = 0
61
+ while pc < len(lines):
62
+ line = lines[pc]
63
+ if line == self.end_marker:
64
+ pc += 1
65
+ continue
66
+
67
+ tokens = shlex.split(line, posix=False)
68
+ command = tokens[0]
69
+ args = tokens[1:]
70
+
71
+ base_root, suffix = self._get_root(command)
72
+ if not base_root:
73
+ raise SyntaxError(f"[{self.lang.upper()}] Unknown root: {command}")
74
+
75
+ action = self.roots[base_root]
76
+
77
+ if action == 'assign':
78
+ var_name, val_expr = self._extract_vibhakti(args, needs_target=True)
79
+ self.variables[var_name] = self._eval_expr(val_expr)
80
+
81
+ elif action == 'io':
82
+ if suffix.startswith('_net'):
83
+ var_name, url_expr = self._extract_vibhakti(args, needs_target=True)
84
+ url = self._eval_expr(url_expr)
85
+ try:
86
+ req = urllib.request.Request(url, headers={'User-Agent': f'{self.lang.capitalize()}/2.0'})
87
+ with urllib.request.urlopen(req) as response:
88
+ content = response.read().decode('utf-8')
89
+ self.variables[var_name] = content[:150] + "... [truncated]"
90
+ except Exception as e:
91
+ self.variables[var_name] = f"Network Error: {e}"
92
+ else:
93
+ _, val_expr = self._extract_vibhakti(args, needs_target=False)
94
+ print(f"Output: {self._eval_expr(val_expr)}")
95
+
96
+ elif action == 'compute':
97
+ var_name, val_expr = self._extract_vibhakti(args, needs_target=True)
98
+ self.variables[var_name] = self._eval_expr(val_expr)
99
+
100
+ elif action == 'control':
101
+ end_idx = self._find_block_end(lines, pc)
102
+ block_lines = lines[pc+1:end_idx]
103
+
104
+ _, cond_expr = self._extract_vibhakti(args, needs_target=False)
105
+
106
+ if suffix.startswith('_yadi') or suffix.startswith('_if'):
107
+ if self._eval_expr(cond_expr):
108
+ self._execute_block(block_lines)
109
+ elif suffix.startswith('_chakra') or suffix.startswith('_loop'):
110
+ while self._eval_expr(cond_expr):
111
+ self._execute_block(block_lines)
112
+
113
+ pc = end_idx
114
+
115
+ pc += 1
116
+
117
+ def _find_block_end(self, lines, start_idx):
118
+ depth = 1
119
+ for i in range(start_idx + 1, len(lines)):
120
+ line = lines[i]
121
+
122
+ # Count opening blocks
123
+ if self.lang == 'sanskrypt' and line.startswith('kri_'): depth += 1
124
+ elif self.lang == 'engscript' and line.startswith('do_'): depth += 1
125
+
126
+ # Count closing blocks
127
+ if line == self.end_marker: depth -= 1
128
+
129
+ if depth == 0: return i
130
+
131
+ raise SyntaxError(f"Missing '{self.end_marker}' (block end marker) starting at line {start_idx}")
132
+
133
+ def _eval_expr(self, expr_str):
134
+ if not expr_str: return ""
135
+ if expr_str.startswith('"') and expr_str.endswith('"'):
136
+ return expr_str[1:-1]
137
+
138
+ sorted_vars = sorted(self.variables.keys(), key=len, reverse=True)
139
+ for var in sorted_vars:
140
+ val = self.variables[var]
141
+ if isinstance(val, str):
142
+ expr_str = re.sub(rf'\b{var}\b', f'"{val}"', expr_str)
143
+ else:
144
+ expr_str = re.sub(rf'\b{var}\b', str(val), expr_str)
145
+ try:
146
+ return eval(expr_str)
147
+ except Exception:
148
+ return expr_str
@@ -0,0 +1,48 @@
1
+ Metadata-Version: 2.4
2
+ Name: sanskrypt-lang
3
+ Version: 2.0.0
4
+ Summary: A root-based, order-agnostic programming language inspired by Paninian grammar.
5
+ Home-page: https://github.com/yourusername/sanskrypt
6
+ Author: Your Name
7
+ Author-email: your.email@example.com
8
+ Classifier: Programming Language :: Python :: 3
9
+ Classifier: License :: OSI Approved :: MIT License
10
+ Classifier: Operating System :: OS Independent
11
+ Requires-Python: >=3.6
12
+ Description-Content-Type: text/markdown
13
+ Dynamic: author
14
+ Dynamic: author-email
15
+ Dynamic: classifier
16
+ Dynamic: description
17
+ Dynamic: description-content-type
18
+ Dynamic: home-page
19
+ Dynamic: requires-python
20
+ Dynamic: summary
21
+
22
+ # Sanskrypt & EngScript
23
+
24
+ A root-based, order-agnostic programming language parser inspired by Paninian grammar.
25
+
26
+ Sanskrypt replaces hundreds of arbitrary keywords with a minimal set of foundational roots (*Dhatus*), allowing you to construct expressive, self-documenting code. It supports two dialects: the original **Sanskrypt** (using Sanskrit roots) and **EngScript** (mapped to English roots).
27
+
28
+ ## Installation
29
+
30
+ ```bash
31
+ pip install sanskrypt
32
+ ```
33
+
34
+ ## Quick Start
35
+
36
+ ```python
37
+ import sanskrypt
38
+
39
+ code = """
40
+ hold_var n_count v_0
41
+ do_loop n_count < 3
42
+ speak_out n_count
43
+ compute_math n_count n_count + 1
44
+ end
45
+ """
46
+
47
+ sanskrypt.run(code, lang='engscript')
48
+ ```
@@ -0,0 +1,8 @@
1
+ README.md
2
+ setup.py
3
+ sanskrypt/__init__.py
4
+ sanskrypt/interpreter.py
5
+ sanskrypt_lang.egg-info/PKG-INFO
6
+ sanskrypt_lang.egg-info/SOURCES.txt
7
+ sanskrypt_lang.egg-info/dependency_links.txt
8
+ sanskrypt_lang.egg-info/top_level.txt
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,25 @@
1
+ import os
2
+ from setuptools import setup, find_packages
3
+
4
+ # Read the README file for the long description
5
+ with open(os.path.join(os.path.dirname(__file__), 'README.md'), encoding='utf-8') as f:
6
+ long_description = f.read()
7
+
8
+ setup(
9
+ name='sanskrypt-lang', # Unique name on PyPI
10
+ version='2.0.0',
11
+ description='A root-based, order-agnostic programming language inspired by Paninian grammar.',
12
+ long_description=long_description,
13
+ long_description_content_type='text/markdown',
14
+ packages=find_packages(),
15
+ author='Your Name',
16
+ author_email='your.email@example.com',
17
+ url='https://github.com/yourusername/sanskrypt', # Update with your repo
18
+ classifiers=[
19
+ 'Programming Language :: Python :: 3',
20
+ 'License :: OSI Approved :: MIT License',
21
+ 'Operating System :: OS Independent',
22
+ ],
23
+ python_requires='>=3.6',
24
+ install_requires=[],
25
+ )