lua-users home
lua-l archive

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

Hello all,

I'm trying to convert a string like


to another string


using the lpeg lua parser. I'm slowly learning how to use lpeg but I
still can't find a suitable solution to do this with capture
substitutions. Any ideas?

Here is what I did so far.

local lpeg = require("lpeg")

local S, P, R = lpeg.S, lpeg.P, lpeg.R
local C, Cc, Ct = lpeg.C, lpeg.Cc, lpeg.Ct
local Cf, Cg, Cs = lpeg.Cf, lpeg.Cg, lpeg.Cs
local V = lpeg.V

local thenop = P("?")
local elseop = P(":")
local openpar = P("(")
local closepar = P(")")
local digit = R("09")
local letter = R("az") + R("AZ")

local parser =
    F = V("E") * (thenop * V("E") * elseop * V("E"))^0,
    E = (letter + digit)^1 + (openpar * V("F") * closepar)
 }) -- * -1 -- Is it needed?

Many thanks in advance.

PS: This is a question I asked a few days ago here
but got no answer (yet).

Best regards