Skip to content

Commit 92b88e4

Browse files
committed
feat: improve unsafe template engine
1 parent 8021047 commit 92b88e4

38 files changed

Lines changed: 9713 additions & 3997 deletions

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,5 @@ coverage.txt
3939
*.tgz
4040

4141
node_modules/
42+
43+
preprocessor/

examples/preprocessor_demo.hl

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
fn main() {
2+
comptime {
3+
echo "Current line: $LINE"
4+
echo "Current file: $FILE"
5+
echo "Target platform: $TARGET"
6+
7+
if $TARGET == "vbs" {
8+
echo "VBScript target detected at line $LINE"
9+
} else if $TARGET == "ps" {
10+
echo "PowerShell target detected at line $LINE"
11+
}
12+
}
13+
14+
unsafe """
15+
echo "Hello from line {{ $LINE }}"
16+
echo "File: {{ $FILE }}"
17+
echo "Target: {{ $TARGET }}"
18+
19+
{{ if $TARGET == "vbs" }}
20+
echo "VBScript code here"
21+
{{ else }}
22+
echo "Other platform code here"
23+
{{ end }}
24+
"""
25+
26+
comptime {
27+
echo "Outer comptime at line $LINE"
28+
29+
unsafe """
30+
echo "Inner unsafe at line {{ $LINE }}"
31+
echo "Generated from template"
32+
"""
33+
}
34+
}
35+
36+
fn process_data() {
37+
comptime {
38+
echo "Processing data at line $LINE"
39+
echo "Function: process_data"
40+
}
41+
42+
unsafe """
43+
echo "Data processing at line {{ $LINE }}"
44+
echo "Function: {{ $FUNCTION }}"
45+
"""
46+
}

internal/README.md

Lines changed: 0 additions & 2 deletions
This file was deleted.

internal/interpreter/interpreter.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ func (interp *Interpreter) Eval(node ast.Node) ast.Node {
7878
return interp.rebuildFuncDecl(node)
7979
case *ast.CommentGroup:
8080
return interp.rebuildCommentGroup(node)
81-
case *ast.UnsafeStmt:
81+
case *ast.UnsafeExpr:
8282
return interp.rebuildUnsafeStmt(node)
8383
case *ast.ExternDecl:
8484
return interp.rebuildExternDecl(node)
@@ -373,7 +373,7 @@ func (interp *Interpreter) rebuildCallExpr(node *ast.CallExpr) ast.Node {
373373
return &ast.CallExpr{Fun: newFun.(ast.Expr), Recv: newRecv}
374374
}
375375

376-
func (interp *Interpreter) rebuildUnsafeStmt(node *ast.UnsafeStmt) ast.Node {
376+
func (interp *Interpreter) rebuildUnsafeStmt(node *ast.UnsafeExpr) ast.Node {
377377
return node
378378
}
379379

0 commit comments

Comments
 (0)