The idea of parsing a language with regexp is amiss from the start.
Translating spaces away - what if they are inside a string? Modifying string literals is bad. If your next thought is to start detecting strings with your regexp, you are starting down a dark and evil path that leads nowhere good.
On Mon, May 21, 2012 at 2:25 AM, David H <[address removed]>
This is more of a regex inquiry, but it's in a Ruby context; I'm
working on porting* jsmin form C to a much smaller Ruby script and
using regex to do it. Currently, I'm attempting to do a conditional
replace of spaces according to Crockford's spec
"It omits spaces except when a space is preceded and followed by a
non-ASCII character or by an ASCII letter or digit, or by one of these
characters: \ $ _"
I figured this bit would take care of that:
compressed_js = uncompressed_js.gsub(/[^[\x20-\x7Ea-zA-Z0-9\$\\_]]
|match| match.gsub(/ /, "")
I suspect that the regex itself might be checking for an OR condition
instead of the AND described in the spec. Would anyone know if that or
something else may be amis?
* Porting the minification parts without the syntax checking parts,
and adding support for combining multiple .js files into a single
bundle of fun. Code-in-progress here:
Love and kittens,
david [.dh] huerta
Please Note: If you hit "REPLY", your message will be sent to everyone on this mailing list ([address removed])
This message was sent by David H ([address removed]) from NYC Rubyist Roundtable.
To learn more about David H, visit his/her member profile: http://www.meetup.com/nycruby/members/2144607/
Set my mailing list to email me
As they are sent
In one daily email
Don't send me mailing list messages
Meetup, PO Box 4668 #37895 New York, New York[masked] | [address removed]