lua-users home
lua-l archive

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

It was thus said that the Great Andrew Starks once stated:
> On Tue, May 27, 2014 at 5:47 AM, Bas Groothedde <> wrote:
> >  On 27.05.2014 09:44, steve donovan wrote:
> >
> > On Tue, May 27, 2014 at 5:06 AM, Coda Highland <> 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:

	  border:	1px solid black;
	  padding:	1em;
	  text-align:	justify;
	  color:	purple;

is easy enough to do, you start hitting corner cases quite fast.  For

	  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

	DIV > OL LI P[lang="de"] > SPAN + SPAN:hover,
	DIV > UL > + 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.