Comments (9)
This is by design. When you pass scopes, we assume you are parsing an eval
. When parsing an eval
, a syntax error is not raised for those jumps. Instead, it relies on the compiler to evaluate whether or not they are valid. This matches CRuby semantics.
from prism.
Hm, but SyntaxError
is raised in CRuby:
$ ruby -v test.rb
ruby 3.3.0 (2023-12-25 revision 5124f9ac75) [x86_64-darwin23]
(eval at test.rb:1): (eval at test.rb:1):1: Invalid break (SyntaxError)
test.rb:
eval("def m; break; end")
Ah, you mean it's a responsibility of compiler. Got it 👍
from prism.
Yeah, unfortunately. Consider for instance the difference between 0 rescue next
and eval("0 rescue next")
. The second raises Can't escape from eval with next
.
from prism.
Is it mostly about different error messages? I'm not sure if that difference is important enough to have this behavior differ with scopes.
For the def m; break; end
case it seems to behave the same within or outside eval in CRuby, so it feels like Prism could always give a syntax error for that one, no?
It's not very important, but it would avoid duplicating this logic in the compiler/translator, where it feels wrong/annoying to do so.
from prism.
Some other examples:
def m; retry; end
Prism seems to always error for this, eval or not, good.
module M; yield; end
Prism seems to only handle (= error) it if not in eval. This feels very much like a syntactic restriction, so would be nicer if Prism handled it always.
from prism.
I'll try to find which tests were failing, but when I implemented this I got a couple more test-all
tests passing. There are some things that are relying on this behavior.
from prism.
Ahh, it was the ERB tests. We need this to not error out in case you're parsing an ERB file
from prism.
We need this to not error out in case you're parsing an ERB file
I'm not following, could you give a concrete example?
Which specific jump should not error when parsing an ERB file?
And how comes there is no error from compile.c
then, i.e. how come one can distinguish between parser and compile.c in that case? (eval
does both).
from prism.
Ah maybe it's related to Ripper? I've seen https://bugs.ruby-lang.org/issues/20460 now
from prism.
Related Issues (20)
- Ensure line number is incorrect in CRuby compiler
- Incorrect frozen value for interpolated string HOT 1
- Not emitting `class` tracepoint events in CRuby compiler HOT 1
- Not emitting `end` tracepoint events in CRuby compiler HOT 1
- Dynamic regular expressions have incorrect encoding in CRuby compiler HOT 1
- Regexp fixed encoding should raise SyntaxError if source encoding doesn't match a fixed one
- Encoding flags for parts of an InterpolatedRegularExpressionNode HOT 2
- Not accurate exception message for incorrect global variable name `$`
- Missing typed sigil in rbi files HOT 4
- Unexpected write target for multi write node HOT 3
- Failure when calling `transpose` in `Prism::Translation::Parser` HOT 3
- `Prism::Translation::RubyParser` edge case when interpolating `__FILE__` into a string
- `Prism::Translation::RubyParser` - nested string literal interpolations are not flattened
- Parser Compiler: NoMethodError: undefined method `opening_loc' for @ ItParametersNode
- Update makefile to use / fall back on built-in "ar" HOT 36
- Value omitted hash keys ending with `!` or `?` are being parsed
- method_source not working with Prism due to different SyntaxError messages HOT 1
- CRuby prism compiler: respect Coverage eval setting HOT 1
- Question: How can I create a new Prism node and pass in `source`? HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from prism.