# POLS violation? /\\s\*/ no match at StringScanner end

**URL:** <https://www.ruby-forum.com/t/pols-violation-s-no-match-at-stringscanner-end/55464>\
**Category:** Ruby\
**Created:** [March 21, 2006, 10:51am UTC](https://www.ruby-forum.com/t/pols-violation-s-no-match-at-stringscanner-end/55464 "2006-03-21T10:51:40Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![capnregex](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/59ef9b/32.png) [@capnregex](https://www.ruby-forum.com/u/capnregex)\
**Post date:** [March 21, 2006, 10:51am UTC](https://www.ruby-forum.com/t/pols-violation-s-no-match-at-stringscanner-end/55464/1 "2006-03-21T10:51:40Z")

</div>

Hi,

I’ve been bitten by this discrepancy on some occasions:

irb(main):003:0\> StringScanner.new("").match?(/\s\*/)  
=\> nil  
irb(main):004:0\> /\s\*/ =~ “”  
=\> 0

Running: ruby 1.8.4 (2005-12-24) [i686-linux]

Is it a bug or a feature?! I can see arguments for both sides but for  
me it violates POLS. Opinions?

/Robert

---

<div class="post-metadata">

**Author:** ![capnregex](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/59ef9b/32.png) [@capnregex](https://www.ruby-forum.com/u/capnregex)\
**Post date:** [March 21, 2006, 1:33pm UTC](https://www.ruby-forum.com/t/pols-violation-s-no-match-at-stringscanner-end/55464/2 "2006-03-21T13:33:48Z")

</div>

Robert F. wrote:

> Is it a bug or a feature?! I can see arguments for both sides but for  
> me it violates POLS. Opinions?

I think, if it matches /\s\*/ at end of string, then it should scan it  
too; and then, #eos? would never be true (you could scan /\s\*/ at the  
end infinitly).

---

<div class="post-metadata">

**Author:** ![capnregex](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/59ef9b/32.png) [@capnregex](https://www.ruby-forum.com/u/capnregex)\
**Post date:** [March 21, 2006, 2:09pm UTC](https://www.ruby-forum.com/t/pols-violation-s-no-match-at-stringscanner-end/55464/3 "2006-03-21T14:09:22Z")

</div>

On 3/21/06, Carlos [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > Running: ruby 1.8.4 (2005-12-24) [i686-linux]
> > 
> > Is it a bug or a feature?! I can see arguments for both sides but for  
> > me it violates POLS. Opinions?
> 
> I think, if it matches /\s\*/ at end of string, then it should scan it  
> too; and then, #eos? would never be true (you could scan /\s\*/ at the  
> end infinitly).

My point is that my POLS is that eos? should be true _and_ you should  
be able to scan any regexp that can match empty string infinitely at  
the end. If not the behavior at the end is different than from within  
which means that users need to handle the situation differently  
depending on when such regexps are used.

But my POLS might be “wrong”.

/R

---

<div class="post-metadata">

**Author:** ![capnregex](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/59ef9b/32.png) [@capnregex](https://www.ruby-forum.com/u/capnregex)\
**Post date:** [March 21, 2006, 5:44pm UTC](https://www.ruby-forum.com/t/pols-violation-s-no-match-at-stringscanner-end/55464/4 "2006-03-21T17:44:25Z")

</div>

On Tue, 21 Mar 2006 22:09:18 +0900, Robert F.  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> On 3/21/06, Carlos [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:
> 
> > Robert F. wrote:  
> > [snip]  
> > which means that users need to handle the situation differently  
> > depending on when such regexps are used.

While I can see your point, I don’t see it as a POLS violation:

irb(main):014:0\> lex = StringScanner.new(“”)  
=\> #

The termination condition for a scanner is eos, and I would expect that  
a terminated lexical scanner should consistently _not scan_, regardless  
of  
whether a given pattern (eg, /\s\*/, /\z/, /$/, //) could match at eos.

I do expect a different behaviour between a lexical scanner in the  
middle  
of its input, and one that reached its termination condition.

However, the StringScanner docs aren’t very explicit about this.

> But my POLS might be “wrong”.

ditto 🙂

andrew
