[ragel-users] Capturing subpatterns
Adrian Thurston
thurs... at cs.queensu.ca
Wed Jul 11 17:33:09 UTC 2007
Hello,
This is a feature I've spent some time thinking about. It would end up
being syntactic sugar for
( ( 'Mon' | 'Fri' | 'Sun' ) 'day'? ) >{ m=p; } %{ me=p; }
It seems too trivial to me to deserve it's own syntax. Also, there is
more than one way to do this. Sometimes you may be able to record the
end position on the last character (IE using @).
This may be obvious to Ragel users, but I just want state for the record
that PCRE is a different kind of tool from Ragel. PCRE has an
interpretor that can backtrack through regular expressions (not to be
confused with backtracking through input), whereas Ragel generates
deterministic state machines. They both support nondeterministic
expressions. The difference is that in PCRE nondeterminism can occur at
runtime, whereas in Ragel it is always eliminated at compile time.
Regards,
Adrian
Carlos Antunes wrote:
> HI Adrian,
>
> As promised, here's my request for a capture feature.
>
> I base my request on a similar feature used on PCRE called Named
> Subpatterns. This is useful because it obviates the need to do capture
> byte-by-byte. A typical expression would be (as given in the
> pcrepattern(3) man-page :
>
> (?P<DN>Mon|Fri|Sun)(?:day)?|
> (?P<DN>Tue)(?:sday)?|
> (?P<DN>Wed)(?:nesday)?|
> (?P<DN>Thu)(?:rsday)?|
> (?P<DN>Sat)(?:urday)?
>
> The syntax uses '?' as a modifier to '(' and allows different and
> context-sensitive extensions to its regular meaning. The 'P<name>' is
> the one used for naming capturing subpatterns. (The fact that
> subpatterns in Ragel don't currently do any capturing is of no
> consequence, I would suggest.)
>
> Personally, I think this feature would be very useful as it would make
> the life of the programmer easier.It would facilitate the capture of
> portions of the input stream without relying on byte-by-byte copying.
>
> So, here I am, humbly requesting yet another feature! :)
>
> Thanks!
>
> Carlos
>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 252 bytes
Desc: OpenPGP digital signature
URL: <http://www.colm.net/pipermail/ragel-users/attachments/20070711/70521633/attachment-0001.sig>
More information about the ragel-users
mailing list