Skip to content

Commit

Permalink
fix typo for grapheme
Browse files Browse the repository at this point in the history
  • Loading branch information
CrowdHailer committed Jul 3, 2024
1 parent a45fb3d commit 8ceb301
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 28 deletions.
4 changes: 2 additions & 2 deletions eyg/src/easel/print.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ pub fn print_keyword(keyword, loc, acc, err) {
let Location(path: path, ..) = loc
// list.fold(
// string.to_graphemes(keyword),
stringx.fold_graphmemes(keyword, acc, fn(acc, ch) {
stringx.fold_graphemes(keyword, acc, fn(acc, ch) {
[#(ch, path, -1, Keyword, err), ..acc]
})
}
Expand All @@ -431,7 +431,7 @@ pub fn print_with_offset(content, loc, style, err, acc, info, _analysis) {
_ -> #(content, style)
}
let acc =
stringx.index_fold_graphmemes(
stringx.index_fold_graphemes(
// list.index_fold(
// string.to_graphemes(content),
content,
Expand Down
14 changes: 10 additions & 4 deletions eyg/src/gleam/stringx.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,18 @@ pub fn replace_at(original, from, to, new) {
|> string.concat
}

@external(javascript, "../plinth_ffi.js", "foldGraphmemes")
pub fn fold_graphmemes(a: String, b: a, c: fn(a, String) -> a) -> a
@external(javascript, "../gleam_stringx_ffi.mjs", "foldGraphemes")
pub fn fold_graphemes(a: String, b: a, c: fn(a, String) -> a) -> a

@external(javascript, "../plinth_ffi.js", "foldGraphmemes")
pub fn index_fold_graphmemes(a: String, b: a, c: fn(a, String, Int) -> a) -> a
@external(javascript, "../gleam_stringx_ffi.mjs", "foldGraphemes")
pub fn index_fold_graphemes(a: String, b: a, c: fn(a, String, Int) -> a) -> a

pub fn wrap(content, pre, post) {
string.concat([pre, content, post])
}

@external(javascript, "../gleam_stringx_ffi.mjs", "byte_slice_from")
pub fn byte_slice_from(string: String, from: Int) -> String

@external(javascript, "../gleam_stringx_ffi.mjs", "byte_slice_range")
pub fn byte_slice_range(string: String, from: Int, to: Int) -> String
19 changes: 19 additions & 0 deletions eyg/src/gleam_stringx_ffi.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
export function byte_slice_from(string, from) {
return string.slice(from);
}

export function byte_slice_range(string, from, to) {
return string.slice(from, to);
}

// https://stackoverflow.com/questions/1966476/how-can-i-process-each-letter-of-text-using-javascript
export function foldGraphemes(string, initial, f) {
let value = initial;
// for (const ch of string) {
// value = f(value, ch);
// }
[...string].forEach((c, i) => {
value = f(value, c, i);
});
return value;
}
6 changes: 3 additions & 3 deletions eyg/src/old_plinth/browser/document.gleam
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// TODO fix proper action or add event listener
@external(javascript, "../../plinth_ffi.js", "onClick")
@external(javascript, "../../plinth_ffi.mjs", "onClick")
pub fn on_click(a: fn(String) -> Nil) -> Nil

@external(javascript, "../../plinth_ffi.js", "onKeyDown")
@external(javascript, "../../plinth_ffi.mjs", "onKeyDown")
pub fn on_keydown(a: fn(String) -> Nil) -> Nil

@external(javascript, "../../plinth_ffi.js", "onChange")
@external(javascript, "../../plinth_ffi.mjs", "onChange")
pub fn on_change(a: fn(String) -> Nil) -> Nil
19 changes: 0 additions & 19 deletions eyg/src/plinth_ffi.js → eyg/src/plinth_ffi.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -41,22 +41,3 @@ export function onChange(f) {
};
}


// -------- element properties --------


export function array_graphmemes(string) {
return [...string];
}

// https://stackoverflow.com/questions/1966476/how-can-i-process-each-letter-of-text-using-javascript
export function foldGraphmemes(string, initial, f) {
let value = initial;
// for (const ch of string) {
// value = f(value, ch);
// }
[...string].forEach((c, i) => {
value = f(value, c, i);
});
return value;
}

0 comments on commit 8ceb301

Please sign in to comment.