[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: pattern nick name table, would it be handy?
- From: Peter Odding <peter@...>
- Date: Tue, 31 May 2011 15:05:12 +0200
> I am using LPEG patterns in a project I am working on.
>
> I was thinking about creating nick names for all the patterns I was
> planning on using and putting them in a table.
>
> For instance, a simple example from PIL, patterns.anyWord = "%a+"
>
> Wouldn't the overhead of creating a table of let's say 100 or so of
> these patterns be minimal? People could just copy and paste the table
> into their code and use the nick name instead of the pattern itself. I
> could find quite a few patterns on the wiki and once I posted the table
> back to the wiki others could add to it?
Sounds like a good idea! I've created such collections of "building
block" patterns myself, though I've been too lazy to put the patterns in
a separate module so I keep copy/pasting them between projects :-(.
Below are some simple examples, inspired by the patterns from <ctype.h>
that I use the most.
local R = lpeg.R
local S = lpeg.S
local upp, low = R'AZ', R'az'
local oct, dec = R'07', R'09'
local hex = dec + R'AF' + R'af'
local letter = upp + low
local alnum = letter + dec + '_'
local endline = S'\r\n\f'
local newline = '\r\n' + endline
- Peter