lua-users home
lua-l archive

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


On Wed, 16 Aug 2023 at 12:20, Sean Conner <sean@conman.org> wrote:
> (...)

Hi Sean,

> I don't see these as different, due to the fact that
>
>         (a * b) * c     =       a * (b * c)

try this:

  foo = function (str) return setmetatable({str}, foo_mt) end
  foo_mt = {
    __tostring = function (a) return a[1] end,
    __mul = function (a,b) return foo(format("(%s%s)", a[1], b[1])) end,
  }
  = (foo"a" * foo"b") * foo"c"   --> "((ab)c)"
  = foo"a" * (foo"b" * foo"c")   --> "(a(bc))"

The associativity of the multiplication in Lua is not a "fact".

> These are expressions ... what's a "subpattern"?  Again,
>
>       (a * b) * c     =       a * (b * c)

Is that a honest question?

Here's a way to define subpatterns by analogy. We all know how to
build bigger expressions from basic expressions, and after learning
how to do that we all learned what are subexpressions, but most of us
never saw a formal definition of "subexpression". Similarly, we "all"
know what are basic (lpeg) patterns, and we "all" know how to build
bigger (lpeg) patterns from basic (lpeg) patterns. Most of us know what
are sub-(lpeg)-patterns by analogy with subexpressions...

> For me, they cloud the issue. To me, a capture captures the text of
> a pattern, and possibly transforms it. For example:

Makes sense, but most of the lpeg patterns that _I_ wrote in the last
year or so transform the original text in ways that are very complex,
and most of the captures that appear in the intermediate steps of _my_
transformations are tables, ASTs, or numbers... and that's why _right
now_ _I_'m not interested in the basic cases in which lpeg captures
simply capture text and transform text - my priority now is to
understand some obscure features and corner cases...

  Cheers,
    Eduardo