Skip to content

Commit

Permalink
better html parser
Browse files Browse the repository at this point in the history
  • Loading branch information
CrowdHailer committed Oct 21, 2023
1 parent 3c3f67f commit 4074496
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 1 deletion.
2 changes: 1 addition & 1 deletion eyg/saved/saved.json

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions eyg/src/harness/ffi/core.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,11 @@ pub fn lib() {
// string
|> extend("string_append", string.append())
|> extend("string_split", string.split())
|> extend("string_split_once", string.split_once())
|> extend("string_replace", string.replace())
|> extend("string_uppercase", string.uppercase())
|> extend("string_lowercase", string.lowercase())
|> extend("string_starts_with", string.starts_with())
|> extend("string_ends_with", string.ends_with())
|> extend("string_length", string.length())
|> extend("pop_grapheme", string.pop_grapheme())
Expand Down
33 changes: 33 additions & 0 deletions eyg/src/harness/ffi/string.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,23 @@ pub fn do_split(s, pattern, rev, env, k) {
)
}

pub fn split_once() {
let type_ =
t.Fun(t.Str, t.Open(0), t.Fun(t.Str, t.Open(1), t.LinkedList(t.Str)))
#(type_, r.Arity2(do_split_once))
}

pub fn do_split_once(s, pattern, rev, env, k) {
use s <- cast.require(cast.string(s), rev, env, k)
use pattern <- cast.require(cast.string(pattern), rev, env, k)
let value = case string.split_once(s, pattern) {
Ok(#(pre, post)) ->
r.ok(r.Record([#("pre", r.Str(pre)), #("post", r.Str(post))]))
Error(Nil) -> r.error(r.unit)
}
r.prim(r.Value(value), rev, env, k)
}

pub fn uppercase() {
let type_ = t.Fun(t.Str, t.Open(0), t.Str)
#(type_, r.Arity1(do_uppercase))
Expand All @@ -55,6 +72,22 @@ pub fn do_lowercase(value, rev, env, k) {
r.prim(r.Value(r.Str(string.lowercase(value))), rev, env, k)
}

pub fn starts_with() {
let type_ =
t.Fun(t.Str, t.Open(0), t.Fun(t.Str, t.Open(1), t.result(t.Str, t.unit)))
#(type_, r.Arity2(do_starts_with))
}

pub fn do_starts_with(value, prefix, rev, env, k) {
use value <- cast.require(cast.string(value), rev, env, k)
use prefix <- cast.require(cast.string(prefix), rev, env, k)
let ret = case string.split_once(value, prefix) {
Ok(#("", post)) -> r.ok(r.Str(post))
_ -> r.error(r.unit)
}
r.prim(r.Value(ret), rev, env, k)
}

pub fn ends_with() {
let type_ =
t.Fun(t.Str, t.Open(0), t.Fun(t.Str, t.Open(1), t.result(t.Str, t.unit)))
Expand Down
13 changes: 13 additions & 0 deletions tmp.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,19 @@ OR
deploying a continuation
lisp docs, everything first class so partial cases, but need record syntax

```
fn (state, ch) {
match state {
ReadText(state) -> read_text(state, ch)
ReadTag(state) -> read_tag(state, ch)
}
}
match {
ReadText read_text
ReadTag read_tag
}
```

(let client (facilities.google.auth 1))
(client.send "[email protected]" "somemessage")
Expand Down

0 comments on commit 4074496

Please sign in to comment.