Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: P6: parsing whitespace

by moritz (Cardinal)
on Jun 09, 2010 at 18:01 UTC ( [id://843880]=note: print w/replies, xml ) Need Help??


in reply to P6: parsing whitespace

If you have whitespace in a rule, it is internally replaced by a call to the ws token.

The default ws matches at least one space (\s+) if the left and right are word characters (ie matching \w), and matching zero or more (\s*) otherwise.

In code:

class Grammar { token ws { <!ww> \s* } }

Where ww is within word, and could be defined as

token ww { <after \w> <before \w> }

If you want 8.8x5.0 to match, you need to override the ws rule in your grammar:

grammar Calc { token ws { \s* } # rest of your code here without any modifications

(Update: fixed ww rule after comment from TimToady++)

Perl 6 - links to (nearly) everything that is Perl 6.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://843880]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (5)
As of 2024-03-29 09:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found