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
1
vote
0 answers

Opening and closing elements in LPEG for Pandoc Reader

I am working on a simple Pandoc reader that can process some of the basic html-like syntax used in forums (such as [b]bold[/b] and [h1]Header[/h1]). I managed to get a basic reader working with LPEG (as described in the pandoc documentation), but…
iUknwn
  • 322
  • 2
  • 9
1
vote
0 answers

LPEG - "Rule may be left-recursive" error, despite being a terminable grammar

I'm trying to use LPEG to build a preprocessor for GLSL. I've managed to get #define and #undef statements working no problem, but my issues comes when trying to work with #ifdef statements. My thought was that I could build a rule that would…
Hoeloe
  • 650
  • 4
  • 21
1
vote
2 answers

How to match efficiently against keys in a table in Lua?

Available in my Lua 5.1 environment are obviously the default Lua pattern matching, but also a reasonably recent version of PCRE and LPEG. I don't honestly care which of these is used; as long as my problem is tackled in an efficient manner I'm…
Stigma
  • 1,686
  • 13
  • 27
1
vote
2 answers

Case-insensitive matching in LPeg.re (Lua)

I'm new to the "LPeg" and "re" modules of Lua, currently I want to write a pattern based on following rules: Match the string that starts with "gv_$/gv$/v$/v_$/x$/xv$/dba_/all_/cdb_", and the prefix "SYS.%s*" or "PUBLIC.%s*" is optional The string…
Tyler
  • 185
  • 5
1
vote
4 answers

Can I create a gmatch pattern that returns a variadic number of values?

I need to iterate over some pairs of strings in a program that I am writing. Instead of putting the string pairs in a big table-of-tables, I am putting them all in a single string, because I think the end result is easier to read: function…
hugomg
  • 68,213
  • 24
  • 160
  • 246
1
vote
3 answers

Matching a string with a specific end in LPeg

I'm trying to capture a string with a combination of a's and b's but always ending with b. In other words: local patt = S'ab'^0 * P'b' matching aaab and bbabb but not aaa or bba. The above however does not match anything. Is this because S'ab'^0 is…
Luis
  • 1,210
  • 2
  • 11
  • 24
1
vote
2 answers

Changing the return order of captures in an LPeg pattern?

(I'm using Lua 5.2 and LPeg 0.12) Suppose I have a pattern P that produces some indeterminate number of captures, if any, and I want to write create a pattern Q that captures P as well as the position after P--but for that position to be returned…
Evelyn Kokemoor
  • 326
  • 1
  • 9
1
vote
1 answer

Lua lunadry error

I've been using lunadry to reformat my code for me, but I've run into errors, namely, this happens when I try it: lua: ./lunadry.lua:322: assertion failed! stack traceback: [C]: in function 'assert' ./lunadry.lua:322: in main chunk [C]:…
Jonathan Picazo
  • 975
  • 3
  • 13
  • 23
0
votes
1 answer

LPeg how to match an odd integer?

R"09"^0 * S"13579" does not work because R"09"^0 will consume all digits and S"13579" will have nothing to match.
0
votes
1 answer

How to write a peg used in lpeg to parse lua itself?

As title say, I know lua has a offical extended BNF in The Complete Syntax of Lua. I want to write a PEG to pass to lpeg.re.compile to parse lua itself. Maybe the Lua PEG is something like it's BNF. I have read the BNF and try to translate it to a…
rangercyh
  • 37
  • 4
0
votes
2 answers

lua lpeg expression to not sub in between delimeters

I would like to understand how I could lpeg to replace strings if they are NOT between a certain start and end delimiter. Below is an example, where I would like to use SKIPstart and SKIPstop to signify where text shouldn't be…
likethevegetable
  • 264
  • 1
  • 4
  • 17
0
votes
1 answer

How to start writing an expression evaluator using LPEG in Lua?

For example, I pass an expression string and a context table and it return a boolean value whether it was true/false. Can I do this using LPEG? Something similar to this: context = { x = 3, y = 3 } local result = eval("x==y", context)
Anon
  • 116
  • 2
  • 6
0
votes
1 answer

lpeg grammar to parse comma separated groups that may have internal groups

I need to parse comma separated groups(enclosed in brackets) that may have internal groups inside the groups. It should only separate the outside groups. I have a function that does this: function lpeg.commaSplit(arg) local P,C,V,sep = lpeg.P,…
Uiy
  • 165
  • 1
  • 9
1 2
3