diff --git a/examples/be.coem b/examples/be.coem
new file mode 100644
index 0000000..d5642cc
--- /dev/null
+++ b/examples/be.coem
@@ -0,0 +1,7 @@
+#as palimpsest
+
+let flag be black
+let flag be yellow
+let flag be red
+
+know—flag—
\ No newline at end of file
diff --git a/examples/briefly.coem b/examples/briefly.coem
new file mode 100644
index 0000000..5d03130
--- /dev/null
+++ b/examples/briefly.coem
@@ -0,0 +1,6 @@
+say—surrender—
+say—alabaster—
+let (switchblade|honeysuckle|goldenrod)
+say—autumn— † despite the green in my eyes.
+say—beauty— † despite daylight.
+say—“i’d kill for it”—
\ No newline at end of file
diff --git a/examples/cat-detected.be.coem b/examples/cat-detected.be.coem
new file mode 100644
index 0000000..9e1879a
--- /dev/null
+++ b/examples/cat-detected.be.coem
@@ -0,0 +1,10 @@
+let (ch|k)at(|tze) be “🐈”
+
+let savoir be know
+savoir—chat is “🐈”—
+
+let weten be know
+weten—kat is “🐈”—
+
+let wissen be know
+wissen—katze is “🐈”—
\ No newline at end of file
diff --git a/examples/docks.coem b/examples/docks.coem
new file mode 100644
index 0000000..968ab4f
--- /dev/null
+++ b/examples/docks.coem
@@ -0,0 +1,6 @@
+let se(e|a) be “blue”
+let mis(t|sed) be “thick”
+let mou?rning be “dark”
+let me be nothing
+know—see, mist, morning—
+know—sea, missed, mourning—
\ No newline at end of file
diff --git a/examples/index.html b/examples/index.html
new file mode 100644
index 0000000..cc59348
--- /dev/null
+++ b/examples/index.html
@@ -0,0 +1,42 @@
+
+
+
+
+
+ coem-lang sandbox
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/examples/index.js b/examples/index.js
new file mode 100644
index 0000000..6165c99
--- /dev/null
+++ b/examples/index.js
@@ -0,0 +1,23 @@
+// $ .../index.js file-name.coem
+
+import { readFile } from "fs/promises";
+import { join } from "path";
+
+import { run, Environment } from "../src/main.js";
+
+const coemFileName = process.argv[2];
+
+if (!coemFileName) {
+ console.log("no coem file name provided");
+ process.exit();
+}
+
+const coem = await readFile(join(import.meta.dirname, coemFileName), "utf8");
+
+const debug = false;
+try {
+ const echo = await run(coem, new Environment(), debug);
+ console.log(echo);
+} catch (e) {
+ console.error(e);
+}
diff --git a/examples/optimism.coem b/examples/optimism.coem
new file mode 100644
index 0000000..295ee47
--- /dev/null
+++ b/examples/optimism.coem
@@ -0,0 +1,6 @@
+#with patience
+
+while—maybe—:
+ know—optimism—.
+
+know—peace—
\ No newline at end of file
diff --git a/examples/reminder.coem b/examples/reminder.coem
new file mode 100644
index 0000000..42d9964
--- /dev/null
+++ b/examples/reminder.coem
@@ -0,0 +1,9 @@
+† this is a reminder
+
+to breathe?——:
+ † in and out, and thus to
+ know—myself—.
+
+let me|myself|I be “present”
+if—I am “present”—:
+ let me be breath——.
\ No newline at end of file
diff --git a/examples/sleep.coem b/examples/sleep.coem
new file mode 100644
index 0000000..475cf00
--- /dev/null
+++ b/examples/sleep.coem
@@ -0,0 +1,6 @@
+to sl?eep—when—:
+ “dreams”.
+
+sleep—“now”—
+sleep—“never”—
+seep—“continually”—
\ No newline at end of file
diff --git a/examples/snail-train.coem b/examples/snail-train.coem
new file mode 100644
index 0000000..c65652d
--- /dev/null
+++ b/examples/snail-train.coem
@@ -0,0 +1 @@
+print—“i_@”—
\ No newline at end of file
diff --git a/examples/snail-train.realtime.coem b/examples/snail-train.realtime.coem
new file mode 100644
index 0000000..e6e7ebf
--- /dev/null
+++ b/examples/snail-train.realtime.coem
@@ -0,0 +1,3 @@
+#with patience
+
+print—“i_@”—
\ No newline at end of file
diff --git a/index.js b/examples/test.coem
similarity index 64%
rename from index.js
rename to examples/test.coem
index 8b028f9..c54f0f5 100644
--- a/index.js
+++ b/examples/test.coem
@@ -1,8 +1,4 @@
-import { run, Environment } from './src/main.js';
-
-const debug = true;
-
-const source = `#as palimpsest
+#as palimpsest
to conditional——:
let tomorrow be not coming
@@ -28,29 +24,11 @@ to conditional——:
let end be “watching the sky burn”.
† conditional——
+
say—“It doesn’t matter.”—
say—“That would be enough.”—
let this be “us alive”
let this be “right here”
let this be “feeling lucky”
let you be wanting
-this`;
-
-function handleError(e, source = "") {
- if (!e) return null;
- console.error(e);
-}
-
-function handleOutput(...txt) {
- console.log(...txt);
-}
-
-const browserEnv = new Environment();
-try {
- // console.log(run(source, browserEnv, handleOutput, false));
- let echo = run(source, browserEnv, debug);
- console.log(echo);
- handleError(null);
-} catch (e) {
- handleError(e, source);
-}
\ No newline at end of file
+this
\ No newline at end of file
diff --git a/examples/woman.coem b/examples/woman.coem
new file mode 100644
index 0000000..658e842
--- /dev/null
+++ b/examples/woman.coem
@@ -0,0 +1,10 @@
+† based on Emmy Meli's “I Am Woman”
+
+#as palimpsest
+
+let I|me|myself be “woman”
+let me be “fearless”
+let me be “sexy”
+let me be “divine”
+
+know—myself—
\ No newline at end of file
diff --git a/src/environment.js b/src/environment.js
index ce64c71..43954dc 100644
--- a/src/environment.js
+++ b/src/environment.js
@@ -1,10 +1,10 @@
-import { runtimeError } from './errors.js';
+import { runtimeError } from "./errors.js";
class Environment {
-
constructor(enclosing = null) {
this.values = new Map();
this.enclosing = enclosing;
+ this.withPatience = false;
}
get(token) {
@@ -42,6 +42,13 @@ class Environment {
Environment.asPalimpsest = true;
return;
}
+ if (
+ (name === "with" && value.literal === "patience") ||
+ (name === "read" && value.literal === "slowly")
+ ) {
+ this.withPatience = true;
+ return;
+ }
let pattern = new RegExp(name);
let set = this.getSet(name);
@@ -81,4 +88,4 @@ class Environment {
Environment.asPalimpsest = false;
-export { Environment };
\ No newline at end of file
+export { Environment };
diff --git a/src/main.js b/src/main.js
index ebedaee..6deb429 100644
--- a/src/main.js
+++ b/src/main.js
@@ -1,13 +1,13 @@
// adapted from YALI.js by Daniel Berezin (danman113)
// https://github.com/danman113/YALI.js
-import { Tokenizer } from './tokenizer.js';
-import { Parser } from './parser.js';
-import { Interpreter } from './interpreter.js';
-import { Environment } from './environment.js';
+import { Tokenizer } from "./tokenizer.js";
+import { Parser } from "./parser.js";
+import { Interpreter } from "./interpreter.js";
+import { Environment } from "./environment.js";
// function run(code, environment, printfn, debug = false) {
-function run(code, environment, debug = false) {
+async function run(code, environment, debug = false) {
const tokenizer = new Tokenizer(code);
const tokens = tokenizer.scanTokens();
if (debug) console.log(tokens);
@@ -21,6 +21,11 @@ function run(code, environment, debug = false) {
lastStatement = interpreter.interpret(statement);
}
const echo = interpreter.getEcho();
+
+ if (environment.withPatience) {
+ await new Promise((res) => setTimeout(res, code.split("\n").length * 500));
+ }
+
return echo;
// return lastStatement;
}
@@ -33,12 +38,5 @@ function parse(code) {
return statements;
}
-export { formatCoemError } from './errors.js';
-export {
- run,
- parse,
- Parser,
- Tokenizer,
- Interpreter,
- Environment
-};
\ No newline at end of file
+export { formatCoemError } from "./errors.js";
+export { run, parse, Parser, Tokenizer, Interpreter, Environment };