Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
#!/home/rir/rakudo/parrot_install/bin/perl6 grammar OP { token TOP { <op>+ } token op { <cop> | <sop> | <bop> } token cop { # constrained <short> <sep> <long> <div> <char>+ } token sop { # string <short> <sep> <long> <div> } token bop { # bool <short> <sep> <long> } token long { \w+ } token short { \w } token char { # XXX Rename flag. Eliminate '_'. \w } rule sep { ':' } rule div { '/' } } my $s = 'a:aaa b:bbb/ c:ccccc/def'; my $match = OP.parse($s); die "failed" unless $match; say '$match<op>: ', $match<op>; say '$match.from: ', $match.from, ' $match.to: ', $match.to; say '$match.chars: ', $match.chars; say '$match.orig: ', $match.orig; say '$match.Str: ', $match.Str; say '$match.ast: ', $match.ast; say '$match.caps: is not found'; say '$match.pos: is not found'; my @array = $match; say '@array = $match; then @array: ['; for @array -> $i { say $i ; } say "]";
I have a match object that doesn't appear to contain what I'd like. The examples, I've found, are not working for me; I find SO5 a bit thick. Attempting this with a grammar is a learning exercise.

In the above, I'd like to grab ops, know their "type" and insert into a hash keyed on the shorts.

Is this arranged correctly to avoid a partial sop matching as a bop?

The input string will be small; should I walk the string or walk the match object? As an exercise, treating the problem like a larger language appeals?

How do I traverse $match?

$match is supposed to work just like $/, yes?

I don't care to capture seps or divs but I would like to abstract the values. Should this be done in the grammar? --by variables?

Be well,
rir -- swimming a sea of sticky voluminous syntax errors all alike


In reply to P6: Beginning grammar by rir

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (3)
As of 2024-04-24 00:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found