ambiguous first argument?

R

Roger Pack

Hi all.
With this code:

memory_bitmap.scan /\x00{5}+/

I get this warning:

test.rb:1: warning: ambiguous first argument; put parentheses or even
spaces

Could somebody please help me to understand what exactly is ambiguous
there?
Thank you!
-r
 
R

Ryan Davis

Hi all.
With this code:

memory_bitmap.scan /\x00{5}+/

I get this warning:

test.rb:1: warning: ambiguous first argument; put parentheses or even
spaces

Could somebody please help me to understand what exactly is ambiguous
there?

2 / 2

2 / 2 /
 
G

Gianfranco Bozzetti

Roger said:
Hi all.
With this code:

memory_bitmap.scan /\x00{5}+/

I get this warning:

test.rb:1: warning: ambiguous first argument; put parentheses or even
spaces

Could somebody please help me to understand what exactly is ambiguous
there?
Thank you!
-r

The ambiguity comes from the double quantifier {5}+ where:
- {5} means exactly 5 occurrences of \x00
- + means 1 or more occurrences of preceding expression.

Given the string:
bitmap="\x30\x50\-\x00\x00\x00\x00\x00\x00\-\x40\x50\x30"

p bitmap.scan(/\x00+/) #=> ["\000\000\000\000\000\000"]
p bitmap.scan(/\x00{2}/) #=> ["\000\000", "\000\000", "\000\000"]

HTH gfb
 
R

Rob Biedenharn

Roger said:
Hi all.
With this code:

memory_bitmap.scan /\x00{5}+/

I get this warning:

test.rb:1: warning: ambiguous first argument; put parentheses or even
spaces

Could somebody please help me to understand what exactly is ambiguous
there?
Thank you!
-r

The ambiguity comes from the double quantifier {5}+ where:
- {5} means exactly 5 occurrences of \x00
- + means 1 or more occurrences of preceding expression.

Given the string:
bitmap="\x30\x50\-\x00\x00\x00\x00\x00\x00\-\x40\x50\x30"

p bitmap.scan(/\x00+/) #=> ["\000\000\000\000\000\000"]
p bitmap.scan(/\x00{2}/) #=> ["\000\000", "\000\000", "\000\000"]

HTH gfb


I think the ambiguity is actually in parsing:

memory_bitmap.scan / \x00 { 5 } + /
Is that perhaps dividing by the result of calling \x00 with a block?

Spaces won't help in this case, but some nice parentheses will do.

memory_bitmap.scan(/\x00{5}+/)

That will ensure that the parser sees /\x00{5}+/ as an argument to the
scan method. Whether the Regexp does what you want/expect is another
question.

-Rob

Rob Biedenharn
(e-mail address removed) http://AgileConsultingLLC.com/
(e-mail address removed) http://GaslightSoftware.com/
 
R

Roger Pack

I think the ambiguity is actually in parsing:

memory_bitmap.scan / \x00 { 5 } + /
Is that perhaps dividing by the result of calling \x00 with a block?

Interesting. Ok thanks for all the responses.
It does work as expected :)
-r
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,146
Messages
2,570,832
Members
47,374
Latest member
anuragag27

Latest Threads

Top