Re: [nycruby] Ruby/Regex Question

From: Mark C.
Sent on: Monday, May 21, 2012 10:09 AM
Looks like this has been done using mostly Regexp and Ruby already. So, for an example implementation and how someone else solved the problem, check out: https://github.com...­

I'd think that defining the grammar using the treetop ruby gem might lead to a more elegant solution. Or generate a Ruby parser for JSMin with antlr for Ruby. A google search will get you the appropriate tools.

Best of luck!

Regards,

Mark Coates
[@] [address removed]
[?] http://about.me/m...­
--------------------­-
Editor, Rails Magazine

On May 21, 2012, at 2:25 AM, David H <[address removed]> wrote:

> Hey Rubyists,
> 
> 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
> (https://github.com...­):
> 
> "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-Z­0-9\$\\_]]
> [^[\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:
> https://github.com...­
> 
> Love and kittens,
> 
> -- 
> david [.dh] huerta
> davidhuerta.me
> 
> 
> 
> --
> Please Note: If you hit "REPLY", your message will be sent to everyone on this mailing list ([address removed])
> http://www.meetup...­
> 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...­
> Set my mailing list to email me
> 
> As they are sent
> http://www.meetup...­
> 
> In one daily email
> http://www.meetup...­
> 
> Don't send me mailing list messages
> http://www.meetup...­
> Meetup, PO Box 4668 #37895 New York, New York[masked] | [address removed]
> 

Our Sponsors

  • Pivotal Labs

    Pivotal Labs generously donates meeting space.

  • Case Commons

    Case Commons provides food and beverages for the meetup.

  • The Pragmatic Bookshelf

    The Pragmatic Bookshelf donates their top notch books to the meetup.

  • Magnetic

    Magnetic generously hosts Ruby Meetups.

  • O'Reilly Books

    Providing print resources from a variety of publishers

  • Crowdtap

    Generously hosts roundtable discussions.

  • SmartLogic

    SmartLogic makes sure we are neither hungry nor thirsty

  • Big Fuel

    Venue

People in this
Meetup are also in:

Sign up

Meetup members, Log in

By clicking "Sign up" or "Sign up using Facebook", you confirm that you accept our Terms of Service & Privacy Policy