books-programmingLanguages-programmingLanguagesChMatchingParsingAndStyling

Table of Contents for Programming Languages: a survey

Regular expressions

not Turing-complete

and their more powerful cousins, PCRE without embedded code, also not Turing-complete

Grammars

(note: can be Turing complete)

see Chapter ? in Part ? Formal for the Chomsky hierarchy, which unifies sub-turing grammars and regular expressions and Turing-complete languages into a hierachy.

CSS

Selectors

Selectors are predicates that match certain nodes in an HTML DOM.

adding :pred, where 'pred' is one of the defined primitive predicates (called 'pseudo-classes') to the end of a selector imposes a condition. You can add multiple :s; this is a boolean AND of those predicates.

Some pseudo-classes are quite expressive; consider :nth-child(3n + 1), which takes an arithmetical expression arguments, and :last-child.

You can combine multiple selectors with commas in between them; this is a boolean OR of those selectors.

There are a few selector 'combinators', such as +, which is a binary infix operator which takes two selectors as input and says 'match something that matches my right argument if it is immediately preceded by something that matches my left argument'.

Example

The following example, from http://www.heydonworks.com/article/tetris-the-power-of-css , assumes we have a 3-column grid; if the last row has only one item, it make that item fill the row; if the last column has two items, it makes them each fill half the row.

li:nth-child(3n + 1):last-child {
   float: none;
   width: auto;
}

li:nth-child(3n + 1):nth-last-child(2), 
li:nth-child(3n + 1):nth-last-child(2) + li {
   width: 50%;
}

Links

SASS

LESS