Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Matching css comments /* - not sure if this is a bug or my ignorance #72

Closed
zmoazeni opened this issue Mar 16, 2013 · 4 comments
Closed

Comments

@zmoazeni
Copy link
Contributor

Hi there. I'm loving this library.

I'm working with CSS parsing, and I've come across this confusing issue:

 irb
irb(main):001:0> require "parslet"
=> true
irb(main):002:0> Parslet.match('\*').parse('*')
=> "*"@0
irb(main):003:0> Parslet.match('/').parse('/')
=> "/"@0
irb(main):004:0> Parslet.match('/\*').parse('/*')
Parslet::ParseFailed: Don't know what to do with "*" at line 1 char 2.
        from /Users/zmoazeni/.rbenv/versions/1.9.3-p385/lib/ruby/gems/1.9.1/gems/parslet-1.5.0/lib/parslet/cause.rb:63:in `raise'
        from /Users/zmoazeni/.rbenv/versions/1.9.3-p385/lib/ruby/gems/1.9.1/gems/parslet-1.5.0/lib/parslet/atoms/base.rb:46:in `parse'
        from (irb):4
        from /Users/zmoazeni/.rbenv/versions/1.9.3-p385/bin/irb:12:in `<main>'
irb(main):005:0> (Parslet.match('/') >> Parslet.match('\*')).parse('/*')
=> "/*"@0
irb(main):006:0> '/*' =~ Parslet.match('/\*').re
=> 0

Am I doing something boneheaded with combining the regex Parslet.match('/\*') or is this a subtle bug?

@jonathanhefner
Copy link

I'm new to Parslet as well, so I may be wrong on this, but I think match is supposed to match a single character class. For example, you'd get the same error if you wrote Parslet.match('01').parse('01')

If you can give up the regex functionality (and just do exact matching), you could try Parslet.str('/*').parse('/*')

@floere
Copy link
Contributor

floere commented Mar 17, 2013

Hi guys, you are (almost) right – match only works with regular expression strings that match a single character, eg. [a-z], [\n\t]. Like @jonathanhefner said, str seems to be the thing you are looking for. Cheers!

@zmoazeni
Copy link
Contributor Author

Ah thanks for the tip @floere @jonathanhefner. Brainfart on my side.

@floere
Copy link
Contributor

floere commented Mar 18, 2013

I forgot to post a link to the documentation: https://github.com/kschiess/parslet/blob/master/lib/parslet.rb#L126-L146. The code is very well documented in general. Cheers and have fun!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants