lua-users home
lua-l archive

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




On 05/07/16 09:37 PM, Sean Conner wrote:
It was thus said that the Great Soni L. once stated:
On 05/07/16 06:34 PM, Sean Conner wrote:
It was thus said that the Great Soni L. once stated:
Too bad it's not pure LPeg, instead deferring to a Lua function for it.
   What?  Is not lpeg.Cf() LPeg, just because it accepts a Lua function as
   a parameter?  So,

	lpeg.R"09" / { ['o'] = 0 , ['1'] = 1 , ['2'] = 2 ... }

is fine, but not?

	lpeg.R"09" / tonumber

   If LPeg allows it, it's LPeg.

   But okay, fine!  If you restrict the domain to single digits, then:

	  lpeg.P"0+0" * lpeg.Cc(0)
	+ lpeg.P"0+1" * lpeg.Cc(1)
	+ lpeg.P"0+2" * lpeg.Cc(2)
	+ lpeg.P"0+3" * lpeg.Cc(3)
	... and so on.  Go crazy with this.
The goal is to never run Lua code for it. Perl regex can run Perl code,
but the linked math-with-regex thingy doesn't use that and that's the
whole point. If someone ports LPeg to a different programming language,
a LPeg that calls Lua code will stop working.
   That was never specified as a limititation in your initial post.
No, but it is mentioned in the linked stackoverflow question. You should read the full context before replying.

Also, if this was a codegolf or programming puzzle and you weren't
allowed to use the language's built-in addition subtraction etc, you
could do it with regex instead.
   If this was a codegolf or programming puzzle and you weren't allowed to
use the languages's built-in addition subtraction etc, you wouldn't be
*ABLE* to do this using LPeg.  Period.  End of story.  That '*' in the above
example?  That's Lua multiplication operator.
You're mistaking "operation" and "operator". In other languages, "+" is often overloaded for concatenation as well as addition, and in such challenges you're (usually) still allowed to use "+" for concatenation. Also LPeg has a 're' module.

   There exists a PEG generator for C [1], but none of the examples would
work in LPeg, mainly because of the embedded C code.
Yes, that's why you remove any sort of embedded <insert language here> code.

   LPeg (and PEGs in general) are not regular expressions, although they can
be used where one would use a regex (the reverse is not true).

   -spc (You couldn't even port it to C++ because the ^ and ~ operators
	differ between Lua and C++ and thus the precedence rules would be
	out of wack ... )
You don't have to use operator overloading to use PEGs.

[1]	http://piumarta.com/software/peg/


--
Disclaimer: these emails may be made public at any given time, with or without reason. If you don't agree with this, DO NOT REPLY.