Closed herwinw closed 1 year ago
Source: https://github.com/ruby/prime/blob/586cbdd2af7a5905121c2c93555cdc0bc3c07b50/lib/prime.rb#L46
MRI parses this code differently from Natalie. Compare these two results:
$ ruby -e 'x=13; y=5; p x%(y)' 3 $ bin/natalie -e 'x=13; y=5; p x%(y)' 13 "y"
MRI interprets %( as a String literal and somehow creates an array of these values and passes that to p.
%(
p
If we remove the print, or replace it with something like an assignment, Natalie raises a parse error
$ bin/natalie -e 'x=13; y=5; x%(y)' lib/natalie/parser.rb:32:in `parse': -e#1: syntax error, unexpected dstr '(' (expected: 'end-of-line') (SyntaxError) x=13; y=5; x%(y) ^ here, expected 'end-of-line'
Adding a space between x and % does not change the behaviour (but a space between % and ( does).
x
%
(
Archiving this repo in favor of YARP...
Source: https://github.com/ruby/prime/blob/586cbdd2af7a5905121c2c93555cdc0bc3c07b50/lib/prime.rb#L46
MRI parses this code differently from Natalie. Compare these two results:
MRI interprets
%(
as a String literal and somehow creates an array of these values and passes that top
.If we remove the print, or replace it with something like an assignment, Natalie raises a parse error
Adding a space between
x
and%
does not change the behaviour (but a space between%
and(
does).