IncludeCPP 3.7.1__py3-none-any.whl → 3.7.9__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 +172 -11
- includecpp/core/cssl/CSSL_DOCUMENTATION.md +27 -8
- includecpp/core/cssl/cssl_parser.py +174 -11
- includecpp/core/cssl/cssl_runtime.py +183 -15
- includecpp/core/cssl_bridge.py +477 -48
- includecpp/vscode/cssl/language-configuration.json +1 -4
- includecpp/vscode/cssl/syntaxes/cssl.tmLanguage.json +183 -22
- {includecpp-3.7.1.dist-info → includecpp-3.7.9.dist-info}/METADATA +1 -1
- {includecpp-3.7.1.dist-info → includecpp-3.7.9.dist-info}/RECORD +14 -14
- {includecpp-3.7.1.dist-info → includecpp-3.7.9.dist-info}/WHEEL +0 -0
- {includecpp-3.7.1.dist-info → includecpp-3.7.9.dist-info}/entry_points.txt +0 -0
- {includecpp-3.7.1.dist-info → includecpp-3.7.9.dist-info}/licenses/LICENSE +0 -0
- {includecpp-3.7.1.dist-info → includecpp-3.7.9.dist-info}/top_level.txt +0 -0
includecpp/__init__.py
CHANGED
includecpp/cli/commands.py
CHANGED
|
@@ -1193,7 +1193,7 @@ def build(ctx, clean, keep, verbose, no_incremental, incremental, parallel, jobs
|
|
|
1193
1193
|
@cli.command()
|
|
1194
1194
|
@click.argument('module_name')
|
|
1195
1195
|
def add(module_name):
|
|
1196
|
-
"""Create a new module template."""
|
|
1196
|
+
"""Create a new module template with sample C++ code."""
|
|
1197
1197
|
plugins_dir = Path("plugins")
|
|
1198
1198
|
if not plugins_dir.exists():
|
|
1199
1199
|
click.echo("Error: plugins/ directory not found")
|
|
@@ -1204,6 +1204,7 @@ def add(module_name):
|
|
|
1204
1204
|
click.echo(f"Module {module_name} already exists")
|
|
1205
1205
|
return
|
|
1206
1206
|
|
|
1207
|
+
# Create .cp config file
|
|
1207
1208
|
template = f"""SOURCE(include/{module_name}.cpp) {module_name}
|
|
1208
1209
|
|
|
1209
1210
|
PUBLIC(
|
|
@@ -1215,7 +1216,41 @@ PUBLIC(
|
|
|
1215
1216
|
f.write(template)
|
|
1216
1217
|
|
|
1217
1218
|
click.echo(f"Created {cp_file}")
|
|
1218
|
-
|
|
1219
|
+
|
|
1220
|
+
# Create include/ directory if it doesn't exist
|
|
1221
|
+
include_dir = Path("include")
|
|
1222
|
+
include_dir.mkdir(exist_ok=True)
|
|
1223
|
+
|
|
1224
|
+
# Create .cpp file with sample code
|
|
1225
|
+
cpp_file = include_dir / f"{module_name}.cpp"
|
|
1226
|
+
if not cpp_file.exists():
|
|
1227
|
+
cpp_template = f"""#include <string>
|
|
1228
|
+
#include <vector>
|
|
1229
|
+
|
|
1230
|
+
namespace includecpp {{
|
|
1231
|
+
|
|
1232
|
+
// Example function - returns a greeting
|
|
1233
|
+
std::string example_function(const std::string& name) {{
|
|
1234
|
+
return "Hello, " + name + "!";
|
|
1235
|
+
}}
|
|
1236
|
+
|
|
1237
|
+
// Add more functions here...
|
|
1238
|
+
// int add(int a, int b) {{ return a + b; }}
|
|
1239
|
+
// std::vector<int> range(int n) {{ ... }}
|
|
1240
|
+
|
|
1241
|
+
}} // namespace includecpp
|
|
1242
|
+
"""
|
|
1243
|
+
with open(cpp_file, 'w', encoding='utf-8') as f:
|
|
1244
|
+
f.write(cpp_template)
|
|
1245
|
+
|
|
1246
|
+
click.echo(f"Created {cpp_file}")
|
|
1247
|
+
else:
|
|
1248
|
+
click.echo(f"Note: {cpp_file} already exists, skipped")
|
|
1249
|
+
|
|
1250
|
+
click.echo(f"\nNext steps:")
|
|
1251
|
+
click.echo(f" 1. Edit include/{module_name}.cpp to add your functions")
|
|
1252
|
+
click.echo(f" 2. Update plugins/{module_name}.cp to expose functions")
|
|
1253
|
+
click.echo(f" 3. Run: includecpp rebuild")
|
|
1219
1254
|
|
|
1220
1255
|
@cli.command('list')
|
|
1221
1256
|
def list_modules():
|
|
@@ -7480,13 +7515,12 @@ def cssl_exec(path, code):
|
|
|
7480
7515
|
# Execute
|
|
7481
7516
|
click.secho("--- Output ---", fg='green')
|
|
7482
7517
|
try:
|
|
7483
|
-
result = cssl_lang.
|
|
7518
|
+
result = cssl_lang.run(source)
|
|
7484
7519
|
|
|
7485
7520
|
# Output is already printed to stdout during execution via runtime.output()
|
|
7486
|
-
#
|
|
7487
|
-
|
|
7488
|
-
|
|
7489
|
-
click.echo(f"Result: {result}")
|
|
7521
|
+
# Don't print "Result:" automatically - users should use printl() for output
|
|
7522
|
+
# This prevents unwanted output for function calls like: Function();
|
|
7523
|
+
pass
|
|
7490
7524
|
|
|
7491
7525
|
except Exception as e:
|
|
7492
7526
|
click.secho(f"CSSL Error: {e}", fg='red')
|
|
@@ -7535,10 +7569,29 @@ def cssl_makemodule(path, output):
|
|
|
7535
7569
|
|
|
7536
7570
|
|
|
7537
7571
|
@cssl.command(name='doc')
|
|
7538
|
-
|
|
7539
|
-
|
|
7572
|
+
@click.argument('search', required=False, default=None)
|
|
7573
|
+
@click.option('--list', '-l', 'list_sections', is_flag=True, help='List all documentation sections')
|
|
7574
|
+
def cssl_doc(search, list_sections):
|
|
7575
|
+
"""Show CSSL documentation.
|
|
7576
|
+
|
|
7577
|
+
\b
|
|
7578
|
+
Usage:
|
|
7579
|
+
includecpp cssl doc # Show full documentation
|
|
7580
|
+
includecpp cssl doc "open" # Search for 'open' keyword
|
|
7581
|
+
includecpp cssl doc "$" # Search for shared variable syntax
|
|
7582
|
+
includecpp cssl doc "define" # Search for define keyword
|
|
7583
|
+
includecpp cssl doc --list # List all sections
|
|
7584
|
+
|
|
7585
|
+
\b
|
|
7586
|
+
Examples:
|
|
7587
|
+
includecpp cssl doc "class" # Show OOP/class documentation
|
|
7588
|
+
includecpp cssl doc "json::" # Show JSON functions
|
|
7589
|
+
includecpp cssl doc "this->" # Show this-> keyword usage
|
|
7590
|
+
includecpp cssl doc "map" # Show Map container docs
|
|
7591
|
+
"""
|
|
7540
7592
|
from pathlib import Path as PathLib
|
|
7541
7593
|
import os
|
|
7594
|
+
import re
|
|
7542
7595
|
|
|
7543
7596
|
# Find the documentation file in the cssl package directory
|
|
7544
7597
|
cssl_dir = PathLib(__file__).parent.parent / 'core' / 'cssl'
|
|
@@ -7558,8 +7611,116 @@ def cssl_doc():
|
|
|
7558
7611
|
|
|
7559
7612
|
if doc_path.exists():
|
|
7560
7613
|
content = doc_path.read_text(encoding='utf-8')
|
|
7561
|
-
|
|
7562
|
-
|
|
7614
|
+
|
|
7615
|
+
# List sections mode
|
|
7616
|
+
if list_sections:
|
|
7617
|
+
click.secho("CSSL Documentation Sections", fg='cyan', bold=True)
|
|
7618
|
+
click.secho("=" * 40, fg='cyan')
|
|
7619
|
+
sections = re.findall(r'^##\s+(.+)$', content, re.MULTILINE)
|
|
7620
|
+
for i, section in enumerate(sections, 1):
|
|
7621
|
+
click.echo(f" {i:2d}. {section}")
|
|
7622
|
+
click.echo()
|
|
7623
|
+
click.echo("Use: includecpp cssl doc \"<keyword>\" to search")
|
|
7624
|
+
return
|
|
7625
|
+
|
|
7626
|
+
# Search mode
|
|
7627
|
+
if search:
|
|
7628
|
+
click.secho(f"Searching for: '{search}'", fg='cyan', bold=True)
|
|
7629
|
+
click.secho("=" * 50, fg='cyan')
|
|
7630
|
+
click.echo()
|
|
7631
|
+
|
|
7632
|
+
# Split into subsections (### headers) for focused results
|
|
7633
|
+
subsections = re.split(r'(?=^### )', content, flags=re.MULTILINE)
|
|
7634
|
+
|
|
7635
|
+
# Also split into main sections (## headers)
|
|
7636
|
+
main_sections = re.split(r'(?=^## )', content, flags=re.MULTILINE)
|
|
7637
|
+
|
|
7638
|
+
# Find matching subsections (### level) - most focused
|
|
7639
|
+
matching_subsections = []
|
|
7640
|
+
for subsection in subsections:
|
|
7641
|
+
if search.lower() in subsection.lower():
|
|
7642
|
+
# Extract title
|
|
7643
|
+
title_match = re.match(r'^###\s+(.+)$', subsection, re.MULTILINE)
|
|
7644
|
+
if title_match:
|
|
7645
|
+
# Trim subsection to just the content until next ### or ##
|
|
7646
|
+
lines = subsection.split('\n')
|
|
7647
|
+
trimmed_lines = []
|
|
7648
|
+
for line in lines:
|
|
7649
|
+
if line.startswith('## ') and not line.startswith('### '):
|
|
7650
|
+
break
|
|
7651
|
+
trimmed_lines.append(line)
|
|
7652
|
+
matching_subsections.append((title_match.group(1), '\n'.join(trimmed_lines)))
|
|
7653
|
+
|
|
7654
|
+
if matching_subsections:
|
|
7655
|
+
click.secho(f"Found {len(matching_subsections)} matching subsection(s):", fg='green')
|
|
7656
|
+
click.echo()
|
|
7657
|
+
|
|
7658
|
+
# Show focused subsections (limit output)
|
|
7659
|
+
for title, sub_content in matching_subsections[:5]:
|
|
7660
|
+
click.secho(f"### {title}", fg='yellow', bold=True)
|
|
7661
|
+
# Highlight search term in content
|
|
7662
|
+
highlighted = re.sub(
|
|
7663
|
+
f'({re.escape(search)})',
|
|
7664
|
+
click.style(r'\1', fg='green', bold=True),
|
|
7665
|
+
sub_content,
|
|
7666
|
+
flags=re.IGNORECASE
|
|
7667
|
+
)
|
|
7668
|
+
# Limit lines per subsection
|
|
7669
|
+
lines = highlighted.split('\n')
|
|
7670
|
+
if len(lines) > 30:
|
|
7671
|
+
click.echo('\n'.join(lines[:30]))
|
|
7672
|
+
click.secho(f" ... ({len(lines) - 30} more lines)", fg='cyan')
|
|
7673
|
+
else:
|
|
7674
|
+
click.echo(highlighted)
|
|
7675
|
+
click.echo()
|
|
7676
|
+
click.secho("-" * 40, fg='cyan')
|
|
7677
|
+
click.echo()
|
|
7678
|
+
|
|
7679
|
+
if len(matching_subsections) > 5:
|
|
7680
|
+
click.secho(f"... and {len(matching_subsections) - 5} more subsections", fg='cyan')
|
|
7681
|
+
click.echo("Use --list to see all sections")
|
|
7682
|
+
else:
|
|
7683
|
+
# Fall back to main section search (## level)
|
|
7684
|
+
found_sections = []
|
|
7685
|
+
for section in main_sections:
|
|
7686
|
+
if search.lower() in section.lower():
|
|
7687
|
+
title_match = re.match(r'^##\s+(.+)$', section, re.MULTILINE)
|
|
7688
|
+
if title_match:
|
|
7689
|
+
found_sections.append((title_match.group(1), section))
|
|
7690
|
+
|
|
7691
|
+
if found_sections:
|
|
7692
|
+
click.secho(f"Found in {len(found_sections)} section(s):", fg='green')
|
|
7693
|
+
for title, _ in found_sections:
|
|
7694
|
+
click.echo(f" - {title}")
|
|
7695
|
+
click.echo()
|
|
7696
|
+
|
|
7697
|
+
# Show first matching section, trimmed
|
|
7698
|
+
title, section = found_sections[0]
|
|
7699
|
+
click.secho(f"## {title}", fg='yellow', bold=True)
|
|
7700
|
+
highlighted = re.sub(
|
|
7701
|
+
f'({re.escape(search)})',
|
|
7702
|
+
click.style(r'\1', fg='green', bold=True),
|
|
7703
|
+
section,
|
|
7704
|
+
flags=re.IGNORECASE
|
|
7705
|
+
)
|
|
7706
|
+
lines = highlighted.split('\n')
|
|
7707
|
+
if len(lines) > 40:
|
|
7708
|
+
click.echo('\n'.join(lines[:40]))
|
|
7709
|
+
click.secho(f"\n... ({len(lines) - 40} more lines in this section)", fg='cyan')
|
|
7710
|
+
else:
|
|
7711
|
+
click.echo(highlighted)
|
|
7712
|
+
else:
|
|
7713
|
+
click.secho(f"No matches found for '{search}'", fg='yellow')
|
|
7714
|
+
click.echo()
|
|
7715
|
+
click.echo("Try searching for:")
|
|
7716
|
+
click.echo(" - Keywords: class, function, define, open, global, shuffled")
|
|
7717
|
+
click.echo(" - Syntax: $, @, ::, this->, <<==, <==, #$")
|
|
7718
|
+
click.echo(" - Types: string, int, stack, vector, map, json")
|
|
7719
|
+
click.echo()
|
|
7720
|
+
click.echo("Or use: includecpp cssl doc --list")
|
|
7721
|
+
else:
|
|
7722
|
+
# Full documentation mode
|
|
7723
|
+
click.echo_via_pager(content)
|
|
7563
7724
|
else:
|
|
7564
7725
|
click.secho("Documentation file not found.", fg='yellow')
|
|
7565
7726
|
click.echo("Looking for: CSSL_DOCUMENTATION.md")
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# CSSL - C-Style Scripting Language
|
|
2
2
|
|
|
3
|
-
> Version 3.7.
|
|
3
|
+
> Version 3.7.6 | A modern scripting language with C++-style syntax and unique features like CodeInfusion and BruteInjection.
|
|
4
4
|
|
|
5
5
|
---
|
|
6
6
|
|
|
@@ -41,22 +41,25 @@
|
|
|
41
41
|
```python
|
|
42
42
|
from includecpp import CSSL
|
|
43
43
|
|
|
44
|
-
#
|
|
45
|
-
CSSL.
|
|
46
|
-
|
|
47
|
-
# Execute code
|
|
48
|
-
CSSL.exec("""
|
|
44
|
+
# Execute code (v3.7.6+: use run() instead of exec())
|
|
45
|
+
CSSL.run("""
|
|
49
46
|
printl("Hello CSSL!");
|
|
50
47
|
""")
|
|
51
48
|
|
|
52
49
|
# With parameters and return value
|
|
53
|
-
result = CSSL.
|
|
50
|
+
result = CSSL.run("""
|
|
54
51
|
string name = parameter.get(0);
|
|
55
52
|
printl("Hello " + name);
|
|
56
53
|
parameter.return(true);
|
|
57
54
|
""", "World")
|
|
58
55
|
|
|
59
56
|
print(result) # True
|
|
57
|
+
|
|
58
|
+
# Create typed scripts and modules (v3.7.6+)
|
|
59
|
+
main = CSSL.script("cssl", '''printl("Main");''')
|
|
60
|
+
payload = CSSL.script("cssl-pl", '''void helper() { printl("Helper!"); }''')
|
|
61
|
+
mod = CSSL.makemodule(main, payload, "mymod")
|
|
62
|
+
mod.helper() # Call function directly
|
|
60
63
|
```
|
|
61
64
|
|
|
62
65
|
### CLI Execution
|
|
@@ -701,12 +704,24 @@ super void forceRun() {
|
|
|
701
704
|
|
|
702
705
|
### shuffled
|
|
703
706
|
|
|
704
|
-
Allows multiple return values.
|
|
707
|
+
Allows multiple return values with tuple unpacking.
|
|
705
708
|
|
|
706
709
|
```cssl
|
|
707
710
|
shuffled string getNames() {
|
|
708
711
|
return "Alice", "Bob", "Charlie";
|
|
709
712
|
}
|
|
713
|
+
|
|
714
|
+
// Tuple unpacking (v3.7.6+)
|
|
715
|
+
a, b, c = getNames();
|
|
716
|
+
printl(a); // "Alice"
|
|
717
|
+
printl(b); // "Bob"
|
|
718
|
+
printl(c); // "Charlie"
|
|
719
|
+
|
|
720
|
+
// Works with any types
|
|
721
|
+
shuffled getValues() {
|
|
722
|
+
return "text", 42, true;
|
|
723
|
+
}
|
|
724
|
+
name, num, flag = getValues();
|
|
710
725
|
```
|
|
711
726
|
|
|
712
727
|
---
|
|
@@ -1143,6 +1158,10 @@ print(stats.total) # 50 - Persisted!
|
|
|
1143
1158
|
|
|
1144
1159
|
CodeInfusion enables modifying functions at runtime.
|
|
1145
1160
|
|
|
1161
|
+
> **Important**: Injection operators must be written **without spaces**:
|
|
1162
|
+
> - ✓ `func() <<==` / `func() +<<==` / `func() -<<==` (correct)
|
|
1163
|
+
> - ✗ `func() < <==` / `func() + <<==` / `func() - <<==` (wrong)
|
|
1164
|
+
|
|
1146
1165
|
### <<== (Replace)
|
|
1147
1166
|
|
|
1148
1167
|
Replaces function content.
|
|
@@ -108,6 +108,8 @@ class TokenType(Enum):
|
|
|
108
108
|
COMMENT = auto()
|
|
109
109
|
NEWLINE = auto()
|
|
110
110
|
EOF = auto()
|
|
111
|
+
# Super-functions for .cssl-pl payload files (v3.8.0)
|
|
112
|
+
SUPER_FUNC = auto() # #$run(), #$exec(), #$printl() - pre-execution hooks
|
|
111
113
|
|
|
112
114
|
|
|
113
115
|
KEYWORDS = {
|
|
@@ -212,9 +214,14 @@ class CSSLLexer:
|
|
|
212
214
|
|
|
213
215
|
char = self.source[self.pos]
|
|
214
216
|
|
|
215
|
-
# Comments
|
|
217
|
+
# Super-functions (#$) or Comments (# and // style)
|
|
216
218
|
if char == '#':
|
|
217
|
-
self.
|
|
219
|
+
if self._peek(1) == '$':
|
|
220
|
+
# Super-function: #$run(), #$exec(), #$printl()
|
|
221
|
+
self._read_super_function()
|
|
222
|
+
else:
|
|
223
|
+
# Regular comment
|
|
224
|
+
self._skip_comment()
|
|
218
225
|
elif char == '/' and self._peek(1) == '/':
|
|
219
226
|
# C-style // comment - NEW
|
|
220
227
|
self._skip_comment()
|
|
@@ -446,6 +453,31 @@ class CSSLLexer:
|
|
|
446
453
|
else:
|
|
447
454
|
self._add_token(TokenType.IDENTIFIER, value)
|
|
448
455
|
|
|
456
|
+
def _read_super_function(self):
|
|
457
|
+
"""Read #$<name>(...) super-function call for .cssl-pl payloads.
|
|
458
|
+
|
|
459
|
+
Super-functions are pre-execution hooks that run when a payload is loaded.
|
|
460
|
+
Valid super-functions: #$run(), #$exec(), #$printl()
|
|
461
|
+
|
|
462
|
+
Syntax:
|
|
463
|
+
#$run(initFunction); // Call a function at load time
|
|
464
|
+
#$exec(setup()); // Execute expression at load time
|
|
465
|
+
#$printl("Payload loaded"); // Print at load time
|
|
466
|
+
"""
|
|
467
|
+
start = self.pos
|
|
468
|
+
self._advance() # skip '#'
|
|
469
|
+
self._advance() # skip '$'
|
|
470
|
+
|
|
471
|
+
# Read the super-function name (run, exec, printl, etc.)
|
|
472
|
+
name_start = self.pos
|
|
473
|
+
while self.pos < len(self.source) and (self.source[self.pos].isalnum() or self.source[self.pos] == '_'):
|
|
474
|
+
self._advance()
|
|
475
|
+
func_name = self.source[name_start:self.pos]
|
|
476
|
+
|
|
477
|
+
# Store as #$<name> token value
|
|
478
|
+
value = f'#${func_name}'
|
|
479
|
+
self._add_token(TokenType.SUPER_FUNC, value)
|
|
480
|
+
|
|
449
481
|
def _read_self_ref(self):
|
|
450
482
|
"""Read s@<name> or s@<name>.<member>... self-reference"""
|
|
451
483
|
start = self.pos
|
|
@@ -1377,6 +1409,9 @@ class CSSLParser:
|
|
|
1377
1409
|
elif self._looks_like_function_declaration():
|
|
1378
1410
|
# Nested typed function (e.g., void Level2() { ... })
|
|
1379
1411
|
return self._parse_typed_function()
|
|
1412
|
+
elif self._check(TokenType.SUPER_FUNC):
|
|
1413
|
+
# Super-function for .cssl-pl payload files
|
|
1414
|
+
return self._parse_super_function()
|
|
1380
1415
|
elif (self._check(TokenType.IDENTIFIER) or self._check(TokenType.AT) or
|
|
1381
1416
|
self._check(TokenType.CAPTURED_REF) or self._check(TokenType.SHARED_REF) or
|
|
1382
1417
|
self._check(TokenType.GLOBAL_REF) or self._check(TokenType.SELF_REF) or
|
|
@@ -1594,23 +1629,42 @@ class CSSLParser:
|
|
|
1594
1629
|
return ASTNode('c_for_update', value={'var': var_name, 'op': 'none'})
|
|
1595
1630
|
|
|
1596
1631
|
def _parse_python_style_for(self) -> ASTNode:
|
|
1597
|
-
"""Parse Python-style for loop: for (i in range(...)) { }
|
|
1632
|
+
"""Parse Python-style for loop: for (i in range(...)) { } or for (item in collection) { }
|
|
1598
1633
|
|
|
1599
1634
|
Supports:
|
|
1600
1635
|
for (i in range(n)) { } - 0 to n-1
|
|
1601
1636
|
for (i in range(start, end)) { } - start to end-1
|
|
1602
1637
|
for (i in range(start, end, step)) { }
|
|
1638
|
+
for (item in collection) { } - iterate over list/vector
|
|
1639
|
+
for (item in @global_collection) { } - iterate over global
|
|
1603
1640
|
"""
|
|
1604
1641
|
var_name = self._advance().value
|
|
1605
1642
|
self._expect(TokenType.KEYWORD) # 'in'
|
|
1606
1643
|
|
|
1607
|
-
#
|
|
1644
|
+
# Check if this is range() or collection iteration
|
|
1645
|
+
is_range = False
|
|
1608
1646
|
if self._check(TokenType.KEYWORD) and self._peek().value == 'range':
|
|
1609
1647
|
self._advance() # consume 'range' keyword
|
|
1648
|
+
is_range = True
|
|
1610
1649
|
elif self._check(TokenType.IDENTIFIER) and self._peek().value == 'range':
|
|
1611
1650
|
self._advance() # consume 'range' identifier
|
|
1612
|
-
|
|
1613
|
-
|
|
1651
|
+
is_range = True
|
|
1652
|
+
|
|
1653
|
+
# If not range, parse as collection iteration
|
|
1654
|
+
if not is_range:
|
|
1655
|
+
iterable = self._parse_expression()
|
|
1656
|
+
self._expect(TokenType.PAREN_END)
|
|
1657
|
+
|
|
1658
|
+
node = ASTNode('foreach', value={'var': var_name, 'iterable': iterable}, children=[])
|
|
1659
|
+
self._expect(TokenType.BLOCK_START)
|
|
1660
|
+
|
|
1661
|
+
while not self._check(TokenType.BLOCK_END) and not self._is_at_end():
|
|
1662
|
+
stmt = self._parse_statement()
|
|
1663
|
+
if stmt:
|
|
1664
|
+
node.children.append(stmt)
|
|
1665
|
+
|
|
1666
|
+
self._expect(TokenType.BLOCK_END)
|
|
1667
|
+
return node
|
|
1614
1668
|
|
|
1615
1669
|
self._expect(TokenType.PAREN_START)
|
|
1616
1670
|
first_arg = self._parse_expression()
|
|
@@ -1722,11 +1776,56 @@ class CSSLParser:
|
|
|
1722
1776
|
return node
|
|
1723
1777
|
|
|
1724
1778
|
def _parse_return(self) -> ASTNode:
|
|
1725
|
-
|
|
1779
|
+
"""Parse return statement, supporting multiple values for shuffled functions.
|
|
1780
|
+
|
|
1781
|
+
Syntax:
|
|
1782
|
+
return; // Return None
|
|
1783
|
+
return value; // Return single value
|
|
1784
|
+
return a, b, c; // Return multiple values (for shuffled)
|
|
1785
|
+
"""
|
|
1786
|
+
values = []
|
|
1726
1787
|
if not self._check(TokenType.SEMICOLON) and not self._check(TokenType.BLOCK_END):
|
|
1727
|
-
|
|
1788
|
+
values.append(self._parse_expression())
|
|
1789
|
+
|
|
1790
|
+
# Check for comma-separated return values (shuffled return)
|
|
1791
|
+
while self._check(TokenType.COMMA):
|
|
1792
|
+
self._advance() # consume comma
|
|
1793
|
+
values.append(self._parse_expression())
|
|
1794
|
+
|
|
1795
|
+
self._match(TokenType.SEMICOLON)
|
|
1796
|
+
|
|
1797
|
+
if len(values) == 0:
|
|
1798
|
+
return ASTNode('return', value=None)
|
|
1799
|
+
elif len(values) == 1:
|
|
1800
|
+
return ASTNode('return', value=values[0])
|
|
1801
|
+
else:
|
|
1802
|
+
# Multiple return values - create tuple return
|
|
1803
|
+
return ASTNode('return', value={'multiple': True, 'values': values})
|
|
1804
|
+
|
|
1805
|
+
def _parse_super_function(self) -> ASTNode:
|
|
1806
|
+
"""Parse super-function for .cssl-pl payload files.
|
|
1807
|
+
|
|
1808
|
+
Syntax:
|
|
1809
|
+
#$run(initFunction); // Call function at load time
|
|
1810
|
+
#$exec(setup()); // Execute expression at load time
|
|
1811
|
+
#$printl("Payload loaded"); // Print at load time
|
|
1812
|
+
|
|
1813
|
+
These are pre-execution hooks that run when payload() loads the file.
|
|
1814
|
+
"""
|
|
1815
|
+
token = self._advance() # Get the SUPER_FUNC token
|
|
1816
|
+
super_name = token.value # e.g., "#$run", "#$exec", "#$printl"
|
|
1817
|
+
|
|
1818
|
+
# Parse the arguments
|
|
1819
|
+
self._expect(TokenType.PAREN_START)
|
|
1820
|
+
args = []
|
|
1821
|
+
if not self._check(TokenType.PAREN_END):
|
|
1822
|
+
args.append(self._parse_expression())
|
|
1823
|
+
while self._match(TokenType.COMMA):
|
|
1824
|
+
args.append(self._parse_expression())
|
|
1825
|
+
self._expect(TokenType.PAREN_END)
|
|
1728
1826
|
self._match(TokenType.SEMICOLON)
|
|
1729
|
-
|
|
1827
|
+
|
|
1828
|
+
return ASTNode('super_func', value={'name': super_name, 'args': args})
|
|
1730
1829
|
|
|
1731
1830
|
def _parse_try(self) -> ASTNode:
|
|
1732
1831
|
node = ASTNode('try', children=[])
|
|
@@ -1813,6 +1912,25 @@ class CSSLParser:
|
|
|
1813
1912
|
def _parse_expression_statement(self) -> Optional[ASTNode]:
|
|
1814
1913
|
expr = self._parse_expression()
|
|
1815
1914
|
|
|
1915
|
+
# === TUPLE UNPACKING: a, b, c = shuffled_func() ===
|
|
1916
|
+
# Check if we have comma-separated identifiers before =
|
|
1917
|
+
if expr.type == 'identifier' and self._check(TokenType.COMMA):
|
|
1918
|
+
targets = [expr]
|
|
1919
|
+
while self._match(TokenType.COMMA):
|
|
1920
|
+
next_expr = self._parse_expression()
|
|
1921
|
+
if next_expr.type == 'identifier':
|
|
1922
|
+
targets.append(next_expr)
|
|
1923
|
+
else:
|
|
1924
|
+
# Not a simple identifier list, this is something else
|
|
1925
|
+
# Restore and fall through to normal parsing
|
|
1926
|
+
break
|
|
1927
|
+
|
|
1928
|
+
# Check if followed by =
|
|
1929
|
+
if self._match(TokenType.EQUALS):
|
|
1930
|
+
value = self._parse_expression()
|
|
1931
|
+
self._match(TokenType.SEMICOLON)
|
|
1932
|
+
return ASTNode('tuple_assignment', value={'targets': targets, 'value': value})
|
|
1933
|
+
|
|
1816
1934
|
# === BASIC INJECTION: <== (replace target with source) ===
|
|
1817
1935
|
if self._match(TokenType.INJECT_LEFT):
|
|
1818
1936
|
# Check if this is a createcmd injection with a code block
|
|
@@ -2335,17 +2453,62 @@ class CSSLParser:
|
|
|
2335
2453
|
self._expect(TokenType.COMPARE_GT) # consume >
|
|
2336
2454
|
return ASTNode('instance_ref', value=instance_name)
|
|
2337
2455
|
|
|
2338
|
-
# Check for type generic instantiation: stack<string>, vector<int>, etc.
|
|
2456
|
+
# Check for type generic instantiation: stack<string>, vector<int>, map<string, int>, etc.
|
|
2339
2457
|
# This creates a new instance of the type with the specified element type
|
|
2340
2458
|
if name in TYPE_GENERICS and self._check(TokenType.COMPARE_LT):
|
|
2341
2459
|
self._advance() # consume <
|
|
2342
2460
|
element_type = 'dynamic'
|
|
2461
|
+
value_type = None # For map<K, V>
|
|
2462
|
+
|
|
2343
2463
|
if self._check(TokenType.KEYWORD) or self._check(TokenType.IDENTIFIER):
|
|
2344
2464
|
element_type = self._advance().value
|
|
2465
|
+
|
|
2466
|
+
# Check for second type parameter (map<K, V>)
|
|
2467
|
+
if name == 'map' and self._check(TokenType.COMMA):
|
|
2468
|
+
self._advance() # consume ,
|
|
2469
|
+
if self._check(TokenType.KEYWORD) or self._check(TokenType.IDENTIFIER):
|
|
2470
|
+
value_type = self._advance().value
|
|
2471
|
+
else:
|
|
2472
|
+
value_type = 'dynamic'
|
|
2473
|
+
|
|
2345
2474
|
self._expect(TokenType.COMPARE_GT) # consume >
|
|
2475
|
+
|
|
2476
|
+
# Check for inline initialization: map<K,V>{"key": "value", ...}
|
|
2477
|
+
init_values = None
|
|
2478
|
+
if self._check(TokenType.BLOCK_START):
|
|
2479
|
+
self._advance() # consume {
|
|
2480
|
+
init_values = {}
|
|
2481
|
+
|
|
2482
|
+
while not self._check(TokenType.BLOCK_END) and not self._is_at_end():
|
|
2483
|
+
# Parse key
|
|
2484
|
+
if self._check(TokenType.STRING):
|
|
2485
|
+
key = self._advance().value
|
|
2486
|
+
elif self._check(TokenType.IDENTIFIER):
|
|
2487
|
+
key = self._advance().value
|
|
2488
|
+
else:
|
|
2489
|
+
key = str(self._parse_expression().value) if hasattr(self._parse_expression(), 'value') else 'key'
|
|
2490
|
+
|
|
2491
|
+
# Expect : or =
|
|
2492
|
+
if self._check(TokenType.COLON):
|
|
2493
|
+
self._advance()
|
|
2494
|
+
elif self._check(TokenType.EQUALS):
|
|
2495
|
+
self._advance()
|
|
2496
|
+
|
|
2497
|
+
# Parse value
|
|
2498
|
+
value = self._parse_expression()
|
|
2499
|
+
init_values[key] = value
|
|
2500
|
+
|
|
2501
|
+
# Optional comma
|
|
2502
|
+
if self._check(TokenType.COMMA):
|
|
2503
|
+
self._advance()
|
|
2504
|
+
|
|
2505
|
+
self._expect(TokenType.BLOCK_END) # consume }
|
|
2506
|
+
|
|
2346
2507
|
return ASTNode('type_instantiation', value={
|
|
2347
2508
|
'type': name,
|
|
2348
|
-
'element_type': element_type
|
|
2509
|
+
'element_type': element_type,
|
|
2510
|
+
'value_type': value_type,
|
|
2511
|
+
'init_values': init_values
|
|
2349
2512
|
})
|
|
2350
2513
|
|
|
2351
2514
|
# Check for type-parameterized function call: OpenFind<string>(0)
|