Skip to content

Commit

Permalink
Simplify readi integer validation
Browse files Browse the repository at this point in the history
  • Loading branch information
thaliaarchi committed Jan 31, 2024
1 parent 1c5a4b4 commit f5e7654
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions ws.jq
Original file line number Diff line number Diff line change
Expand Up @@ -350,10 +350,8 @@ def interpret_step:
def readi:
(.in_buf|index("\n")) as $i | .in_buf[:$i] as $line |
.in_consumed += .in_buf[:$i+1] | .in_buf |= .[$i+1:] |
($line|tonumber? // .5) as $n |
assert(($n|. == trunc) and ($line | test("^\\s*[+-]?\\d+\\s*$"));
"invalid integer " + ($line | tojson)) |
store(top; $n) | pop;
assert($line|test("^\\s*-?\\d+\\s*$"); "invalid integer \($line|tojson)") |
store(top; $line|tonumber) | pop;

assert(.pc < (.prog|length); "interpreter stopped") |
assert(.error == null; "interpreter stopped from error") |
Expand Down

0 comments on commit f5e7654

Please sign in to comment.