[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: [LPeg] How can I signal parsing errors with LPeg?
- From: Sean Conner <sean@...>
- Date: Sat, 30 Jul 2016 02:25:24 -0400
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")
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.