kschiess / parslet

A small PEG based parser library. See the Hacking page in the Wiki as well.
kschiess.github.com/parslet
MIT License
809 stars 95 forks source link

Added Parslet::Slice#length, a la #size. #120

Closed postmodern closed 9 years ago

postmodern commented 9 years ago

Add a #length method to complement #size.

kschiess commented 9 years ago

As an alias to size? What is the goal of this?

postmodern commented 9 years ago

MRI's String aliases the two, so I guess an alias is fine. Have you thought of using Forwardable to expose all String methods?

jmettraux commented 9 years ago

I think the goal is to accommodate people who call #length on their strings, arrays and socks instead of #size. Granted, people say "big slice" but not "long slice", but since a Parslet::Slice is a segment of a string somehow, "length" feels right.

postmodern commented 9 years ago

Just to clarify, are parslet users encourages to coerce Slices back into Strings, or leave them as Slices?

kschiess commented 9 years ago

Love you guys - you just preempted all the discussion on the matter ;)

Slices are supposed to be string-like - but will never become strings, otherwise I would have opted for subclassing String. They are somewhat 'frozen' strings; for any real use, you should cast them to other data types. And since we have size and since .. matz thought variety was good, here goes:

Can you change the code of #length into just aliasing #size? I want to press the green button on this one, but can't right now ;)

postmodern commented 9 years ago

Amended and force pushed.