lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On 18/11/2010, at 6:57 PM, Lorenzo Donati wrote:
> 
> I've searched the internet for PEG and LPEG, but everything I found was rather heavy on the Computer Science side. 

You may possibly find this useful:

http://gammon.com.au/forum/?id=10533

On that page (a little way down) is around 60 lines of LPEG which is designed to parse the JSON grammar. I basically wrote that by looking at the BNF specs for JSON and just turning each line into LPEG - something surprisingly easy to do. It certainly isn't perfect, but to illustrate LPEG in a fairly short example, might be helpful.


Also, on this page:

http://gammon.com.au/forum/?id=10155&page=3

... there is a smallish LPEG grammar written by someone else (Willfa), designed to parse something like "six million three hundred forty five thousand nine hundred twenty three" into a simple number. And on the next page of that thread is a modified version which uses the bc library to handle larger numbers.


Finally on this page:

http://gammon.com.au/forum/?id=8683

I wrote there some introductory remarks about LPEG, with short examples aimed at players of MUD games. Examples there parse things like "You see exits leading north, up, down, west and south".


- Nick Gammon