fazer-lang 1.1.0 → 2.1.1
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.
- package/README.md +200 -32
- package/apply_icon.js +28 -0
- package/apply_icon_robust.js +51 -0
- package/bin/fazer.exe +0 -0
- package/fazer.js +1156 -162
- package/package.json +38 -27
- package/standalone.bundled.js +12910 -0
- package/standalone.js +186 -0
- package/test.fz +92 -0
package/standalone.js
ADDED
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
const {
|
|
2
|
+
lexer,
|
|
3
|
+
FazerParser,
|
|
4
|
+
FazerRuntime,
|
|
5
|
+
FazerError,
|
|
6
|
+
prettyError,
|
|
7
|
+
locOf
|
|
8
|
+
} = require("./fazer.js");
|
|
9
|
+
|
|
10
|
+
const EMBEDDED_CODE = `
|
|
11
|
+
fn banner() →
|
|
12
|
+
println(style(" ███████╗███████╗ ███████╗███╗ ██╗ ██████╗██████╗ ██╗ ██╗██████╗ ████████╗", "cyan"))
|
|
13
|
+
println(style(" ██╔════╝╚══███╔╝ ██╔════╝████╗ ██║██╔════╝██╔══██╗╚██╗ ██╔╝██╔══██╗╚══██╔══╝", "cyan"))
|
|
14
|
+
println(style(" █████╗ ███╔╝█████╗█████╗ ██╔██╗ ██║██║ ██████╔╝ ╚████╔╝ ██████╔╝ ██║ ", "cyan"))
|
|
15
|
+
println(style(" ██╔══╝ ███╔╝ ╚════╝██╔══╝ ██║╚██╗██║██║ ██╔══██╗ ╚██╔╝ ██╔═══╝ ██║ ", "cyan"))
|
|
16
|
+
println(style(" ██║ ███████╗ ███████╗██║ ╚████║╚██████╗██║ ██║ ██║ ██║ ██║ ", "cyan"))
|
|
17
|
+
println(style(" ╚═╝ ╚══════╝ ╚══════╝╚═╝ ╚═══╝ ╚═════╝╚═╝ ╚═╝ ╚═╝ ╚═╝ ╚═╝ ", "cyan"))
|
|
18
|
+
println(style(" SECURE VAULT • AES-256-GCM • FAZER LANGUAGE", "gray"))
|
|
19
|
+
println("")
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
fn menu() →
|
|
23
|
+
box(
|
|
24
|
+
style("MENU PRINCIPAL", "yellow"),
|
|
25
|
+
"1) Chiffrer un fichier (Texte)",
|
|
26
|
+
"2) Déchiffrer un fichier (Texte)",
|
|
27
|
+
"3) Chiffrer un fichier (Binaire)",
|
|
28
|
+
"4) Déchiffrer un fichier (Binaire)",
|
|
29
|
+
"0) Quitter"
|
|
30
|
+
)
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
fn promptPath(label, def) →
|
|
34
|
+
v := ask(label + " [" + def + "]: ")
|
|
35
|
+
case v
|
|
36
|
+
null → return(def) end
|
|
37
|
+
"" → return(def) end
|
|
38
|
+
else → return(v) end
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
fn promptPass() →
|
|
43
|
+
p := ask("Mot de passe: ")
|
|
44
|
+
case p
|
|
45
|
+
null → return("") end
|
|
46
|
+
else → return(p) end
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
fn checkExists(p) →
|
|
51
|
+
case exists(p)
|
|
52
|
+
true → return(true) end
|
|
53
|
+
else →
|
|
54
|
+
println(style("❌ ERREUR: Le fichier '" + p + "' est introuvable.", "red"))
|
|
55
|
+
return(false)
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
fn doEncText() →
|
|
61
|
+
inPath := promptPath("Fichier source (Texte)", "message.txt")
|
|
62
|
+
case checkExists(inPath)
|
|
63
|
+
false → return(null) end
|
|
64
|
+
else → end
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
outPath := promptPath("Fichier destination", "message.enc")
|
|
68
|
+
pass := promptPass()
|
|
69
|
+
|
|
70
|
+
println(style("⏳ Chiffrement en cours...", "cyan"))
|
|
71
|
+
readText(inPath) →> encText(pass) →> saveText(outPath)
|
|
72
|
+
println(style("✅ Succès ! Fichier chiffré : " + outPath, "green"))
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
fn doDecText() →
|
|
76
|
+
inPath := promptPath("Fichier chiffré (.enc)", "message.enc")
|
|
77
|
+
case checkExists(inPath)
|
|
78
|
+
false → return(null) end
|
|
79
|
+
else → end
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
outPath := promptPath("Fichier destination (Texte)", "message.txt")
|
|
83
|
+
pass := promptPass()
|
|
84
|
+
|
|
85
|
+
println(style("⏳ Déchiffrement en cours...", "cyan"))
|
|
86
|
+
readText(inPath) →> decText(pass) →> saveText(outPath)
|
|
87
|
+
println(style("✅ Succès ! Fichier déchiffré : " + outPath, "green"))
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
fn doEncBin() →
|
|
91
|
+
inPath := promptPath("Fichier source (Binaire)", "image.png")
|
|
92
|
+
case checkExists(inPath)
|
|
93
|
+
false → return(null) end
|
|
94
|
+
else → end
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
outPath := promptPath("Fichier destination", "image.enc")
|
|
98
|
+
pass := promptPass()
|
|
99
|
+
|
|
100
|
+
println(style("⏳ Chiffrement binaire en cours...", "cyan"))
|
|
101
|
+
readB64(inPath) →> encB64(pass) →> saveText(outPath)
|
|
102
|
+
println(style("✅ Succès ! Fichier chiffré : " + outPath, "green"))
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
fn doDecBin() →
|
|
106
|
+
inPath := promptPath("Fichier chiffré (.enc)", "image.enc")
|
|
107
|
+
case checkExists(inPath)
|
|
108
|
+
false → return(null) end
|
|
109
|
+
else → end
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
outPath := promptPath("Fichier destination (Binaire)", "image_out.png")
|
|
113
|
+
pass := promptPass()
|
|
114
|
+
|
|
115
|
+
println(style("⏳ Déchiffrement binaire en cours...", "cyan"))
|
|
116
|
+
readText(inPath) →> decB64(pass) →> saveB64(outPath)
|
|
117
|
+
println(style("✅ Succès ! Fichier déchiffré : " + outPath, "green"))
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
fn loop() →
|
|
121
|
+
println("")
|
|
122
|
+
menu()
|
|
123
|
+
c := ask("Votre choix: ")
|
|
124
|
+
|
|
125
|
+
case c
|
|
126
|
+
"1" → doEncText() end
|
|
127
|
+
"2" → doDecText() end
|
|
128
|
+
"3" → doEncBin() end
|
|
129
|
+
"4" → doDecBin() end
|
|
130
|
+
"0" →
|
|
131
|
+
println(style("👋 Au revoir !", "gray"))
|
|
132
|
+
return(null)
|
|
133
|
+
end
|
|
134
|
+
else → println(style("⚠️ Choix invalide.", "red")) end
|
|
135
|
+
end
|
|
136
|
+
|
|
137
|
+
loop()
|
|
138
|
+
end
|
|
139
|
+
|
|
140
|
+
banner()
|
|
141
|
+
loop()
|
|
142
|
+
`;
|
|
143
|
+
|
|
144
|
+
function main() {
|
|
145
|
+
const code = EMBEDDED_CODE;
|
|
146
|
+
const filePath = "<embedded>";
|
|
147
|
+
|
|
148
|
+
const lex = lexer.tokenize(code);
|
|
149
|
+
if (lex.errors.length) {
|
|
150
|
+
console.error("Lexer error:", lex.errors[0].message || String(lex.errors[0]));
|
|
151
|
+
process.exit(1);
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
const parser = new FazerParser();
|
|
155
|
+
parser.input = lex.tokens;
|
|
156
|
+
const ast = parser.program();
|
|
157
|
+
|
|
158
|
+
if (parser.errors.length) {
|
|
159
|
+
const e = parser.errors[0];
|
|
160
|
+
const tok = e.token || (lex.tokens.length ? lex.tokens[0] : null);
|
|
161
|
+
const meta = tok ? locOf(tok) : null;
|
|
162
|
+
const ferr = new FazerError(e.message, meta || {});
|
|
163
|
+
console.error(prettyError(ferr, filePath, code));
|
|
164
|
+
process.exit(1);
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
const rt = new FazerRuntime({ argv: [], filename: filePath, code });
|
|
168
|
+
try {
|
|
169
|
+
rt.run(ast);
|
|
170
|
+
// Keep window open after successful execution if loop returns
|
|
171
|
+
console.log("\nAppuyez sur Entrée pour quitter...");
|
|
172
|
+
try { fs.readSync(0, Buffer.alloc(1), 0, 1, null); } catch(e){}
|
|
173
|
+
} catch (err) {
|
|
174
|
+
if (err instanceof FazerError) {
|
|
175
|
+
console.error(prettyError(err, filePath, code));
|
|
176
|
+
} else {
|
|
177
|
+
console.error(err && err.stack ? err.stack : String(err));
|
|
178
|
+
}
|
|
179
|
+
console.log("\nUne erreur s'est produite.");
|
|
180
|
+
console.log("Appuyez sur Entrée pour fermer la fenêtre...");
|
|
181
|
+
try { fs.readSync(0, Buffer.alloc(1), 0, 1, null); } catch(e){}
|
|
182
|
+
process.exit(1);
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
main();
|
package/test.fz
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
banner := fn() →
|
|
2
|
+
println(style("███████╗ █████╗ ███████╗███████╗██████╗ ", "cyan"))
|
|
3
|
+
println(style("██╔════╝██╔══██╗╚══███╔╝██╔════╝██╔══██╗", "cyan"))
|
|
4
|
+
println(style("█████╗ ███████║ ███╔╝ █████╗ ██████╔╝", "cyan"))
|
|
5
|
+
println(style("██╔══╝ ██╔══██║ ███╔╝ ██╔══╝ ██╔══██╗", "cyan"))
|
|
6
|
+
println(style("██║ ██║ ██║███████╗███████╗██║ ██║", "cyan"))
|
|
7
|
+
println(style("╚═╝ ╚═╝ ╚═╝╚══════╝╚══════╝╚═╝ ╚═╝", "cyan"))
|
|
8
|
+
println(style(" VAULT • AES-256-GCM", "gray"))
|
|
9
|
+
println("")
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
menu := fn() →
|
|
13
|
+
box(
|
|
14
|
+
style("MENU", "yellow"),
|
|
15
|
+
"1) Encrypt TEXT (in.txt -> out.enc)",
|
|
16
|
+
"2) Decrypt TEXT (in.enc -> out.txt)",
|
|
17
|
+
"3) Encrypt BINARY (file.bin -> out.enc)",
|
|
18
|
+
"4) Decrypt BINARY (in.enc -> file.bin)",
|
|
19
|
+
"0) Quit"
|
|
20
|
+
)
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
promptPath := fn(label, def) →
|
|
24
|
+
v := ask(label + " [" + def + "]: ")
|
|
25
|
+
case v
|
|
26
|
+
null → return(def) end
|
|
27
|
+
"" → return(def) end
|
|
28
|
+
else → return(v) end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
promptPass := fn() →
|
|
33
|
+
p := ask("Password: ")
|
|
34
|
+
case p
|
|
35
|
+
null → return("") end
|
|
36
|
+
else → return(p) end
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
doEncText := fn() →
|
|
41
|
+
inPath := promptPath("Input text file", "in.txt")
|
|
42
|
+
outPath := promptPath("Output .enc file", "out.enc")
|
|
43
|
+
pass := promptPass()
|
|
44
|
+
box(style("WORK", "cyan"), "Encrypting TEXT...", "in=" + inPath, "out=" + outPath)
|
|
45
|
+
readText(inPath) →> encText(pass) →> writeText(outPath)
|
|
46
|
+
box(style("OK", "green"), "Encrypted.", "out=" + outPath)
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
doDecText := fn() →
|
|
50
|
+
inPath := promptPath("Input .enc file", "out.enc")
|
|
51
|
+
outPath := promptPath("Output text file", "out.txt")
|
|
52
|
+
pass := promptPass()
|
|
53
|
+
box(style("WORK", "cyan"), "Decrypting TEXT...", "in=" + inPath, "out=" + outPath)
|
|
54
|
+
readText(inPath) →> decText(pass) →> writeText(outPath)
|
|
55
|
+
box(style("OK", "green"), "Decrypted.", "out=" + outPath)
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
doEncBin := fn() →
|
|
59
|
+
inPath := promptPath("Input binary file", "file.bin")
|
|
60
|
+
outPath := promptPath("Output .enc file", "file.enc")
|
|
61
|
+
pass := promptPass()
|
|
62
|
+
box(style("WORK", "cyan"), "Encrypting BINARY...", "in=" + inPath, "out=" + outPath)
|
|
63
|
+
readB64(inPath) →> encB64(pass) →> writeText(outPath)
|
|
64
|
+
box(style("OK", "green"), "Encrypted.", "out=" + outPath)
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
doDecBin := fn() →
|
|
68
|
+
inPath := promptPath("Input .enc file", "file.enc")
|
|
69
|
+
outPath := promptPath("Output binary file", "file.out.bin")
|
|
70
|
+
pass := promptPass()
|
|
71
|
+
box(style("WORK", "cyan"), "Decrypting BINARY...", "in=" + inPath, "out=" + outPath)
|
|
72
|
+
readText(inPath) →> decB64(pass) →> writeB64(outPath)
|
|
73
|
+
box(style("OK", "green"), "Decrypted.", "out=" + outPath)
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
loop := fn() →
|
|
77
|
+
menu()
|
|
78
|
+
c := ask("Choice: ")
|
|
79
|
+
case c
|
|
80
|
+
"1" → doEncText() end
|
|
81
|
+
"2" → doDecText() end
|
|
82
|
+
"3" → doEncBin() end
|
|
83
|
+
"4" → doDecBin() end
|
|
84
|
+
"0" → box(style("BYE", "gray"), "See you.") → return(null) end
|
|
85
|
+
else → box(style("ERROR", "red"), "Invalid choice: " + c) end
|
|
86
|
+
end
|
|
87
|
+
println("")
|
|
88
|
+
loop()
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
banner()
|
|
92
|
+
loop()
|