Re: lookahead ?

[email protected] (Damian Conway)
Newsgroups perl.recdescent
Message-ID <[email protected]>
> 
   > Ok, now the line I'm trying to deal with is "some amount of whitespace,
   > then some text, then starting at column 48 a number, followed by a period,
   > followed by another number".  I want to capture the text (the "title"),
   > and the two numbers (major and minor versions):
   > 
   > line: title // <reject: $thiscolumn != 48> major \. minor
   > 
   > title: ??WHAT GOES HERE??
   > major: digits
   > minor: digits
   > 
   > digits: /\d+/
   > 
   > In a regex(p)?, I think I'd know what to do: positive lookahead on the
   > whitespace:
   > 
   > my ($title, $major, $minor) =
   >     $line =~ m/^\s*        # leading whitespace
   > 	      (.*?)        # the title
   >               (?:\s+(?=\d+\.\d+\s*$)) # the space preceeding the numbers
   >               (\d+)        # the major version number
   >               \.
   >               (\d+)        # the minor version number
   > 	      /x;
   > 
   > Can I accomplish this in a RD grammer without changing <skip:> ?

You really do want to use a regex here (to get the lookahead/backtracking
that RecDescent doesn't do).

   line: m/^(\s*        		# leading whitespace
   	      (.*?)        		# the title
              (?:\s+(?=\d+\.\d+\s*$)) 	# the space preceeding the numbers
	    )
            (\d+)        		# the major version number
            \.
            (\d+)        		# the minor version number
	 /x
	 <reject: length $1 != 47>
	 { @{$return}{title major minor)} = ($2,$3,$4) }


Damian
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.