Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling

Comment on

( #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, ' $ ', $; 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

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

  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?

    What's my password?
    Create A New User
    and all is quiet...

    How do I use this? | Other CB clients
    Other Users?
    Others cooling their heels in the Monastery: (4)
    As of 2018-02-22 05:27 GMT
    Find Nodes?
      Voting Booth?
      When it is dark outside I am happiest to see ...

      Results (288 votes). Check out past polls.