[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Lua CSS parser?
- From: Sean Conner <sean@...>
- Date: Tue, 27 May 2014 12:20:49 -0400
It was thus said that the Great Andrew Starks once stated:
> On Tue, May 27, 2014 at 5:47 AM, Bas Groothedde <lua@xoru.net> wrote:
>
> > On 27.05.2014 09:44, steve donovan wrote:
> >
> > On Tue, May 27, 2014 at 5:06 AM, Coda Highland <chighland@gmail.com> wrote:
> >
> > The good news is that CSS syntax is very simple -- I think it may even be
> > a regular language. It should be pretty darn easy to write an lpeg parser
> > for it.
> >
> > Yep, also thought this is a job for Captain LPeg - although it's more
> > tricky than at first sight.
> >
> > But, the question is, what parsed representation does the OP need, and
> > for what purpose?
> >
> >
> > I would need something like a hierarchical table in which I could lookup
> > the specified CSS attributes and their values, so that I can extract them
> > for specific elements and apply them in a non-HTML environment. It's for a
> > customizable canvas-like drawing area.
>
> I think I'm stating the obvious, but a parser might not be what you want.
> That is, a parser tell you if its proper syntax, but knowing what the scope
> of a property or a selector is for CSS is incredibly complicated, IMHO.
> It's something that I'd like to have some day as well. [1]
> So... are you trying to answer: "This element has what attributes?" or
> "This CSS declaration applies to what?" or both? I guess those are two
> approaches to the same thing... How complete do you need to be?
I was thinking a bit about this on the way to work, and yes, it's a
nightmare. Sure, something like:
P
{
border: 1px solid black;
padding: 1em;
text-align: justify;
color: purple;
}
is easy enough to do, you start hitting corner cases quite fast. For
instance:
P
{
border-top: 3px dashed pink;
border: thick solid black;
text-align: right;
color: limegreen;
}
which sets the top border to pink and the three remaining borders to black
(because border-top is more specific than border, and CSS stands for
Cascading Style Sheets). This compilicates the parser a bit. But the
following:
DIV > OL LI P[lang="de"]:first-child.foo > SPAN + SPAN:hover,
DIV > UL > P:hover:first-child.bar + P[lang="en"] > SPAN
{
border-top: 3x dashed pink;
border-bottom: thick solid orange;
border-left: none
border-right: none
border: 34px solid black; /* why is this even here then? */
text-align: left;
color: mint;
}
is legal (and before you say no sane person would actually write the above,
there's some saying I can't quite find that states that if it's possible, it
will exist in some codebase somewhere).
-spc (I had little desire to parse CSS before, now I have even less)
> [1]When I sit back and contemplate what that would take, it makes me have
> sympathy for web browser designers, which is something that I try not to
> have, given the pain and torture that was the status quo from 96-2011-ish.