samlang 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.
Files changed (36) hide show
  1. samlang-0.1.0/LICENSE +51 -0
  2. samlang-0.1.0/MANIFEST.in +4 -0
  3. samlang-0.1.0/PKG-INFO +306 -0
  4. samlang-0.1.0/README.md +277 -0
  5. samlang-0.1.0/examples/advanced_syntax.sl +74 -0
  6. samlang-0.1.0/examples/demo_import.sl +72 -0
  7. samlang-0.1.0/examples/demo_oop.sl +104 -0
  8. samlang-0.1.0/examples/hello.sl +140 -0
  9. samlang-0.1.0/examples/utils.sl +21 -0
  10. samlang-0.1.0/pyproject.toml +44 -0
  11. samlang-0.1.0/setup.cfg +4 -0
  12. samlang-0.1.0/src/samlang/__init__.py +6 -0
  13. samlang-0.1.0/src/samlang/__main__.py +8 -0
  14. samlang-0.1.0/src/samlang/ast_nodes.py +641 -0
  15. samlang-0.1.0/src/samlang/cli.py +84 -0
  16. samlang-0.1.0/src/samlang/environment.py +386 -0
  17. samlang-0.1.0/src/samlang/errors.py +74 -0
  18. samlang-0.1.0/src/samlang/interpreter.py +1791 -0
  19. samlang-0.1.0/src/samlang/lexer.py +386 -0
  20. samlang-0.1.0/src/samlang/lsp/__init__.py +8 -0
  21. samlang-0.1.0/src/samlang/lsp/__main__.py +15 -0
  22. samlang-0.1.0/src/samlang/lsp/analyzer.py +602 -0
  23. samlang-0.1.0/src/samlang/lsp/protocol.py +80 -0
  24. samlang-0.1.0/src/samlang/lsp/server.py +166 -0
  25. samlang-0.1.0/src/samlang/parser.py +1968 -0
  26. samlang-0.1.0/src/samlang/runner.py +56 -0
  27. samlang-0.1.0/src/samlang/stdlib.py +73 -0
  28. samlang-0.1.0/src/samlang/tokens.py +136 -0
  29. samlang-0.1.0/src/samlang.egg-info/PKG-INFO +306 -0
  30. samlang-0.1.0/src/samlang.egg-info/SOURCES.txt +34 -0
  31. samlang-0.1.0/src/samlang.egg-info/dependency_links.txt +1 -0
  32. samlang-0.1.0/src/samlang.egg-info/entry_points.txt +2 -0
  33. samlang-0.1.0/src/samlang.egg-info/top_level.txt +1 -0
  34. samlang-0.1.0/tests/test_lsp.py +145 -0
  35. samlang-0.1.0/tests/test_oop.py +221 -0
  36. samlang-0.1.0/tests/test_samlang.py +1030 -0
samlang-0.1.0/LICENSE ADDED
@@ -0,0 +1,51 @@
1
+ SamLang Proprietary License
2
+ ============================
3
+
4
+ Copyright (c) 2026 Samrane Ahmed. All Rights Reserved.
5
+
6
+ NOTICE: This software and all associated documentation, source code, compiled
7
+ binaries, examples, and related materials (collectively, the "Software") are
8
+ the exclusive intellectual property of Samrane Ahmed ("the Owner").
9
+
10
+ 1. OWNERSHIP
11
+ The Software, including all source code, design, architecture, algorithms,
12
+ and documentation, is the sole and exclusive property of Samrane Ahmed.
13
+ All intellectual property rights, including but not limited to copyright,
14
+ patent rights, trade secrets, and trademark rights, are retained by the Owner.
15
+
16
+ 2. RESTRICTIONS
17
+ Unless explicitly authorized in writing by the Owner, you may NOT:
18
+ a) Copy, reproduce, or duplicate the Software or any part thereof.
19
+ b) Modify, adapt, translate, or create derivative works based on the Software.
20
+ c) Distribute, sublicense, lease, rent, sell, or otherwise transfer the
21
+ Software to any third party.
22
+ d) Reverse engineer, decompile, disassemble, or attempt to derive the source
23
+ code of the Software.
24
+ e) Remove, alter, or obscure any copyright notices, trademarks, or other
25
+ proprietary rights notices contained in the Software.
26
+ f) Use the Software for commercial purposes without a separate commercial
27
+ license agreement with the Owner.
28
+
29
+ 3. PERMITTED USE
30
+ The Owner may grant limited, non-exclusive, non-transferable, revocable
31
+ licenses to use the Software under separate written agreements. Any such
32
+ license does not constitute a transfer of ownership.
33
+
34
+ 4. NO WARRANTY
35
+ THE SOFTWARE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
36
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
37
+ FITNESS FOR A PARTICULAR PURPOSE, AND NONINFRINGEMENT.
38
+
39
+ 5. LIMITATION OF LIABILITY
40
+ IN NO EVENT SHALL THE OWNER BE LIABLE FOR ANY CLAIM, DAMAGES, OR OTHER
41
+ LIABILITY ARISING FROM THE USE OR INABILITY TO USE THE SOFTWARE.
42
+
43
+ 6. TERMINATION
44
+ Any unauthorized use of the Software automatically terminates any permissions
45
+ granted and may result in legal action.
46
+
47
+ 7. GOVERNING LAW
48
+ This license shall be governed by and construed in accordance with
49
+ applicable international copyright laws and treaties.
50
+
51
+ For licensing inquiries, contact: Samrane Ahmed
@@ -0,0 +1,4 @@
1
+ include LICENSE
2
+ include README.md
3
+ recursive-include src/samlang *.py
4
+ recursive-include examples *.sl
samlang-0.1.0/PKG-INFO ADDED
@@ -0,0 +1,306 @@
1
+ Metadata-Version: 2.4
2
+ Name: samlang
3
+ Version: 0.1.0
4
+ Summary: SamLang — A modern, high-performance programming language blending Python simplicity with C# elegance.
5
+ Author: Samrane Ahmed
6
+ License-Expression: LicenseRef-Proprietary
7
+ Project-URL: Homepage, https://github.com/samrane-ahmed/samlang
8
+ Project-URL: Repository, https://github.com/samrane-ahmed/samlang
9
+ Project-URL: Issues, https://github.com/samrane-ahmed/samlang/issues
10
+ Keywords: programming-language,interpreter,samlang,compiler,oop
11
+ Classifier: Development Status :: 4 - Beta
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: Intended Audience :: Education
14
+ Classifier: Operating System :: OS Independent
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: Programming Language :: Python :: 3.8
17
+ Classifier: Programming Language :: Python :: 3.9
18
+ Classifier: Programming Language :: Python :: 3.10
19
+ Classifier: Programming Language :: Python :: 3.11
20
+ Classifier: Programming Language :: Python :: 3.12
21
+ Classifier: Programming Language :: Python :: 3.13
22
+ Classifier: Programming Language :: Python :: 3.14
23
+ Classifier: Topic :: Software Development :: Compilers
24
+ Classifier: Topic :: Software Development :: Interpreters
25
+ Requires-Python: >=3.8
26
+ Description-Content-Type: text/markdown
27
+ License-File: LICENSE
28
+ Dynamic: license-file
29
+
30
+ # 🚀 SamLang (`.sl`)
31
+
32
+ A modern, high-performance, general-purpose programming language.
33
+ **Author:** Samrane Ahmed
34
+
35
+ ---
36
+
37
+ ## 📁 Project Architecture
38
+
39
+ ```
40
+ nova/
41
+ ├── src/
42
+ │ └── samlang/
43
+ │ ├── __init__.py # Package metadata
44
+ │ ├── tokens.py # Token types, Position tracking
45
+ │ ├── errors.py # Error diagnostics with visual arrows (^)
46
+ │ ├── ast_nodes.py # AST Node definitions (Number, BinOp, Assign, etc.)
47
+ │ ├── lexer.py # Lexical analyzer / Tokenizer
48
+ │ ├── parser.py # Recursive descent parser (BODMAS/Precedence)
49
+ │ ├── environment.py # Scopes and symbol table bindings
50
+ │ ├── interpreter.py # AST Tree-Walk evaluator
51
+ │ ├── runner.py # Execution pipeline
52
+ │ └── cli.py # CLI runner and interactive REPL
53
+ ├── examples/
54
+ │ └── hello.sl # Example SamLang script
55
+ ├── tests/
56
+ │ └── test_samlang.py # Automated test suite
57
+ └── main.py # Root CLI entry point
58
+ ```
59
+
60
+ ---
61
+
62
+ ## ⚡ Quick Start
63
+
64
+ ### 1. Run a SamLang Script (`.sl`)
65
+ ```bash
66
+ py main.py examples/hello.sl
67
+ ```
68
+
69
+ ### 2. Launch the Interactive REPL
70
+ ```bash
71
+ py main.py
72
+ ```
73
+ ```text
74
+ ==================================================
75
+ SamLang 0.1.0 Interactive REPL
76
+ Created by Samrane Ahmed
77
+ Type 'exit' or 'quit' to exit.
78
+ ==================================================
79
+ samlang> x = 4;
80
+ samlang> y = 10;
81
+ samlang> println "Sum is:", x + y;
82
+ Sum is: 14
83
+ samlang> echo "Testing: "; println "Done!"
84
+ Testing: Done!
85
+ ```
86
+
87
+ ### 3. Run Tests
88
+ ```bash
89
+ py tests/test_samlang.py
90
+ ```
91
+
92
+ ---
93
+
94
+ ## 🎯 Language Features
95
+
96
+ ### Phase 1: Foundation & Arithmetic
97
+ - [x] **Dynamic Variable Declaration:** Direct assignment `x = 4;` (no mandatory `let` required)
98
+ - [x] **Semicolons Support:** Semicolon `;` support for clean statement termination & multiple statements on one line
99
+ - [x] **Output Statements:**
100
+ - `println expr1, expr2...` (prints with newline)
101
+ - `print expr1, expr2...` (prints inline without newline)
102
+ - `echo expr1, expr2...` (alias to `print`, inline output)
103
+ - [x] **Numbers & Types:** Integers (`10`, `-5`), Floats (`3.14`), Strings with escapes
104
+ - [x] **Arithmetic:** `+`, `-`, `*`, `/`, `%`, `^` (power) with mathematical precedence
105
+ - [x] **Parentheses:** For grouping expressions `(a + b) * c`
106
+ - [x] **Comments:** Single-line comments starting with `#`
107
+ - [x] **Precision Diagnostics:** Line & column tracking with visual pointer arrows (`^`)
108
+
109
+ ### Phase 2: Environment, Types & Scoping
110
+ - [x] **Booleans & Null:** `true`, `false`, and `null` literals
111
+ - [x] **Comparison Operators:** `==`, `!=`, `<`, `>`, `<=`, `>=`
112
+ - [x] **Logical Operators:** `and`, `or`, `not` as well as C-style `&&`, `||`, `!`
113
+ - [x] **Lexical Scoping & Code Blocks:** `{ ... }` blocks with local scope isolation and outer variable mutability
114
+
115
+ ### Phase 3: Functions, Dual Blocks & Control Flow
116
+ - [x] **Functions (`func`):** Definition with `func name(a, b) ...`, parameter binding, call stack
117
+ - [x] **Return Statement (`return`):** Early returns, returning values or null
118
+ - [x] **Dual Block Styles:**
119
+ - **C/JS Style:** Using braces `{ statement1; statement2; }`
120
+ - **Python Style:** Using colon and indentation `: \n statement1 \n statement2`
121
+ - [x] **Conditional Branches:** `if`, `elif`, `else` (supports both brace and colon syntax)
122
+ - [x] **Loops (`while`):** While loops (supports both brace and colon syntax)
123
+ - [x] **Recursion:** Full recursive calls and closures supported
124
+
125
+ ### Phase 4: Advanced Loops & Unique Superpowers
126
+ - [x] **C-Style For Loop:** `for (init; cond; step) { ... }` with optional components (`for (;;)`)
127
+ - [x] **Python-Style For Loop:** `for i in range(stop)` and `for i in range(start, stop, step)`
128
+ - [x] **Do-While Loop:** `do { ... } while (cond);` (executes at least once)
129
+ - [x] **Real Constants (`const`):** Immutable constants with strict runtime reassign prevention
130
+ - [x] **Increment & Decrement (`++` / `--`):** Prefix and postfix increment/decrement (`x++`, `++x`, `x--`, `--x`)
131
+ - [x] **Compound Assignments:** `+=`, `-=`, `*=`, `/=`, `%=` (numbers and string operations)
132
+ - [x] **Repeat Loop:** `repeat count { ... }` or `repeat count: ...` for clean, simple repetitions
133
+
134
+ ### Phase 5: Data Structures, String Interpolation & Built-ins
135
+ - [x] **Arrays / Lists:** `[1, 2, "three"]`, indexing `arr[0]`, negative indexing `arr[-1]`, mutation `arr[0] = 99;`
136
+ - [x] **Array Looping:**
137
+ - Parcours par élément: `for x in list { ... }`
138
+ - Parcours par index et élément: `for i, x in list { ... }`
139
+ - Parcours par index pur: `for i in range(len(list)) { ... }`
140
+ - [x] **Dictionaries / HashMaps:** `{ name: "Ahmed", age: 22 }`, dot access `d.name`, bracket access `d["age"]`
141
+ - [x] **Dictionary Iteration:** `for key, val in dict { ... }`
142
+ - [x] **Ternary Operator:** `condition ? val1 : val2` (supports chaining)
143
+ - [x] **Direct String Interpolation:** `"Salam ${name}, next year: ${year + 1}!"` with nested expressions
144
+ - [x] **String Built-in Functions & Methods:**
145
+ - `clean(s)` / `s.clean()` (strip / trim)
146
+ - `upper(s)` / `s.upper()`
147
+ - `lower(s)` / `s.lower()`
148
+ - `mirror(s)` / `s.mirror()` (reverse)
149
+ - `begin(s, prefix)` / `s.begin(prefix)` (startswith)
150
+ - `end(s, suffix)` / `s.end(suffix)` (endswith)
151
+ - `find(s, sub)` / `s.find(sub)`
152
+ - `clip(s, start, end)` / `clp` / `s.clip(...)` (slice / substring)
153
+ - `divide(s, sep)` / `s.divide(sep)` (split)
154
+ - `merge(arr, sep)` / `arr.merge(sep)` / `sep.merge(arr)` (join)
155
+ - `swap(s, old, new)` / `s.swap(old, new)` (replace)
156
+ - [x] **SQL-Style Array Built-in Functions & Methods:**
157
+ - `order(arr)` / `arr.order()` (ORDER BY ASC)
158
+ - `order_desc(arr)` / `arr.order_desc()` (ORDER BY DESC)
159
+ - `distinct(arr)` / `arr.distinct()` (DISTINCT)
160
+ - `limit(arr, n)` / `arr.limit(n)` (LIMIT)
161
+ - `offset(arr, n)` / `arr.offset(n)` (OFFSET)
162
+ - `count(arr)` / `arr.count()` (COUNT(*))
163
+ - `sum(arr)` / `arr.sum()` (SUM)
164
+ - `avg(arr)` / `arr.avg()` (AVG)
165
+ - `min(arr)` / `max(arr)` (MIN / MAX)
166
+ - `union(arr1, arr2)` (UNION)
167
+ - `exists(arr, val)` / `arr.exists(val)` (EXISTS)
168
+ - `insert(arr, item, idx)` / `arr.insert(...)` (INSERT)
169
+ - `delete(arr, val)` / `arr.delete(val)` (DELETE)
170
+
171
+ ### Phase 6: Modules & Import System (Ready for `spm`)
172
+ - [x] **File Module Imports:**
173
+ - Namespace import: `import "./utils.sl";` -> `utils.func()`
174
+ - Alias import: `import "./utils.sl" as u;` -> `u.func()`
175
+ - Named items: `import { add, sub } from "./math.sl";`
176
+ - Renamed items: `import { add as plus } from "./math.sl";`
177
+ - Wildcard import: `import * from "./utils.sl";`
178
+ - Python-style import: `from "./utils.sl" import add, sub;`
179
+ - [x] **Standard Library Modules:**
180
+ - `import math;` (`pi`, `sqrt`, `floor`, `ceil`, `sin`, `cos`, `random`, `randint`, etc.)
181
+ - `import json;` (`stringify`, `parse`)
182
+ - `import time;` (`now`, `date`, `sleep`, `clock`)
183
+ - `import os;` (`cwd`, `exists`, `is_file`, `is_dir`, `read_file`, `write_file`, `env`)
184
+ - [x] **Modular Architecture:**
185
+ - Package lookup in `spm_modules/` (prepared for SamLang Package Manager `spm`)
186
+ - Cyclic import protection & module caching
187
+ - Private symbol convention (`_private` ignored in wildcard imports)
188
+
189
+ ### Phase 7: Advanced Syntax & Modern Functional Superpowers
190
+ - [x] **Loop Controls (`break` & `continue`):** Works in `while`, `for (;;) `, `for-in`, `repeat`.
191
+ - [x] **Exception Handling (`try / catch / finally`):**
192
+ - Safe error trapping: `try { ... } catch (err) { ... } finally { ... }`
193
+ - Dual syntax support (braces `{}` and colons `:`)
194
+ - Rich error object `err.message`, `err.details`, `err.type`.
195
+ - [x] **Arrow Functions / Lambdas (`=>`):**
196
+ - Multi-arg: `(x, y) => x + y`
197
+ - Single-arg shorthand: `x => x * 2`
198
+ - Block body: `(x) => { return x + 1; }`
199
+ - [x] **Functional Array Methods:**
200
+ - `arr.map(fn)`: Map transformation over elements
201
+ - `arr.filter(fn)`: Filter elements matching predicate
202
+ - `arr.reduce(fn, initial)`: Fold/reduce elements to single value
203
+ - `arr.for_each(fn)`: Execute action per element
204
+
205
+ ### Phase 8: Object-Oriented Programming (POO / OOP)
206
+ - [x] **Classes (`class`):** Full class declarations supporting both `{}` and `:` blocks.
207
+ - [x] **C#-Style Auto-Properties:**
208
+ - Read/Write: `let Name { get; set; }`
209
+ - Default values: `let Age { get; set; } = 18`
210
+ - Read-only: `let Id { get; } = "XYZ"` (reassignment raises runtime error)
211
+ - [x] **Constructors:**
212
+ - C# style constructors named after the class `Person(name, age) { ... }` or `func init(...)`.
213
+ - Chaining / parent constructor delegation via `base(...)`.
214
+ - [x] **Inheritance (`:`):** Single class inheritance: `class Student : Person`.
215
+ - [x] **Explicit Polymorphism:**
216
+ - Parent methods marked `func virtuel display()`
217
+ - Child methods marked `func override display()`
218
+ - Enforced runtime safety: derived classes cannot override non-virtual methods, preventing accidental method hiding.
219
+ - [x] **Parent Delegation (`base`):** `base(...)` for constructor delegation and `base.method()` for parent methods.
220
+ - [x] **Self-Reference:** Both `this` (C# style) and `self` (Python style) are fully supported.
221
+ - [x] **Flexible Instantiation Styles:**
222
+ - Untyped dynamic assignment: `s = new Student("Ahmed", 22)`
223
+ - Standard declaration: `let s = new Student("Ahmed", 22)`
224
+ - Polymorphic typed declaration: `Person s = new Student("Ahmed", 22)` (verifies subclass relationship at runtime)
225
+ - Exact typed declaration: `Student s = new Student("Ahmed", 22)`
226
+ - Instantiation without `new`: `Student("Ahmed", 22)`
227
+ - [x] **Static Methods (`static`):** `static func add(a, b)` called directly on the class (`MathHelper.add(a, b)`).
228
+
229
+ ---
230
+
231
+ ## 🌐 Universal IDE Support & SamLang LSP (`samlang-lsp`)
232
+
233
+ SamLang implements the standard **Language Server Protocol (LSP 3.17)**, giving any modern editor first-class IDE capabilities:
234
+
235
+ | Feature | Description |
236
+ | :--- | :--- |
237
+ | **Live Diagnostics (Red Squiggles)** | Instant syntax error reporting as you type with precise line & column markers. |
238
+ | **Smart Autocomplete** | Keywords, built-in functions, array methods (`.map`, `.filter`), stdlib modules (`math.`, `os.`), and user symbols. |
239
+ | **Hover Tooltips** | Full signatures, markdown documentation, and parameter details when hovering code. |
240
+ | **Go to Definition (`F12`)** | Jump directly to where functions or variables are declared. |
241
+ | **Document Outline / Symbols** | Breadcrumbs and outline hierarchy showing all functions and variables. |
242
+
243
+ ---
244
+
245
+ ### 1. VS Code & Antigravity IDE
246
+ Run the automated installer:
247
+ ```bash
248
+ py install_extension.py
249
+ ```
250
+ Then reload window (`Ctrl + Shift + P` -> `Developer: Reload Window`). The extension automatically starts the LSP server!
251
+
252
+ ---
253
+
254
+ ### 2. Neovim (nvim-lspconfig)
255
+ Add to your `init.lua`:
256
+ ```lua
257
+ local lspconfig = require('lspconfig')
258
+ local configs = require('lspconfig.configs')
259
+
260
+ if not configs.samlang then
261
+ configs.samlang = {
262
+ default_config = {
263
+ cmd = { "samlang", "--lsp" }, -- or {"py", "-3", "-m", "samlang.lsp"}
264
+ filetypes = { "samlang" },
265
+ root_dir = lspconfig.util.root_pattern(".git", "."),
266
+ settings = {},
267
+ },
268
+ }
269
+ end
270
+ lspconfig.samlang.setup{}
271
+ ```
272
+
273
+ ---
274
+
275
+ ### 3. Sublime Text (LSP Package)
276
+ In Sublime Text, open `Preferences > Package Settings > LSP > Settings` and add:
277
+ ```json
278
+ {
279
+ "clients": {
280
+ "samlang": {
281
+ "enabled": true,
282
+ "command": ["samlang", "--lsp"],
283
+ "selector": "source.samlang"
284
+ }
285
+ }
286
+ }
287
+ ```
288
+
289
+ ---
290
+
291
+ ### 4. Helix / Zed Editor
292
+ In Helix (`languages.toml`):
293
+ ```toml
294
+ [[language]]
295
+ name = "samlang"
296
+ scope = "source.samlang"
297
+ file-types = ["sl"]
298
+ roots = [".git"]
299
+ language-servers = [ "samlang-lsp" ]
300
+
301
+ [language-server.samlang-lsp]
302
+ command = "samlang"
303
+ args = ["--lsp"]
304
+ ```
305
+
306
+
@@ -0,0 +1,277 @@
1
+ # 🚀 SamLang (`.sl`)
2
+
3
+ A modern, high-performance, general-purpose programming language.
4
+ **Author:** Samrane Ahmed
5
+
6
+ ---
7
+
8
+ ## 📁 Project Architecture
9
+
10
+ ```
11
+ nova/
12
+ ├── src/
13
+ │ └── samlang/
14
+ │ ├── __init__.py # Package metadata
15
+ │ ├── tokens.py # Token types, Position tracking
16
+ │ ├── errors.py # Error diagnostics with visual arrows (^)
17
+ │ ├── ast_nodes.py # AST Node definitions (Number, BinOp, Assign, etc.)
18
+ │ ├── lexer.py # Lexical analyzer / Tokenizer
19
+ │ ├── parser.py # Recursive descent parser (BODMAS/Precedence)
20
+ │ ├── environment.py # Scopes and symbol table bindings
21
+ │ ├── interpreter.py # AST Tree-Walk evaluator
22
+ │ ├── runner.py # Execution pipeline
23
+ │ └── cli.py # CLI runner and interactive REPL
24
+ ├── examples/
25
+ │ └── hello.sl # Example SamLang script
26
+ ├── tests/
27
+ │ └── test_samlang.py # Automated test suite
28
+ └── main.py # Root CLI entry point
29
+ ```
30
+
31
+ ---
32
+
33
+ ## ⚡ Quick Start
34
+
35
+ ### 1. Run a SamLang Script (`.sl`)
36
+ ```bash
37
+ py main.py examples/hello.sl
38
+ ```
39
+
40
+ ### 2. Launch the Interactive REPL
41
+ ```bash
42
+ py main.py
43
+ ```
44
+ ```text
45
+ ==================================================
46
+ SamLang 0.1.0 Interactive REPL
47
+ Created by Samrane Ahmed
48
+ Type 'exit' or 'quit' to exit.
49
+ ==================================================
50
+ samlang> x = 4;
51
+ samlang> y = 10;
52
+ samlang> println "Sum is:", x + y;
53
+ Sum is: 14
54
+ samlang> echo "Testing: "; println "Done!"
55
+ Testing: Done!
56
+ ```
57
+
58
+ ### 3. Run Tests
59
+ ```bash
60
+ py tests/test_samlang.py
61
+ ```
62
+
63
+ ---
64
+
65
+ ## 🎯 Language Features
66
+
67
+ ### Phase 1: Foundation & Arithmetic
68
+ - [x] **Dynamic Variable Declaration:** Direct assignment `x = 4;` (no mandatory `let` required)
69
+ - [x] **Semicolons Support:** Semicolon `;` support for clean statement termination & multiple statements on one line
70
+ - [x] **Output Statements:**
71
+ - `println expr1, expr2...` (prints with newline)
72
+ - `print expr1, expr2...` (prints inline without newline)
73
+ - `echo expr1, expr2...` (alias to `print`, inline output)
74
+ - [x] **Numbers & Types:** Integers (`10`, `-5`), Floats (`3.14`), Strings with escapes
75
+ - [x] **Arithmetic:** `+`, `-`, `*`, `/`, `%`, `^` (power) with mathematical precedence
76
+ - [x] **Parentheses:** For grouping expressions `(a + b) * c`
77
+ - [x] **Comments:** Single-line comments starting with `#`
78
+ - [x] **Precision Diagnostics:** Line & column tracking with visual pointer arrows (`^`)
79
+
80
+ ### Phase 2: Environment, Types & Scoping
81
+ - [x] **Booleans & Null:** `true`, `false`, and `null` literals
82
+ - [x] **Comparison Operators:** `==`, `!=`, `<`, `>`, `<=`, `>=`
83
+ - [x] **Logical Operators:** `and`, `or`, `not` as well as C-style `&&`, `||`, `!`
84
+ - [x] **Lexical Scoping & Code Blocks:** `{ ... }` blocks with local scope isolation and outer variable mutability
85
+
86
+ ### Phase 3: Functions, Dual Blocks & Control Flow
87
+ - [x] **Functions (`func`):** Definition with `func name(a, b) ...`, parameter binding, call stack
88
+ - [x] **Return Statement (`return`):** Early returns, returning values or null
89
+ - [x] **Dual Block Styles:**
90
+ - **C/JS Style:** Using braces `{ statement1; statement2; }`
91
+ - **Python Style:** Using colon and indentation `: \n statement1 \n statement2`
92
+ - [x] **Conditional Branches:** `if`, `elif`, `else` (supports both brace and colon syntax)
93
+ - [x] **Loops (`while`):** While loops (supports both brace and colon syntax)
94
+ - [x] **Recursion:** Full recursive calls and closures supported
95
+
96
+ ### Phase 4: Advanced Loops & Unique Superpowers
97
+ - [x] **C-Style For Loop:** `for (init; cond; step) { ... }` with optional components (`for (;;)`)
98
+ - [x] **Python-Style For Loop:** `for i in range(stop)` and `for i in range(start, stop, step)`
99
+ - [x] **Do-While Loop:** `do { ... } while (cond);` (executes at least once)
100
+ - [x] **Real Constants (`const`):** Immutable constants with strict runtime reassign prevention
101
+ - [x] **Increment & Decrement (`++` / `--`):** Prefix and postfix increment/decrement (`x++`, `++x`, `x--`, `--x`)
102
+ - [x] **Compound Assignments:** `+=`, `-=`, `*=`, `/=`, `%=` (numbers and string operations)
103
+ - [x] **Repeat Loop:** `repeat count { ... }` or `repeat count: ...` for clean, simple repetitions
104
+
105
+ ### Phase 5: Data Structures, String Interpolation & Built-ins
106
+ - [x] **Arrays / Lists:** `[1, 2, "three"]`, indexing `arr[0]`, negative indexing `arr[-1]`, mutation `arr[0] = 99;`
107
+ - [x] **Array Looping:**
108
+ - Parcours par élément: `for x in list { ... }`
109
+ - Parcours par index et élément: `for i, x in list { ... }`
110
+ - Parcours par index pur: `for i in range(len(list)) { ... }`
111
+ - [x] **Dictionaries / HashMaps:** `{ name: "Ahmed", age: 22 }`, dot access `d.name`, bracket access `d["age"]`
112
+ - [x] **Dictionary Iteration:** `for key, val in dict { ... }`
113
+ - [x] **Ternary Operator:** `condition ? val1 : val2` (supports chaining)
114
+ - [x] **Direct String Interpolation:** `"Salam ${name}, next year: ${year + 1}!"` with nested expressions
115
+ - [x] **String Built-in Functions & Methods:**
116
+ - `clean(s)` / `s.clean()` (strip / trim)
117
+ - `upper(s)` / `s.upper()`
118
+ - `lower(s)` / `s.lower()`
119
+ - `mirror(s)` / `s.mirror()` (reverse)
120
+ - `begin(s, prefix)` / `s.begin(prefix)` (startswith)
121
+ - `end(s, suffix)` / `s.end(suffix)` (endswith)
122
+ - `find(s, sub)` / `s.find(sub)`
123
+ - `clip(s, start, end)` / `clp` / `s.clip(...)` (slice / substring)
124
+ - `divide(s, sep)` / `s.divide(sep)` (split)
125
+ - `merge(arr, sep)` / `arr.merge(sep)` / `sep.merge(arr)` (join)
126
+ - `swap(s, old, new)` / `s.swap(old, new)` (replace)
127
+ - [x] **SQL-Style Array Built-in Functions & Methods:**
128
+ - `order(arr)` / `arr.order()` (ORDER BY ASC)
129
+ - `order_desc(arr)` / `arr.order_desc()` (ORDER BY DESC)
130
+ - `distinct(arr)` / `arr.distinct()` (DISTINCT)
131
+ - `limit(arr, n)` / `arr.limit(n)` (LIMIT)
132
+ - `offset(arr, n)` / `arr.offset(n)` (OFFSET)
133
+ - `count(arr)` / `arr.count()` (COUNT(*))
134
+ - `sum(arr)` / `arr.sum()` (SUM)
135
+ - `avg(arr)` / `arr.avg()` (AVG)
136
+ - `min(arr)` / `max(arr)` (MIN / MAX)
137
+ - `union(arr1, arr2)` (UNION)
138
+ - `exists(arr, val)` / `arr.exists(val)` (EXISTS)
139
+ - `insert(arr, item, idx)` / `arr.insert(...)` (INSERT)
140
+ - `delete(arr, val)` / `arr.delete(val)` (DELETE)
141
+
142
+ ### Phase 6: Modules & Import System (Ready for `spm`)
143
+ - [x] **File Module Imports:**
144
+ - Namespace import: `import "./utils.sl";` -> `utils.func()`
145
+ - Alias import: `import "./utils.sl" as u;` -> `u.func()`
146
+ - Named items: `import { add, sub } from "./math.sl";`
147
+ - Renamed items: `import { add as plus } from "./math.sl";`
148
+ - Wildcard import: `import * from "./utils.sl";`
149
+ - Python-style import: `from "./utils.sl" import add, sub;`
150
+ - [x] **Standard Library Modules:**
151
+ - `import math;` (`pi`, `sqrt`, `floor`, `ceil`, `sin`, `cos`, `random`, `randint`, etc.)
152
+ - `import json;` (`stringify`, `parse`)
153
+ - `import time;` (`now`, `date`, `sleep`, `clock`)
154
+ - `import os;` (`cwd`, `exists`, `is_file`, `is_dir`, `read_file`, `write_file`, `env`)
155
+ - [x] **Modular Architecture:**
156
+ - Package lookup in `spm_modules/` (prepared for SamLang Package Manager `spm`)
157
+ - Cyclic import protection & module caching
158
+ - Private symbol convention (`_private` ignored in wildcard imports)
159
+
160
+ ### Phase 7: Advanced Syntax & Modern Functional Superpowers
161
+ - [x] **Loop Controls (`break` & `continue`):** Works in `while`, `for (;;) `, `for-in`, `repeat`.
162
+ - [x] **Exception Handling (`try / catch / finally`):**
163
+ - Safe error trapping: `try { ... } catch (err) { ... } finally { ... }`
164
+ - Dual syntax support (braces `{}` and colons `:`)
165
+ - Rich error object `err.message`, `err.details`, `err.type`.
166
+ - [x] **Arrow Functions / Lambdas (`=>`):**
167
+ - Multi-arg: `(x, y) => x + y`
168
+ - Single-arg shorthand: `x => x * 2`
169
+ - Block body: `(x) => { return x + 1; }`
170
+ - [x] **Functional Array Methods:**
171
+ - `arr.map(fn)`: Map transformation over elements
172
+ - `arr.filter(fn)`: Filter elements matching predicate
173
+ - `arr.reduce(fn, initial)`: Fold/reduce elements to single value
174
+ - `arr.for_each(fn)`: Execute action per element
175
+
176
+ ### Phase 8: Object-Oriented Programming (POO / OOP)
177
+ - [x] **Classes (`class`):** Full class declarations supporting both `{}` and `:` blocks.
178
+ - [x] **C#-Style Auto-Properties:**
179
+ - Read/Write: `let Name { get; set; }`
180
+ - Default values: `let Age { get; set; } = 18`
181
+ - Read-only: `let Id { get; } = "XYZ"` (reassignment raises runtime error)
182
+ - [x] **Constructors:**
183
+ - C# style constructors named after the class `Person(name, age) { ... }` or `func init(...)`.
184
+ - Chaining / parent constructor delegation via `base(...)`.
185
+ - [x] **Inheritance (`:`):** Single class inheritance: `class Student : Person`.
186
+ - [x] **Explicit Polymorphism:**
187
+ - Parent methods marked `func virtuel display()`
188
+ - Child methods marked `func override display()`
189
+ - Enforced runtime safety: derived classes cannot override non-virtual methods, preventing accidental method hiding.
190
+ - [x] **Parent Delegation (`base`):** `base(...)` for constructor delegation and `base.method()` for parent methods.
191
+ - [x] **Self-Reference:** Both `this` (C# style) and `self` (Python style) are fully supported.
192
+ - [x] **Flexible Instantiation Styles:**
193
+ - Untyped dynamic assignment: `s = new Student("Ahmed", 22)`
194
+ - Standard declaration: `let s = new Student("Ahmed", 22)`
195
+ - Polymorphic typed declaration: `Person s = new Student("Ahmed", 22)` (verifies subclass relationship at runtime)
196
+ - Exact typed declaration: `Student s = new Student("Ahmed", 22)`
197
+ - Instantiation without `new`: `Student("Ahmed", 22)`
198
+ - [x] **Static Methods (`static`):** `static func add(a, b)` called directly on the class (`MathHelper.add(a, b)`).
199
+
200
+ ---
201
+
202
+ ## 🌐 Universal IDE Support & SamLang LSP (`samlang-lsp`)
203
+
204
+ SamLang implements the standard **Language Server Protocol (LSP 3.17)**, giving any modern editor first-class IDE capabilities:
205
+
206
+ | Feature | Description |
207
+ | :--- | :--- |
208
+ | **Live Diagnostics (Red Squiggles)** | Instant syntax error reporting as you type with precise line & column markers. |
209
+ | **Smart Autocomplete** | Keywords, built-in functions, array methods (`.map`, `.filter`), stdlib modules (`math.`, `os.`), and user symbols. |
210
+ | **Hover Tooltips** | Full signatures, markdown documentation, and parameter details when hovering code. |
211
+ | **Go to Definition (`F12`)** | Jump directly to where functions or variables are declared. |
212
+ | **Document Outline / Symbols** | Breadcrumbs and outline hierarchy showing all functions and variables. |
213
+
214
+ ---
215
+
216
+ ### 1. VS Code & Antigravity IDE
217
+ Run the automated installer:
218
+ ```bash
219
+ py install_extension.py
220
+ ```
221
+ Then reload window (`Ctrl + Shift + P` -> `Developer: Reload Window`). The extension automatically starts the LSP server!
222
+
223
+ ---
224
+
225
+ ### 2. Neovim (nvim-lspconfig)
226
+ Add to your `init.lua`:
227
+ ```lua
228
+ local lspconfig = require('lspconfig')
229
+ local configs = require('lspconfig.configs')
230
+
231
+ if not configs.samlang then
232
+ configs.samlang = {
233
+ default_config = {
234
+ cmd = { "samlang", "--lsp" }, -- or {"py", "-3", "-m", "samlang.lsp"}
235
+ filetypes = { "samlang" },
236
+ root_dir = lspconfig.util.root_pattern(".git", "."),
237
+ settings = {},
238
+ },
239
+ }
240
+ end
241
+ lspconfig.samlang.setup{}
242
+ ```
243
+
244
+ ---
245
+
246
+ ### 3. Sublime Text (LSP Package)
247
+ In Sublime Text, open `Preferences > Package Settings > LSP > Settings` and add:
248
+ ```json
249
+ {
250
+ "clients": {
251
+ "samlang": {
252
+ "enabled": true,
253
+ "command": ["samlang", "--lsp"],
254
+ "selector": "source.samlang"
255
+ }
256
+ }
257
+ }
258
+ ```
259
+
260
+ ---
261
+
262
+ ### 4. Helix / Zed Editor
263
+ In Helix (`languages.toml`):
264
+ ```toml
265
+ [[language]]
266
+ name = "samlang"
267
+ scope = "source.samlang"
268
+ file-types = ["sl"]
269
+ roots = [".git"]
270
+ language-servers = [ "samlang-lsp" ]
271
+
272
+ [language-server.samlang-lsp]
273
+ command = "samlang"
274
+ args = ["--lsp"]
275
+ ```
276
+
277
+