develooper Front page | perl.perl6.language | Postings from September 2002

Regex query

Thread Next
From:
Simon Cozens
Date:
September 19, 2002 23:08
Subject:
Regex query
Message ID:
86lm5xry63.fsf@squash.oucs.ox.ac.uk

Well, I've started my Perl 6 programming career already and I've got
stuck. :)

I'm trying to parse a Linux RAID table (/etc/raidtab), which looks a
bit like this:

raiddev /dev/md0
        raid-level              5
        option                  value
        option                  value
        ...

        device          /dev/sde1
        raid-disk       0
        device          /dev/sdf1
        raid-disk       1
        device          /dev/sdg1
        raid-disk       2
        ...

raiddev /dev/md1
        ...

Here's the grammar I have so far:

grammar Raidtab;

rule raidtab { <raiddev>+ };
rule comment { <sp*> \# .* |
               # Or a blank line
               ^^ \n };

rule comm_eol { <sp*> <comment>? <sp*> \n };

rule raiddev { <comment>*
               <sp>* "raiddev" <sp>+ $name := (/dev/md\d+) <comm_eol>
                (<devicelayout> | <option> | <comment>)+ };

rule option  { <sp>* $key := (<[a-z]->+) <sp>* $value := (\w+) <comm_eol> };

rule devicelayout { <sp>* device <sp>+ $name := (/dev/\w+) <comm_eol>
                    <sp>* $type := (raid|spare|parity) -disk <sp>*
                    $index := (\d+) <comm_eol>
                  };

What I can't figure out is how to drill down into the returned match
object and get at individual devices. I'd expect to be able to say
something like

        $matchobject{raiddev}[0]{devicelayout}[1]{name}

and get "/dev/sdf1". Is that how it works, with multiply-matched rules
being put into arrays, or is it stored differently somehow?

-- 
3rd Law of Computing:
	Anything that can go wr
fortune: Segmentation violation -- Core dumped

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About