Questions tagged [lpeg]

LPeg is a pattern-matching library for Lua, based on Parsing Expression Grammars (PEGs).

LPeg is a pattern-matching library for Lua, based on Parsing Expression Grammars (PEGs). It defines patterns as first-class objects that can be composed using regular Lua operators. Its powerful capture mechanisms allows to search, extract and transform strings, following regular expressions or full grammars.

Useful links:

43 questions
3
votes
1 answer

how to use / include lpeg luapeg re module

ATM I'm trying to execute lua files from my application, this works with the basic lua. I'm using a borland compiler (builder 3, just don't ask >.<) Now I'm trying to use lpeg via the re module. I've added the lpeg directory to the LUA_PATH…
confusedandtired
  • 139
  • 1
  • 12
2
votes
2 answers

Transform (cond ? then : else) to ifthenelse(cond,then,else) with lpeg

I'm trying to convert a string like 'a?(b?c:d):e' to another string 'ifthenelse(a,ifthenelse(b,c,d),e)' using the lpeg lua parser. I'm slowly learning how to use lpeg but still I can't find a suitable solution to do this with captures. Any…
cjorssen
  • 877
  • 2
  • 7
  • 22
2
votes
1 answer

How can I write a LPeg pattern that never matches anything?

Is there a way to create an LPeg pattern that always fails to match anything? I'm not talking about matching the empty string, I'm talking about a pattern that always fails so if you put it in an ordered choice it always will fall back to the second…
hugomg
  • 68,213
  • 24
  • 160
  • 246
2
votes
2 answers

Using lpeg to only capture on word boundaries

I've been working on a text editor that uses LPEG to implement syntax highlighting support. Getting things up and running was pretty simple, but I've only done the minimum required. I've defined a bunch of patterns like this: -- Keywords local…
user14038
2
votes
1 answer

How can I signal parsing errors with LPeg?

I'm writing an LPeg-based parser. How can I make it so a parsing error returns nil, errmsg? I know I can use error(), but as far as I know that creates a normal error, not nil, errmsg. The code is pretty long, but the relevant part is this: local…
SoniEx2
  • 1,864
  • 3
  • 27
  • 40
2
votes
1 answer

Lpeg "empty loop in rule" error

Can anyone provide a clear explanation and some simple examples that show this error, apparently related to match-time capture (Cmt) ? I don't understand the only mention that I can find, which is…
sailco12
  • 87
  • 5
2
votes
1 answer

Parsing XML-type file with LPeg re module

I'm trying to learn LPeg's re module and it has been quite an interesting experience, specially since the official documentation is so nice. However there are some topics that seem to be poorly explaned there. For example the named group capture…
Augusto T.
  • 177
  • 7
2
votes
2 answers

Lua word search

How would I go about doing a multiple pattern search in Lua? (I have Lpeg set up). For example, say I'm receiving strings in a row, I'm processing one at a time, captalizing them and calling them msg. Now I want to get msg and check if it has any…
Bernardo Meurer
  • 2,295
  • 5
  • 31
  • 52
2
votes
2 answers

How to build lpeg on windows?

I've downloaded lpeg source code from http://www.inf.puc-rio.br/~roberto/lpeg/lpeg-0.12.tar.gz How to get the dll? I can't do it with the makefile included. I'm using mingw32.
2
votes
2 answers

Matching an optional number in a Lua pattern

I'm parsing the output from the diff3 command and some lines look like this: 1:1,2c 2:0a I am interested in the numbers in the middle. Its either a single number or a pair of numbers separated by commas. With regexes I can capture them both like…
hugomg
  • 68,213
  • 24
  • 160
  • 246
2
votes
1 answer

LPeg Increment for Each Match

I'm making a serialization library for Lua, and I'm using LPeg to parse the string. I've got K/V pairs working (with the key explicitly named), but now I'm going to add auto-indexing. It'll work like so: @"value" @"value2" Will evaluate to { …
Caleb P
  • 341
  • 1
  • 2
  • 15
2
votes
1 answer

Making a Lua pattern case insensitive with LPeg

I have an app that (among other things) supports plain-text searches and searches using Lua patterns. As a convenience, the app supports case-insensitive searches. Here is an image snippet: The code that transforms the given Lua pattern into a…
Stomp
  • 890
  • 1
  • 6
  • 19
1
vote
0 answers

Capturing named pattern inside another pattern

Consider the following lpeg pattern pat = lpeg.C((lpeg.P " ")^0 * lpeg.C(lpeg.R "az") * lpeg.P ".") lpeg.match(lpeg.Ct(pat), " a.") I would like to capture both the full substring and the letter only as two different named patterns, but I have…
MrMobster
  • 1,851
  • 16
  • 25
1
vote
1 answer

Match PEG Pattern surrounded by the same pattern (LPEG)

I'm trying to convert this regex pattern to lpeg: { *(?
Optimum
  • 146
  • 2
  • 11
1
vote
1 answer

Non-greedy search in lpeg without consuming the end match

This was spun off from the comments on this question. As I understand, in the PEG grammar, it's possible to implement a non-greedy search by writing S <- E2 / E1 S (or S = pattern E2 if possible or pattern E1 and continued S). However, I don't want…
iUknwn
  • 322
  • 2
  • 9