IncludeCPP 3.4.21__py3-none-any.whl → 3.6.0__py3-none-any.whl
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.
- includecpp/__init__.py +1 -1
- includecpp/cli/commands.py +100 -6
- includecpp/core/cssl/CSSL_DOCUMENTATION.md +351 -20
- includecpp/core/cssl/cssl_builtins.py +228 -2
- includecpp/core/cssl/cssl_parser.py +214 -25
- includecpp/core/cssl/cssl_runtime.py +441 -40
- includecpp/core/cssl/cssl_types.py +339 -2
- includecpp/core/cssl_bridge.py +106 -5
- includecpp/core/cssl_bridge.pyi +177 -0
- includecpp/vscode/__init__.py +1 -0
- includecpp/vscode/cssl/__init__.py +1 -0
- includecpp/vscode/cssl/language-configuration.json +38 -0
- includecpp/vscode/cssl/package.json +30 -0
- includecpp/vscode/cssl/syntaxes/cssl.tmLanguage.json +221 -0
- {includecpp-3.4.21.dist-info → includecpp-3.6.0.dist-info}/METADATA +1 -1
- {includecpp-3.4.21.dist-info → includecpp-3.6.0.dist-info}/RECORD +20 -15
- {includecpp-3.4.21.dist-info → includecpp-3.6.0.dist-info}/WHEEL +0 -0
- {includecpp-3.4.21.dist-info → includecpp-3.6.0.dist-info}/entry_points.txt +0 -0
- {includecpp-3.4.21.dist-info → includecpp-3.6.0.dist-info}/licenses/LICENSE +0 -0
- {includecpp-3.4.21.dist-info → includecpp-3.6.0.dist-info}/top_level.txt +0 -0
includecpp/__init__.py
CHANGED
includecpp/cli/commands.py
CHANGED
|
@@ -7139,20 +7139,21 @@ def cppy_types():
|
|
|
7139
7139
|
# EXEC - Interactive Code Execution
|
|
7140
7140
|
# ============================================================================
|
|
7141
7141
|
|
|
7142
|
-
@cli.command()
|
|
7143
|
-
@click.argument('lang', type=click.Choice(['py', 'cpp', 'python', 'c++']))
|
|
7142
|
+
@cli.command(name='exec')
|
|
7143
|
+
@click.argument('lang', type=click.Choice(['py', 'cpp', 'python', 'c++', 'cssl']))
|
|
7144
7144
|
@click.argument('path', required=False, type=click.Path())
|
|
7145
7145
|
@click.option('--all', 'import_all', is_flag=True, help='Import all available modules')
|
|
7146
|
-
def
|
|
7146
|
+
def exec_repl(lang, path, import_all):
|
|
7147
7147
|
"""Execute code interactively for quick testing.
|
|
7148
7148
|
|
|
7149
|
-
Run Python
|
|
7149
|
+
Run Python, C++ or CSSL code snippets without creating files.
|
|
7150
7150
|
Perfect for testing your IncludeCPP modules quickly.
|
|
7151
7151
|
|
|
7152
7152
|
\b
|
|
7153
7153
|
Usage:
|
|
7154
7154
|
includecpp exec py # Interactive Python
|
|
7155
7155
|
includecpp exec cpp # Interactive C++
|
|
7156
|
+
includecpp exec cssl # Interactive CSSL
|
|
7156
7157
|
includecpp exec py mymodule # Auto-import mymodule
|
|
7157
7158
|
includecpp exec py plugins/x.cp # Auto-import from plugin
|
|
7158
7159
|
includecpp exec py --all # Import all modules
|
|
@@ -7178,7 +7179,8 @@ def exec(lang, path, import_all):
|
|
|
7178
7179
|
|
|
7179
7180
|
# Normalize language
|
|
7180
7181
|
is_python = lang in ('py', 'python')
|
|
7181
|
-
|
|
7182
|
+
is_cssl = lang == 'cssl'
|
|
7183
|
+
lang_name = 'Python' if is_python else ('CSSL' if is_cssl else 'C++')
|
|
7182
7184
|
|
|
7183
7185
|
# Build imports/includes
|
|
7184
7186
|
imports = []
|
|
@@ -7286,6 +7288,7 @@ def exec(lang, path, import_all):
|
|
|
7286
7288
|
|
|
7287
7289
|
if is_python:
|
|
7288
7290
|
# Execute Python code
|
|
7291
|
+
import builtins
|
|
7289
7292
|
full_code = '\n'.join(code_lines)
|
|
7290
7293
|
try:
|
|
7291
7294
|
# Use exec with captured output
|
|
@@ -7299,7 +7302,7 @@ def exec(lang, path, import_all):
|
|
|
7299
7302
|
exec_globals = {'__name__': '__main__'}
|
|
7300
7303
|
|
|
7301
7304
|
with redirect_stdout(stdout_capture), redirect_stderr(stderr_capture):
|
|
7302
|
-
exec(full_code, exec_globals)
|
|
7305
|
+
builtins.exec(full_code, exec_globals)
|
|
7303
7306
|
|
|
7304
7307
|
stdout_val = stdout_capture.getvalue()
|
|
7305
7308
|
stderr_val = stderr_capture.getvalue()
|
|
@@ -7315,6 +7318,29 @@ def exec(lang, path, import_all):
|
|
|
7315
7318
|
except Exception as e:
|
|
7316
7319
|
click.secho(f"Error: {e}", fg='red')
|
|
7317
7320
|
|
|
7321
|
+
elif is_cssl:
|
|
7322
|
+
# Execute CSSL code
|
|
7323
|
+
full_code = '\n'.join(lines)
|
|
7324
|
+
try:
|
|
7325
|
+
from ..core.cssl_bridge import CsslLang
|
|
7326
|
+
cssl_lang = CsslLang()
|
|
7327
|
+
result = cssl_lang.exec(full_code)
|
|
7328
|
+
|
|
7329
|
+
# Print any output from the execution
|
|
7330
|
+
output = cssl_lang.get_output()
|
|
7331
|
+
if output:
|
|
7332
|
+
for line in output:
|
|
7333
|
+
click.echo(line)
|
|
7334
|
+
|
|
7335
|
+
if result is not None:
|
|
7336
|
+
click.echo(result)
|
|
7337
|
+
|
|
7338
|
+
if not output and result is None:
|
|
7339
|
+
click.secho("(no output)", fg='bright_black')
|
|
7340
|
+
|
|
7341
|
+
except Exception as e:
|
|
7342
|
+
click.secho(f"Error: {e}", fg='red')
|
|
7343
|
+
|
|
7318
7344
|
else:
|
|
7319
7345
|
# Execute C++ code
|
|
7320
7346
|
# Build a complete C++ program
|
|
@@ -7631,6 +7657,74 @@ void error(string message) {{
|
|
|
7631
7657
|
click.echo(f" CSSL.exec('{cssl_file}')")
|
|
7632
7658
|
|
|
7633
7659
|
|
|
7660
|
+
@cssl.command(name='vscode')
|
|
7661
|
+
def cssl_vscode():
|
|
7662
|
+
"""Install VSCode extension for CSSL syntax highlighting."""
|
|
7663
|
+
from pathlib import Path as PathLib
|
|
7664
|
+
import shutil
|
|
7665
|
+
import os
|
|
7666
|
+
|
|
7667
|
+
# Find VSCode extensions directory
|
|
7668
|
+
if os.name == 'nt': # Windows
|
|
7669
|
+
vscode_ext_dir = PathLib(os.environ.get('USERPROFILE', '')) / '.vscode' / 'extensions'
|
|
7670
|
+
else: # Linux/Mac
|
|
7671
|
+
vscode_ext_dir = PathLib.home() / '.vscode' / 'extensions'
|
|
7672
|
+
|
|
7673
|
+
if not vscode_ext_dir.exists():
|
|
7674
|
+
# Try VSCode Insiders
|
|
7675
|
+
if os.name == 'nt':
|
|
7676
|
+
vscode_ext_dir = PathLib(os.environ.get('USERPROFILE', '')) / '.vscode-insiders' / 'extensions'
|
|
7677
|
+
else:
|
|
7678
|
+
vscode_ext_dir = PathLib.home() / '.vscode-insiders' / 'extensions'
|
|
7679
|
+
|
|
7680
|
+
if not vscode_ext_dir.exists():
|
|
7681
|
+
click.secho("VSCode extensions directory not found.", fg='red')
|
|
7682
|
+
click.echo("Make sure VSCode is installed.")
|
|
7683
|
+
click.echo()
|
|
7684
|
+
click.echo("Expected locations:")
|
|
7685
|
+
if os.name == 'nt':
|
|
7686
|
+
click.echo(f" %USERPROFILE%\\.vscode\\extensions")
|
|
7687
|
+
else:
|
|
7688
|
+
click.echo(f" ~/.vscode/extensions")
|
|
7689
|
+
return
|
|
7690
|
+
|
|
7691
|
+
# Find our bundled extension
|
|
7692
|
+
package_dir = PathLib(__file__).parent.parent
|
|
7693
|
+
source_ext_dir = package_dir / 'vscode' / 'cssl'
|
|
7694
|
+
|
|
7695
|
+
if not source_ext_dir.exists():
|
|
7696
|
+
click.secho("CSSL extension files not found in package.", fg='red')
|
|
7697
|
+
return
|
|
7698
|
+
|
|
7699
|
+
# Install extension
|
|
7700
|
+
target_dir = vscode_ext_dir / 'includecpp.cssl-1.0.0'
|
|
7701
|
+
|
|
7702
|
+
try:
|
|
7703
|
+
if target_dir.exists():
|
|
7704
|
+
shutil.rmtree(target_dir)
|
|
7705
|
+
|
|
7706
|
+
shutil.copytree(source_ext_dir, target_dir)
|
|
7707
|
+
|
|
7708
|
+
click.secho("CSSL VSCode extension installed!", fg='green', bold=True)
|
|
7709
|
+
click.echo()
|
|
7710
|
+
click.echo(f"Installed to: {target_dir}")
|
|
7711
|
+
click.echo()
|
|
7712
|
+
click.echo("Features:")
|
|
7713
|
+
click.echo(" - Syntax highlighting for .cssl, .cssl-pl, .cssl-mod files")
|
|
7714
|
+
click.echo(" - BruteInjection operators: <==, ==>, <<==, +<==, etc.")
|
|
7715
|
+
click.echo(" - Type highlighting: int, string, stack<T>, datastruct<T>")
|
|
7716
|
+
click.echo(" - Global references: @Name, r@Name, s@Name")
|
|
7717
|
+
click.echo(" - Shared objects: $Name")
|
|
7718
|
+
click.echo(" - Filter helpers: string::contains, json::key, etc.")
|
|
7719
|
+
click.echo()
|
|
7720
|
+
click.secho("Restart VSCode to activate the extension.", fg='yellow')
|
|
7721
|
+
|
|
7722
|
+
except PermissionError:
|
|
7723
|
+
click.secho("Permission denied. Try running as administrator.", fg='red')
|
|
7724
|
+
except Exception as e:
|
|
7725
|
+
click.secho(f"Installation failed: {e}", fg='red')
|
|
7726
|
+
|
|
7727
|
+
|
|
7634
7728
|
# Register hidden cssl command group
|
|
7635
7729
|
cli.add_command(cssl)
|
|
7636
7730
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# CSSL - C-Style Scripting Language
|
|
2
2
|
|
|
3
|
-
> Version 3.
|
|
3
|
+
> Version 3.6.0 | A modern scripting language with C++-style syntax and unique features like CodeInfusion and BruteInjection.
|
|
4
4
|
|
|
5
5
|
---
|
|
6
6
|
|
|
@@ -15,16 +15,19 @@
|
|
|
15
15
|
7. [Functions](#functions)
|
|
16
16
|
8. [Function Keywords](#function-keywords)
|
|
17
17
|
9. [String Methods](#string-methods)
|
|
18
|
-
10. [
|
|
19
|
-
11. [
|
|
20
|
-
12. [
|
|
21
|
-
13. [
|
|
22
|
-
14. [
|
|
23
|
-
15. [
|
|
24
|
-
16. [
|
|
25
|
-
17. [
|
|
26
|
-
18. [
|
|
27
|
-
19. [
|
|
18
|
+
10. [File I/O](#file-io)
|
|
19
|
+
11. [JSON Functions](#json-functions)
|
|
20
|
+
12. [Live Object Sharing](#live-object-sharing)
|
|
21
|
+
13. [CodeInfusion](#codeinfusion)
|
|
22
|
+
14. [Value Capture](#value-capture)
|
|
23
|
+
15. [BruteInjection](#bruteinjection)
|
|
24
|
+
16. [Filter Syntax](#filter-syntax)
|
|
25
|
+
17. [Module System](#module-system)
|
|
26
|
+
18. [Parameter Bridge](#parameter-bridge)
|
|
27
|
+
19. [Structures](#structures)
|
|
28
|
+
20. [Error Handling](#error-handling)
|
|
29
|
+
21. [CLI Commands](#cli-commands)
|
|
30
|
+
22. [Examples](#examples)
|
|
28
31
|
|
|
29
32
|
---
|
|
30
33
|
|
|
@@ -336,14 +339,26 @@ int number = 42;
|
|
|
336
339
|
// Declaration with 'global'
|
|
337
340
|
global myGlobal = "visible everywhere";
|
|
338
341
|
|
|
339
|
-
// Access with '@'
|
|
342
|
+
// Access with '@' prefix
|
|
340
343
|
printl(@myGlobal);
|
|
341
344
|
|
|
342
|
-
//
|
|
345
|
+
// Or access directly without '@' (since v3.5.9)
|
|
346
|
+
printl(myGlobal); // Works the same!
|
|
347
|
+
|
|
348
|
+
// Alternative: r@ syntax for declaration
|
|
343
349
|
r@anotherGlobal = "also global";
|
|
344
350
|
printl(@anotherGlobal);
|
|
351
|
+
printl(anotherGlobal); // Also works
|
|
345
352
|
```
|
|
346
353
|
|
|
354
|
+
### Lookup Order
|
|
355
|
+
|
|
356
|
+
When accessing a variable, CSSL checks in order:
|
|
357
|
+
1. Local scope
|
|
358
|
+
2. Global scope
|
|
359
|
+
3. Promoted globals
|
|
360
|
+
4. Built-in functions
|
|
361
|
+
|
|
347
362
|
### Usage in Functions
|
|
348
363
|
|
|
349
364
|
```cssl
|
|
@@ -539,6 +554,29 @@ string n = getName();
|
|
|
539
554
|
int sum = add(5, 3);
|
|
540
555
|
```
|
|
541
556
|
|
|
557
|
+
### Named Parameters
|
|
558
|
+
|
|
559
|
+
Functions can be called with named parameters for clarity.
|
|
560
|
+
|
|
561
|
+
```cssl
|
|
562
|
+
// Define function
|
|
563
|
+
int calculate(int base, int multiplier, int offset) {
|
|
564
|
+
return base * multiplier + offset;
|
|
565
|
+
}
|
|
566
|
+
|
|
567
|
+
// Call with positional arguments
|
|
568
|
+
int r1 = calculate(10, 5, 3); // 53
|
|
569
|
+
|
|
570
|
+
// Call with named parameters
|
|
571
|
+
int r2 = calculate(base=10, multiplier=5, offset=3); // 53
|
|
572
|
+
|
|
573
|
+
// Mix positional and named (positional must come first)
|
|
574
|
+
int r3 = calculate(10, multiplier=5, offset=3); // 53
|
|
575
|
+
|
|
576
|
+
// Named parameters can be in any order
|
|
577
|
+
int r4 = calculate(offset=3, base=10, multiplier=5); // 53
|
|
578
|
+
```
|
|
579
|
+
|
|
542
580
|
### Nested Functions
|
|
543
581
|
|
|
544
582
|
```cssl
|
|
@@ -798,6 +836,170 @@ string padded2 = num.padEnd(5, "."); // "42..."
|
|
|
798
836
|
|
|
799
837
|
---
|
|
800
838
|
|
|
839
|
+
## File I/O
|
|
840
|
+
|
|
841
|
+
CSSL provides built-in functions for file operations.
|
|
842
|
+
|
|
843
|
+
### Basic File Operations
|
|
844
|
+
|
|
845
|
+
```cssl
|
|
846
|
+
// Read entire file
|
|
847
|
+
string content = read("/path/to/file.txt");
|
|
848
|
+
printl(content);
|
|
849
|
+
|
|
850
|
+
// Read specific line (1-indexed)
|
|
851
|
+
string line5 = readline(5, "/path/to/file.txt");
|
|
852
|
+
printl(line5);
|
|
853
|
+
|
|
854
|
+
// Write to file (overwrites)
|
|
855
|
+
write("/path/to/file.txt", "Hello World");
|
|
856
|
+
|
|
857
|
+
// Write/replace specific line
|
|
858
|
+
writeline(3, "New line content", "/path/to/file.txt");
|
|
859
|
+
```
|
|
860
|
+
|
|
861
|
+
### Extended File Functions
|
|
862
|
+
|
|
863
|
+
```cssl
|
|
864
|
+
// Read all lines as array
|
|
865
|
+
stack<string> lines = readlines("/path/to/file.txt");
|
|
866
|
+
|
|
867
|
+
// Append to file
|
|
868
|
+
appendfile("/path/to/file.txt", "\nNew content");
|
|
869
|
+
|
|
870
|
+
// File checks
|
|
871
|
+
bool exists = pathexists("/path/to/file.txt");
|
|
872
|
+
bool isFile = isfile("/path/to/file.txt");
|
|
873
|
+
bool isDir = isdir("/path/to/folder");
|
|
874
|
+
|
|
875
|
+
// File size
|
|
876
|
+
int size = filesize("/path/to/file.txt");
|
|
877
|
+
|
|
878
|
+
// Directory listing
|
|
879
|
+
stack<string> files = listdir("/path/to/folder");
|
|
880
|
+
```
|
|
881
|
+
|
|
882
|
+
### Path Functions
|
|
883
|
+
|
|
884
|
+
```cssl
|
|
885
|
+
// Path manipulation
|
|
886
|
+
string base = basename("/path/to/file.txt"); // "file.txt"
|
|
887
|
+
string dir = dirname("/path/to/file.txt"); // "/path/to"
|
|
888
|
+
string full = joinpath("/path", "to", "file.txt"); // "/path/to/file.txt"
|
|
889
|
+
string abs = abspath("./file.txt"); // "/current/dir/file.txt"
|
|
890
|
+
```
|
|
891
|
+
|
|
892
|
+
### All File I/O Functions
|
|
893
|
+
|
|
894
|
+
| Function | Description |
|
|
895
|
+
|----------|-------------|
|
|
896
|
+
| `read(path)` | Read entire file content |
|
|
897
|
+
| `readline(line, path)` | Read specific line (1-indexed) |
|
|
898
|
+
| `write(path, content)` | Write content to file |
|
|
899
|
+
| `writeline(line, content, path)` | Write/replace specific line |
|
|
900
|
+
| `readfile(path)` | Read file (alias for read) |
|
|
901
|
+
| `writefile(path, content)` | Write file (alias for write) |
|
|
902
|
+
| `readlines(path)` | Read all lines as array |
|
|
903
|
+
| `appendfile(path, content)` | Append to file |
|
|
904
|
+
| `pathexists(path)` | Check if path exists |
|
|
905
|
+
| `isfile(path)` | Check if is file |
|
|
906
|
+
| `isdir(path)` | Check if is directory |
|
|
907
|
+
| `filesize(path)` | Get file size in bytes |
|
|
908
|
+
| `listdir(path)` | List directory contents |
|
|
909
|
+
| `makedirs(path)` | Create directories |
|
|
910
|
+
| `removefile(path)` | Delete file |
|
|
911
|
+
| `removedir(path)` | Delete empty directory |
|
|
912
|
+
| `copyfile(src, dst)` | Copy file |
|
|
913
|
+
| `movefile(src, dst)` | Move file |
|
|
914
|
+
|
|
915
|
+
---
|
|
916
|
+
|
|
917
|
+
## JSON Functions
|
|
918
|
+
|
|
919
|
+
CSSL provides namespace-style JSON functions with the `json::` prefix.
|
|
920
|
+
|
|
921
|
+
### Reading & Writing JSON Files
|
|
922
|
+
|
|
923
|
+
```cssl
|
|
924
|
+
// Read and parse JSON file
|
|
925
|
+
json data = json::read("/path/to/config.json");
|
|
926
|
+
printl(data.name);
|
|
927
|
+
|
|
928
|
+
// Write data to JSON file
|
|
929
|
+
json::write("/path/to/output.json", data);
|
|
930
|
+
```
|
|
931
|
+
|
|
932
|
+
### JSON Parsing & Stringifying
|
|
933
|
+
|
|
934
|
+
```cssl
|
|
935
|
+
// Parse JSON string
|
|
936
|
+
string jsonStr = '{"name": "Alice", "age": 30}';
|
|
937
|
+
json obj = json::parse(jsonStr);
|
|
938
|
+
|
|
939
|
+
// Convert to JSON string
|
|
940
|
+
string str = json::stringify(obj);
|
|
941
|
+
|
|
942
|
+
// Pretty print with indentation
|
|
943
|
+
string pretty = json::pretty(obj);
|
|
944
|
+
printl(pretty);
|
|
945
|
+
```
|
|
946
|
+
|
|
947
|
+
### JSON Path Operations
|
|
948
|
+
|
|
949
|
+
```cssl
|
|
950
|
+
json data = json::read("config.json");
|
|
951
|
+
|
|
952
|
+
// Get value by dot-path
|
|
953
|
+
string name = json::get(data, "user.name");
|
|
954
|
+
int age = json::get(data, "user.profile.age");
|
|
955
|
+
string city = json::get(data, "address.city", "Unknown"); // with default
|
|
956
|
+
|
|
957
|
+
// Set value by dot-path
|
|
958
|
+
data = json::set(data, "user.name", "Bob");
|
|
959
|
+
data = json::set(data, "settings.theme", "dark");
|
|
960
|
+
|
|
961
|
+
// Check if path exists
|
|
962
|
+
if (json::has(data, "user.email")) {
|
|
963
|
+
printl("Email exists");
|
|
964
|
+
}
|
|
965
|
+
```
|
|
966
|
+
|
|
967
|
+
### JSON Object Operations
|
|
968
|
+
|
|
969
|
+
```cssl
|
|
970
|
+
json obj = json::read("data.json");
|
|
971
|
+
|
|
972
|
+
// Get all keys
|
|
973
|
+
stack<string> keys = json::keys(obj);
|
|
974
|
+
foreach (key in keys) {
|
|
975
|
+
printl(key);
|
|
976
|
+
}
|
|
977
|
+
|
|
978
|
+
// Get all values
|
|
979
|
+
stack<dynamic> values = json::values(obj);
|
|
980
|
+
|
|
981
|
+
// Deep merge objects
|
|
982
|
+
json merged = json::merge(obj1, obj2, obj3);
|
|
983
|
+
```
|
|
984
|
+
|
|
985
|
+
### All JSON Functions
|
|
986
|
+
|
|
987
|
+
| Function | Description |
|
|
988
|
+
|----------|-------------|
|
|
989
|
+
| `json::read(path)` | Read and parse JSON file |
|
|
990
|
+
| `json::write(path, data)` | Write data to JSON file |
|
|
991
|
+
| `json::parse(str)` | Parse JSON string to object |
|
|
992
|
+
| `json::stringify(data)` | Convert to JSON string |
|
|
993
|
+
| `json::pretty(data)` | Pretty print JSON |
|
|
994
|
+
| `json::get(data, path, default)` | Get value by dot-path |
|
|
995
|
+
| `json::set(data, path, value)` | Set value by dot-path |
|
|
996
|
+
| `json::has(data, path)` | Check if path exists |
|
|
997
|
+
| `json::keys(data)` | Get all keys |
|
|
998
|
+
| `json::values(data)` | Get all values |
|
|
999
|
+
| `json::merge(obj1, obj2, ...)` | Deep merge objects |
|
|
1000
|
+
|
|
1001
|
+
---
|
|
1002
|
+
|
|
801
1003
|
## Live Object Sharing
|
|
802
1004
|
|
|
803
1005
|
Share Python objects with CSSL. Changes in CSSL reflect back to Python.
|
|
@@ -934,6 +1136,74 @@ exit(); // Executes injection
|
|
|
934
1136
|
|
|
935
1137
|
---
|
|
936
1138
|
|
|
1139
|
+
## Value Capture
|
|
1140
|
+
|
|
1141
|
+
The `%identifier` syntax captures values at registration time, useful for saving original functions before replacement.
|
|
1142
|
+
|
|
1143
|
+
### Capturing Variables
|
|
1144
|
+
|
|
1145
|
+
```cssl
|
|
1146
|
+
string version = "1.0.0";
|
|
1147
|
+
|
|
1148
|
+
// Capture current value
|
|
1149
|
+
v <== { %version; }
|
|
1150
|
+
printl(v); // "1.0.0"
|
|
1151
|
+
|
|
1152
|
+
// Even if version changes later, v keeps captured value
|
|
1153
|
+
version = "2.0.0";
|
|
1154
|
+
printl(v); // Still "1.0.0"
|
|
1155
|
+
```
|
|
1156
|
+
|
|
1157
|
+
### Capturing Functions
|
|
1158
|
+
|
|
1159
|
+
```cssl
|
|
1160
|
+
// Save original exit function before replacing
|
|
1161
|
+
originalExit <<== { %exit(); }
|
|
1162
|
+
|
|
1163
|
+
// Replace exit with custom behavior
|
|
1164
|
+
exit() <<== {
|
|
1165
|
+
printl("Custom cleanup...");
|
|
1166
|
+
originalExit(); // Call saved original
|
|
1167
|
+
}
|
|
1168
|
+
|
|
1169
|
+
exit();
|
|
1170
|
+
// Output:
|
|
1171
|
+
// Custom cleanup...
|
|
1172
|
+
// (original exit behavior)
|
|
1173
|
+
```
|
|
1174
|
+
|
|
1175
|
+
### Use Cases
|
|
1176
|
+
|
|
1177
|
+
```cssl
|
|
1178
|
+
// 1. Preserving original behavior
|
|
1179
|
+
void myFunc() {
|
|
1180
|
+
printl("Original");
|
|
1181
|
+
}
|
|
1182
|
+
|
|
1183
|
+
savedFunc <<== { %myFunc(); }
|
|
1184
|
+
|
|
1185
|
+
myFunc() <<== {
|
|
1186
|
+
printl("Modified");
|
|
1187
|
+
}
|
|
1188
|
+
|
|
1189
|
+
myFunc(); // "Modified"
|
|
1190
|
+
savedFunc(); // "Original"
|
|
1191
|
+
|
|
1192
|
+
// 2. Capturing configuration at startup
|
|
1193
|
+
global config = loadConfig();
|
|
1194
|
+
startupConfig <== { %config; }
|
|
1195
|
+
|
|
1196
|
+
// 3. Snapshot values for later comparison
|
|
1197
|
+
int counter = 0;
|
|
1198
|
+
initial <== { %counter; }
|
|
1199
|
+
// ... operations ...
|
|
1200
|
+
if (counter != initial) {
|
|
1201
|
+
printl("Counter changed!");
|
|
1202
|
+
}
|
|
1203
|
+
```
|
|
1204
|
+
|
|
1205
|
+
---
|
|
1206
|
+
|
|
937
1207
|
## BruteInjection
|
|
938
1208
|
|
|
939
1209
|
BruteInjection copies/moves data between containers.
|
|
@@ -981,6 +1251,26 @@ container ==> data;
|
|
|
981
1251
|
|
|
982
1252
|
---
|
|
983
1253
|
|
|
1254
|
+
### ==>- (Receive Minus)
|
|
1255
|
+
|
|
1256
|
+
Removes matching items from target.
|
|
1257
|
+
|
|
1258
|
+
```cssl
|
|
1259
|
+
stack<string> names;
|
|
1260
|
+
names.push("Alice");
|
|
1261
|
+
names.push("Bob");
|
|
1262
|
+
names.push("Alice");
|
|
1263
|
+
|
|
1264
|
+
stack<string> toRemove;
|
|
1265
|
+
toRemove.push("Alice");
|
|
1266
|
+
|
|
1267
|
+
// Remove all "Alice" from names
|
|
1268
|
+
names ==>- toRemove;
|
|
1269
|
+
printl(names); // ["Bob"]
|
|
1270
|
+
```
|
|
1271
|
+
|
|
1272
|
+
---
|
|
1273
|
+
|
|
984
1274
|
## Filter Syntax
|
|
985
1275
|
|
|
986
1276
|
Filters enable targeted data operations in BruteInjection.
|
|
@@ -1014,6 +1304,30 @@ result +<== [string::contains="App"] fruits; // Apple, Apricot
|
|
|
1014
1304
|
result +<== [string::length=5] fruits; // Apple
|
|
1015
1305
|
```
|
|
1016
1306
|
|
|
1307
|
+
### String Cutting Filters
|
|
1308
|
+
|
|
1309
|
+
Cut strings at specific positions or substrings.
|
|
1310
|
+
|
|
1311
|
+
```cssl
|
|
1312
|
+
string version = "1.0.0-beta";
|
|
1313
|
+
|
|
1314
|
+
// Cut at position (integer index)
|
|
1315
|
+
x = <==[string::cut=3] version;
|
|
1316
|
+
printl(x); // "1.0" (first 3 chars)
|
|
1317
|
+
|
|
1318
|
+
// Cut at substring position
|
|
1319
|
+
x = <==[string::cut="0-"] version;
|
|
1320
|
+
printl(x); // "1.0." (before "0-")
|
|
1321
|
+
|
|
1322
|
+
// Get everything after substring
|
|
1323
|
+
x = <==[string::cutAfter=".0."] version;
|
|
1324
|
+
printl(x); // "0-beta" (after ".0.")
|
|
1325
|
+
|
|
1326
|
+
// Cut after at position
|
|
1327
|
+
x = <==[string::cutAfter=4] version;
|
|
1328
|
+
printl(x); // ".0-beta" (after index 4)
|
|
1329
|
+
```
|
|
1330
|
+
|
|
1017
1331
|
### All Filters
|
|
1018
1332
|
|
|
1019
1333
|
| Filter | Description |
|
|
@@ -1022,6 +1336,10 @@ result +<== [string::length=5] fruits; // Apple
|
|
|
1022
1336
|
| `string::not=VALUE` | Everything except this value |
|
|
1023
1337
|
| `string::contains=VALUE` | Contains substring |
|
|
1024
1338
|
| `string::length=LENGTH` | Exact string length |
|
|
1339
|
+
| `string::cut=INDEX` | Cut at index (returns first N chars) |
|
|
1340
|
+
| `string::cut="SUBSTR"` | Cut at substring position |
|
|
1341
|
+
| `string::cutAfter=INDEX` | Get everything after index |
|
|
1342
|
+
| `string::cutAfter="SUBSTR"` | Get everything after substring |
|
|
1025
1343
|
| `integer::where=VALUE` | Exact int match |
|
|
1026
1344
|
| `json::key=KEYNAME` | Filter by JSON key |
|
|
1027
1345
|
| `json::value=VALUE` | Filter by JSON value |
|
|
@@ -1457,12 +1775,25 @@ print(result) # ["Missing colon after def"]
|
|
|
1457
1775
|
|
|
1458
1776
|
| Operator | Type | Description |
|
|
1459
1777
|
|----------|------|-------------|
|
|
1460
|
-
| `<<==` | CodeInfusion | Replace |
|
|
1461
|
-
| `+<<==` | CodeInfusion | Add |
|
|
1462
|
-
| `-<<==` | CodeInfusion | Remove |
|
|
1463
|
-
|
|
|
1464
|
-
|
|
|
1465
|
-
|
|
|
1778
|
+
| `<<==` | CodeInfusion | Replace function |
|
|
1779
|
+
| `+<<==` | CodeInfusion | Add code (before) |
|
|
1780
|
+
| `-<<==` | CodeInfusion | Remove code |
|
|
1781
|
+
| `<==` | ValueCapture | Capture/assign value |
|
|
1782
|
+
| `+<==` | BruteInjection | Copy data |
|
|
1783
|
+
| `-<==` | BruteInjection | Move data |
|
|
1784
|
+
| `==>` | BruteInjection | Replace data |
|
|
1785
|
+
| `==>-` | BruteInjection | Remove matching items |
|
|
1786
|
+
|
|
1787
|
+
### Special Syntax
|
|
1788
|
+
|
|
1789
|
+
| Syntax | Description |
|
|
1790
|
+
|--------|-------------|
|
|
1791
|
+
| `%identifier` | Capture value at registration time |
|
|
1792
|
+
| `json::func()` | Namespace function call |
|
|
1793
|
+
| `@name` | Access global variable |
|
|
1794
|
+
| `$name` | Access shared Python object |
|
|
1795
|
+
| `s@name` | Self-reference to struct |
|
|
1796
|
+
| `r@name` | Global variable declaration |
|
|
1466
1797
|
|
|
1467
1798
|
---
|
|
1468
1799
|
|
|
@@ -1479,4 +1810,4 @@ print(result) # ["Missing colon after def"]
|
|
|
1479
1810
|
|
|
1480
1811
|
---
|
|
1481
1812
|
|
|
1482
|
-
*CSSL v3.
|
|
1813
|
+
*CSSL v3.6.0 - Developed as part of IncludeCPP*
|