JohnEarnest / ok

An open-source interpreter for the K5 programming language.
MIT License
585 stars 73 forks source link

Rendering character-codes beyond 127 in strings. #92

Closed AdamSaleh closed 2 years ago

AdamSaleh commented 3 years ago

Hi,

I have tried to play around with oK repl, and was a bit puzzled that I receive hexadecimal numbers if I i.e. use emoji in the text. I tracked down the issue to https://github.com/JohnEarnest/ok/blob/gh-pages/oK.js#L70

If I change var h = x.v.some(function(v){ return (v.v<32||v.v>127)&v.v!=9&v.v!=10; }); to remove the check for ||v.v>127:

var h = x.v.some(function(v){ return v.v<32&v.v!=9&v.v!=10; });

It seems to be displaying emoji, math notation and other arbitrary symbols I tried to paste from the unicode table seems to work fine.

Is there some other reason for cutting the chars above 127 character code? I haven't noticed it in the rest of the oK code.

JohnEarnest commented 3 years ago

I included that check to match the behavior of k5/k6, which have no unicode awareness; they just interpreted unicode sequences as lists of bytes, which are prettyprinted as "byte list" hex literals when they contain characters outside the printable ASCII range.