What text, if any, is allowed on the the line after the =begin and
=end delimiters of block comments?
I have code that looks like this:
=begin Hello
=end Goodbye
p “I work”
and it prints “I work” on these versions of Ruby:
ruby 1.8.6 (2008-08-11 patchlevel 287) [universal-darwin9.0]
ruby 1.9.0 (2008-07-25 revision 18217) [i686-darwin9.5.2]
jruby 1.3.0 (ruby 1.8.6p287) (2009-06-03 5dc2e22) (Java HotSpot™
Client VM 1.5.0_19) [i386-java]
Normally I wouldn’t think about this anymore, but he ruby-parser gem
(2.0.2) throws an error:
ruby_parser-2.0.2/lib/ruby_lexer.rb:385:in `rb_compile_error’:
embedded document meets end of file. near line 1: "
Hello" (SyntaxError)
although it works if you remove the text after the =end.
Based on a cursory grepping of the sources, Ruby 1.9 source
(ruby-1.9.1-p129) never uses any text on the same line as the =begin
or =end delimiters and Rubyspec doesn’t have any tests around block
comments. Rubyspec does have some =begin “Text”, but not =end “Text”
comment delimiters.
I’d like to fix the ruby-parser gem, but this seems to be something of
a grey area. I’ve never seen anything that requires Ruby to accept or
reject =end Text delimiters on block comments, but the de facto
standard and practice seem to be in conflict. The standard is to
accept text after the =end; the practice seems to be to not do it.
Thoughts?
1 Like
yesteray wrote:
What text, if any, is allowed on the the line after the =begin and
=end delimiters of block comments?
The Ruby P.ming Language specifically says that text can follow
=begin and =end as long as it’s separated by at least one blank, and
shows an example of both =begin and =end statements will additional text
on the same line. The text is treated as part of the comment.
On 7/18/09, yesteray [email protected] wrote:
Hello" (SyntaxError)
although it works if you remove the text after the =end.
RedParse doesn’t have this bug, tho there is a more obscure problem
with =begin blocks that I haven’t figured out yet.
On Jul 18, 5:27 pm, Tim H. [email protected] wrote:
The Ruby P.ming Language specifically says that text can follow
=begin and =end as long as it’s separated by at least one blank, and
shows an example of both =begin and =end statements will additional text
on the same line. The text is treated as part of the comment.
This appears to be an answer to the question possibly posed by
willfully ignoring everything following the first paragraph of the
post, including the code example.
Yossef M. wrote:
–
-yossef
The OP says “What text, if any, is allowed on the the line after the
=begin and =end delimiters of block comments?,” and “I’ve never seen
anything that requires Ruby to accept or reject =end Text delimiters on
block comments.” My response was a quote from an authoritative
reference. Based on the lack of follow-up I assumed my response was
adequate.
Perhaps I was wrong. What do you think the OP was asking? What’s your
answer to his question?
On Jul 20, 5:34 pm, Tim H. [email protected] wrote:
The OP says “What text, if any, is allowed on the the line after the
=begin and =end delimiters of block comments?,” and “I’ve never seen
anything that requires Ruby to accept or reject =end Text delimiters on
block comments.” My response was a quote from an authoritative
reference. Based on the lack of follow-up I assumed my response was
adequate.
Perhaps I was wrong. What do you think the OP was asking? What’s your
answer to his question?
Somehow my earlier reading seemed to focus on the lack of vertical
space between the =end line and the code line beneath it, and I was
completely wrong about the point of the question.
Apologies in advance for necro-posting, but this is the first link Google coughed up for my search…
I am seeing this behavior. It happens regardless of 1) where in the file the block is, 2) whether the begin/end are on the same line or not, and 3) whether there is anything between the tags or not. Wherever it resides, the code after appears commented out (in VSCode, but not relevant because command-line Ruby is what gives error), and the ruby interpreter gives error on file.
The command …
ruby -v
…gives…
ruby 3.0.2p107 2021-07-07 revision 0db68f0233 x86_64-linux-gnu
Note again, I am not reporting a VSCode error, just noting that the it plus the extensions are seeing the code the same way the command-line ruby interpreter is.
Thanks,
Steve
File: RubyApp1.arb
#!/usr/bin/ruby -w
BEGIN {
puts “Initializing Ruby Program”
}
=begin=end
puts “Hello, Ruby!”;
END {
puts “De-Initializing Ruby Program”
}
System:
Kernel: 5.15.0-57-generic x86_64 bits: 64 compiler: gcc v: 11.3.0 Desktop: Cinnamon 5.6.5
tk: GTK 3.24.33 wm: muffin dm: LightDM Distro: Linux Mint 21.1 Vera base: Ubuntu 22.04 jammy
Machine:
Type: Desktop System: Dell product: OptiPlex 7020 v: 00 serial: Chassis:
type: 6 serial:
Mobo: Dell model: 0F5C5X v: A00 serial: BIOS: Dell v: A10
date: 09/22/2016
Battery:
Device-1: hidpp_battery_0 model: Logitech M570 serial: charge: 35% status: Discharging
CPU:
Info: quad core model: Intel Core i5-4590 bits: 64 type: MCP arch: Haswell rev: 3 cache:
L1: 256 KiB L2: 1024 KiB L3: 6 MiB
Speed (MHz): avg: 2692 high: 2694 min/max: 800/3700 cores: 1: 2694 2: 2690 3: 2693 4: 2694
bogomips: 26340
Flags: avx avx2 ht lm nx pae sse sse2 sse3 sse4_1 sse4_2 ssse3 vmx
Graphics:
Device-1: AMD Oland [Radeon HD 8570 / R5 430 OEM R7 240/340 Radeon 520 OEM] vendor: Dell
driver: radeon v: kernel pcie: speed: 8 GT/s lanes: 8 ports: active: DVI-I-1 empty: DP-1
bus-ID: 01:00.0 chip-ID: 1002:6611
Device-2: Realtek RTL2838 DVB-T type: USB driver: dvb_usb_rtl28xxu,rtl2832_sdr bus-ID: 3-8:4
chip-ID: 0bda:2838
Display: x11 server: X.Org v: 1.21.1.3 driver: X: loaded: ati,radeon
unloaded: fbdev,modesetting,vesa gpu: radeon display-ID: :0 screens: 1
Screen-1: 0 s-res: 1920x1080 s-dpi: 96
Monitor-1: DVI-0 mapped: DVI-I-1 model: Acer H233H res: 1920x1080 dpi: 96 diag: 585mm (23")
OpenGL: renderer: AMD OLAND (LLVM 13.0.1 DRM 2.50 5.15.0-57-generic) v: 4.5 Mesa 22.0.5
direct render: Yes
Audio:
Device-1: Intel 8 Series/C220 Series High Definition Audio vendor: Dell driver: snd_hda_intel
v: kernel bus-ID: 00:1b.0 chip-ID: 8086:8c20
Device-2: AMD Oland/Hainan/Cape Verde/Pitcairn HDMI Audio [Radeon HD 7000 Series] vendor: Dell
driver: snd_hda_intel v: kernel pcie: speed: 8 GT/s lanes: 8 bus-ID: 01:00.1 chip-ID: 1002:aab0
Sound Server-1: ALSA v: k5.15.0-57-generic running: yes
Sound Server-2: JACK v: 1.9.20 running: no
Sound Server-3: PulseAudio v: 15.99.1 running: yes
Sound Server-4: PipeWire v: 0.3.48 running: yes
Network:
Device-1: Intel Ethernet I217-LM vendor: Dell driver: e1000e v: kernel port: f040
bus-ID: 00:19.0 chip-ID: 8086:153a
IF: eno1 state: up speed: 1000 Mbps duplex: full mac:
IF-ID-1: virbr0 state: down mac:
Drives:
Local Storage: total: 1.93 TiB used: 1.89 TiB (98.1%)
ID-1: /dev/sda vendor: Western Digital model: WDS100T2B0A-00SM50 size: 931.51 GiB
speed: 6.0 Gb/s serial:
ID-2: /dev/sdb vendor: Samsung model: SSD 840 EVO 120GB size: 111.79 GiB speed: 6.0 Gb/s
serial:
ID-3: /dev/sdc type: USB vendor: Western Digital model: WD My Passport 25E1 size: 931.48 GiB
serial:
Partition:
ID-1: / size: 98.44 GiB used: 28.51 GiB (29.0%) fs: ext4 dev: /dev/sdb1
ID-2: /home size: 915.82 GiB used: 726.73 GiB (79.4%) fs: ext4 dev: /dev/sda1
Swap:
ID-1: swap-1 type: partition size: 11.21 GiB used: 0 KiB (0.0%) priority: -2 dev: /dev/sdb2
Sensors:
System Temperatures: cpu: 29.8 C mobo: 27.8 C gpu: radeon temp: 38.0 C
Fan Speeds (RPM): N/A
Repos:
[redacted, due to posting limits]
Info:
Processes: 269 Uptime: 3h 18m Memory: 10.65 GiB used: 3.55 GiB (33.4%) Init: systemd v: 249
runlevel: 5 Compilers: gcc: 11.3.0 alt: 11 Client: Unknown python client inxi: 3.3.13