lua-users home
lua-l archive

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




On 30/07/16 03:25 AM, Sean Conner wrote:
It was thus said that the Great Soni L. once stated:
   If you want more specific errors, then you can do something like this:

local escape = lpeg.P"\\ "  / " "
              + lpeg.P"\\\\" / "\\"
              + lpeg.P"\\#"  / "#"
              + lpeg.P"\\>"  / ">"
              + lpeg.P"\\"  / ""
              + lpeg.P"\\n"  / "\n"
              + lpeg.P"\\" * lpeg.Cmt(lpeg.Carg(1) * lpeg.C(1),
                                       function(subject,pos,e,c)
                                         table.insert(e,"Bad escape " .. c)
                                         return nil
                                       end)
local char    = lpeg.R(" [","]~")
Right. Does the "utf-8" on the MDXML spec[1] not mean anything to you?
   Right.  Does example code that shows you how one would go about doing it
not mean anythign to you?  Does "then you can do something like this" mean
any thing to you? Do you always expect everything to be handed to you on a
silver plate, complete and working 100% as you would expect them to?  I
almost quit a job because of this attitude [2].

   But FINE!  Here you go!

	-- -----------------------------------------------------------------
	-- And just because YOU asked for it, this is GPL!  If you use this,
	-- you MUST make your code GPL as well.  Oh, is the GPL too
	-- restrictive for you?  So sorry, you asked ME for this code, so I
	-- get to slap whatever license I want on it.
	--
	-- DEAL WITH IT!
	--
	-- And no, I WILL NOT MAKE AN EXCEPTION FOR YOU!
	-- -----------------------------------------------------------------

	local char = lpeg.R(" [","]~")
                    + lpeg.R("\194\223") * lpeg.R("\128\191")
                    + lpeg.P("\224")     * lpeg.R("\160\191") * lpeg.R("\128\191")
                    + lpeg.R("\225\236") * lpeg.R("\128\191") * lpeg.R("\128\191")
                    + lpeg.P("\237")     * lpeg.R("\128\159") * lpeg.R("\128\191")
                    + lpeg.R("\238\239") * lpeg.R("\128\191") * lpeg.R("\128\191")
                    + lpeg.P("\240")     * lpeg.R("\144\191") * lpeg.R("\128\191") * lpeg.R("\128\191")
                    + lpeg.R("\241\243") * lpeg.R("\128\191") * lpeg.R("\128\191") * lpeg.R("\128\191")
                    + lpeg.P("\224")     * lpeg.R("\128\142") * lpeg.R("\128\191") * lpeg.R("\128\191")
That's even more overcomplicated than the previous example.

My point wasn't to overcomplicate it, it was to simplify it. E.g.

local char = 1 - lpeg.S("\\") (because this handles literally every possible use-case, including nonprintables)

   But to further clarify---this attitude of yours, this "this isn't doing
exactly what I want" is making it hard for me to even bother answering your
questions.

   I'm using lpeg.Carg() to pass in a table to accumulate the errors (this
keeps this reentrant).  lpeg.Cmt() does a match-time capture and if this
returns nil, then that particular capture fails.  I've set up this example
such that if cleanup returns nil, then the passed in table will contain the
error.
I see. I'd still prefer :match itself to emit nil, errmsg with a
dynamically generated errmsg.
   Yeah, and I'd prefer you would do your own damn homework too!

   -spc (I'm beginning to come around to Dirk's point of view---is it too
	hard to say "Thank you" and work to adapt the code to your project?)

[1]	Not my footnote

[2]	The "YOU #$@#$@# FAILED TO READ MY MIND AND IMPLEMENT THE CODE AS I
	WOULD HAVE, YOU @#@$#@$#@ WORK SLAVE!" attitude.

	Sorry, ... no, I'm not sorry.  I gave you an example, and you @#$@#$
	threw it back in my face for not doing everything you deemed
	necessary.


My post clearly indicated I wanted to replace a specific error() call with something that made :match() return nil, errmsg.

Your first solution returns a fixed error message, which is not what was asked.

Your second solution uses Carg(1). Last time I used Carg(1) I had issues getting it to do what I wanted, but as soon as I got rid of it everything worked like a charm.

I don't know how to use LPeg. That's the reason why I'm asking here. I tried to write the whole parser in LPeg but I couldn't get that to work (I also couldn't understand any of it) so I went with a simpler approach by using LPeg as a tokenizer of sorts.

I "threw it back in [your] face" because I don't understand it.

--
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.