Skip to content

Commit

Permalink
fix: allow unicode symbols in string bracket access
Browse files Browse the repository at this point in the history
  • Loading branch information
eWert-Online committed Jan 20, 2024
1 parent 261affe commit 57aa6cf
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
8 changes: 5 additions & 3 deletions lib/pinc_backend/Pinc_Interpreter.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1102,12 +1102,14 @@ and eval_binary_bracket_access ~state left right =
| String a, Int b ->
let output =
try
String.get_utf_8_uchar a b
|> Uchar.utf_decode_uchar
a
|> CCUtf8_string.of_string_exn
|> CCUtf8_string.to_list
|> Fun.flip List.nth b
|> Value.of_char
~value_loc:
(Location.merge ~s:left.expression_loc ~e:right.expression_loc ())
with Invalid_argument _ ->
with Failure _ | Invalid_argument _ ->
Value.null
~value_loc:(Location.merge ~s:left.expression_loc ~e:right.expression_loc ())
()
Expand Down
7 changes: 6 additions & 1 deletion test/test.t/data.pi
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,16 @@ site Docs(
) {
let floats? = [1_000.462, 1., 1.4332, .5, 1e10, 1e+2, 1e-5, 1.e-2, 0.1e-1];

let fruits = " apples,oranges,bannanas ";
let fruits = " ⌘,apples,oranges,bannanas ";

let unicode = "⌘2";

<>
{fruits |> Base.String.trim |> Base.String.split(',')}

{unicode[0]}
{unicode[1]}

{floats[0]}
</>
}
3 changes: 3 additions & 0 deletions test/test.t/run.t
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
$ print . Docs
apples
oranges
bannanas
2
1000.462

0 comments on commit 57aa6cf

Please sign in to comment.