aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAkshay Nair <phenax5@gmail.com>2023-08-25 10:17:21 +0530
committerAkshay Nair <phenax5@gmail.com>2023-08-25 10:17:21 +0530
commit0665e6a2490c9ea770a98908788a1e5d210aa811 (patch)
tree307654d37d10ad2055947c0d8ec40c3188f01938
parent2f99128e354e5c5334094f072767164c8e4fbd2f (diff)
downloadcss-everything-0665e6a2490c9ea770a98908788a1e5d210aa811.tar.gz
css-everything-0665e6a2490c9ea770a98908788a1e5d210aa811.zip
feat: adds try expression for error handlign
Diffstat (limited to '')
-rw-r--r--TODO.norg5
-rw-r--r--examples/clock/style.css1
-rw-r--r--src/eval.ts8
-rw-r--r--src/parser.ts2
4 files changed, 12 insertions, 4 deletions
diff --git a/TODO.norg b/TODO.norg
index 5963d35..e63ec73 100644
--- a/TODO.norg
+++ b/TODO.norg
@@ -4,20 +4,19 @@
- (x) some way to de-quotify values?
- (x) re-quotify value
- (x) analog + digital clock example
+ - (x) error handling try
- ( ) `has-class`
- ( ) `add-class` & `remove-class` should use self if id is not specified?
- ( ) Update `--cssx-text` on update
- - ( ) fix invalid expr in functions error
* Later
- - ( ) FFI interface to declare functions
- - ( ) `request` error handling
- ( ) keyboard events
- ( ) Code cleanup
- ( ) Additional events
- ( ) Improve parser error messages
- ( ) Improve eval error messages
- ( ) filter for on update on specific properties
+ - ( ) FFI interface to declare functions
* Maybe
- ( ) `--cssx-use-properties: --parent-prop;` to trigger nested property update
diff --git a/examples/clock/style.css b/examples/clock/style.css
index a6f8349..c23e033 100644
--- a/examples/clock/style.css
+++ b/examples/clock/style.css
@@ -44,6 +44,7 @@ body * { box-sizing: border-box; }
--cssx-on-mount: update(--date, call(--get-date));
--cssx-on-update:
+ update('[data-element=seconds]', --angle, js-eval("360 * new Date().getSeconds() / 60 - 90")),
update('[data-element=seconds]', --angle, js-eval("360 * new Date().getSeconds() / 60 - 90"))
update('[data-element=minutes]', --angle, js-eval("360 * new Date().getMinutes() / 60 - 90"))
update('[data-element=hours]', --angle,
diff --git a/src/eval.ts b/src/eval.ts
index 91514b9..0be3de5 100644
--- a/src/eval.ts
+++ b/src/eval.ts
@@ -322,6 +322,14 @@ const getFunctions = (
return EvalValue.String(dequotify(str || ''))
},
+ try: async () => {
+ try {
+ return await evalExpr(args[0], actions)
+ } catch (e) {
+ return evalExpr(args[1], actions)
+ }
+ },
+
_: () => Promise.reject(new Error(`Not implemented: ${name}`)),
})
}
diff --git a/src/parser.ts b/src/parser.ts
index eeb9acf..216c1bc 100644
--- a/src/parser.ts
+++ b/src/parser.ts
@@ -142,7 +142,7 @@ export const parseDeclarations = (input: string) =>
)
export const parse = (input: string): Array<Expr> => {
- const res = P.many1(exprParser)(input.trim())
+ const res = P.sepBy(exprParser, P.or([comma, whitespace]))(input.trim())
return match(res, {
Ok: ({ value, input }) => {
if (input) {