Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

[Caml-list] [ANN] CCSS 1.0

2 views
Skip to first unread message

Dario Teixeira

unread,
Mar 10, 2010, 2:16:59 PM3/10/10
to caml...@yquem.inria.fr
Hi,

CCSS is a preprocessor for CSS (Cascading Style Sheets), extending the
language with arithmetic operations and variables. It was born out of
frustration with the unbearable slowness and lack of support for some
CSS3 constructs in other similar tools such as LESS [1]. Here are
some points to be aware:

- The CSS source is actually parsed into an AST, which is then converted
again into a CSS textual representation for output. You can therefore
use it as a pretty-printer. On the downside, comments are stripped out.

- Because it is an actual parser, it is fairly straightforward to hack
your own custom transformations to the AST. The scanner is Ulex-based,
whereas Menhir is required for building the parser.

- CCSS knows only of CSS syntax, and has no knowledge of actual CSS
properties and valid values for each. This simplifies the program
and makes it future-compatible, but also means that will gleefully
accept nonsensical CSS properties such as the following:

h1 {foo: bar;}

- The scanner/parser does not cover some of the hairy corners of CSS.
It does however handle new syntactic constructs introduced with CSS3.

- The arithmetic operations are unit-aware, and will complain if you
try adding apples and oranges, for example.


Examples of use and the syntax for the language extensions are described
in the project's homepage, which also includes building instructions and
download links [2]. Note that the source-code is released under the terms
of the GNU GPL v2.

Last, but not least, though no particular attention was given to performance,
it does fulfill the initial goal of making execution time as close to zero
as not to get in the way...

Hope you find it useful -- feedback is welcome!

Best regards,
Dario Teixeira


[1] http://lesscss.org/index.html
[2] http://ccss.forge.ocamlcore.org/

_______________________________________________
Caml-list mailing list. Subscription management:
http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
Archives: http://caml.inria.fr
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs

Daniel Bünzli

unread,
Mar 10, 2010, 4:09:36 PM3/10/10
to Dario Teixeira, caml...@yquem.inria.fr
Hello Dario,

> CCSS is a preprocessor for CSS (Cascading Style Sheets), extending the
> language with arithmetic operations and variables.

Yes, that's badly missing in CSS.

>  - The arithmetic operations are unit-aware, and will complain if you
>   try adding apples and oranges, for example.

Unit aware is good but the classes should be broader. I find it
disappointing that it won't allow you to add mm to cm correctly, since
it's supposed to be unit aware.

In CSS there are two kinds of units : relative and absolutes ones [1].
Each relative one should be in a different class as there are no known
conversion function between them (they depend on font metrics or on
the display). But all the absolute ones should be in the same class
and arithmetic between them should be performed correctly since the
conversion functions are known. I would thus suggest the following
incompatible classes of unit of measure :

* em
* ex
* px
* in, mm, cm, pt, pc

You'll need a convention for the unit of the result of an expression
with different absolute dimensions. A good way of achieving that would
be to use the unit of the leftmost term in the parse tree of the
expression, that way if you need to you can always get the unit you
want by writing e.g. 0mm + (exp).

>From a user perspective, it makes it much easier to copy paste
snippets from here and there without having to bother to normalize
every length to a single unit.

Other than that, the syntax you chose blends well with css.

Best,

Daniel

[1] http://www.w3.org/TR/CSS21/syndata.html#length-units

Dario Teixeira

unread,
Mar 11, 2010, 8:34:47 AM3/11/10
to Daniel Bünzli, caml...@yquem.inria.fr
Hi,

> Unit aware is good but the classes should be broader. I find it
> disappointing that it won't allow you to add mm to cm correctly, since
> it's supposed to be unit aware.

It's unit-aware in the sense that it knows that numeric values may have
this thing called "units" attached, and they impose some constraints on
arithmetic, but it knows nothing about the semantics and relation between
units.

I understand why you may see this as a bug, but for me it's a feature.
Personal experience tells me that mixing units -- even if they belong
to the same system, as cm and mm -- is asking for trouble (never mind
mixing units from metric and imperial -- ask NASA).

While CCSS has no intention of being a CSS-lint, it does enforce a couple
of good-practices constraints. Forbidding unit mixing is one of them;
another is ensuring each property declaration is terminated by a semicolon,
even if it's the last one: again, experience tells me that omitting it
is asking for trouble.


> From a user perspective, it makes it much easier to copy paste
> snippets from here and there without having to bother to normalize
> every length to a single unit.

That will be a good point if CCSS ever becomes popular and you wish
to copy'n'paste CSS fragments augmented with its syntax. But presently
that's a moot point, since the CSS fragments you find in the wild are not
augmented with variable declarations and/or arithmetic.

But anyway, if you really think unit conversion is a must-have feature,
I can add it to the next release (it's actually simple to implement).
However, personally I remain sceptical about its real-world usefulness.

Best regards,
Dario Teixeira

Daniel Bünzli

unread,
Mar 11, 2010, 9:54:49 AM3/11/10
to Dario Teixeira, caml...@yquem.inria.fr
> I understand why you may see this as a bug, but for me it's a feature.
> Personal experience tells me that mixing units -- even if they belong
> to the same system, as cm and mm -- is asking for trouble (never mind
> mixing units from metric and imperial -- ask NASA).

Well you're not in a NASA case since all the data is tagged correctly.

> But anyway, if you really think unit conversion is a must-have feature,
> I can add it to the next release (it's actually simple to implement).
> However, personally I remain sceptical about its real-world usefulness.

For the web I anyway use more relative lengths than absolute ones. I
don't know if it's a must have feature however I can see that being
annoying if you have to do an absolute layout (e.g. for print).

The problem is that different kind of objects naturally use different
kind of units.
A font size or line height for example is usually expressed in pts and
a standard paper or photographic print size will be in cms (or
inches).

Having to use a calculator to add them just feels wrong and makes the
resulting stylesheet less readable : if I see 210mm x 297mm I
recognize quite easily A4, however if I see 595.275591pt x
841.889764pt, well, no. Conversely a value in pt for a line height or
font size will give me a better idea of the typographical result than
a value in mm.

Best,

Daniel

P.S.
I know about metric typographic units [1] but somehow they didn't
catch and most people still think in pts in typography.

[1] http://www.cl.cam.ac.uk/~mgk25/metric-typo/

Dario Teixeira

unread,
Mar 11, 2010, 2:01:01 PM3/11/10
to Daniel Bünzli, caml...@yquem.inria.fr
Hi,

> The problem is that different kind of objects naturally use different
> kind of units. A font size or line height for example is usually
> expressed in pts and a standard paper or photographic print size will
> be in cms (or inches).

Sure, and nothing stops you from using those different units in different
contexts. CCSS only constrains you if you try doing *arithmetic* with
those units, which I posit should rarely be an issue, precisely because
they live in different contexts.

But anyway, I've implemented unit conversion, which you can find in SVN [1].
In the next release this feature may be activated at user discretion.

Units are divided into four categories, and units within the same category
may be mixed. The result gets the same unit as the first operand. The
categories are as follows:

length: mm, cm, in, pt, pc
angle: deg, grad, rad
time: ms, s
frequency: hz, khz

In the following example, the output for all properties will be "2in":

h1
{
foo1: 1in + 1in;
foo2: 1in + 2.54cm;
foo3: 1in + 25.4mm;
foo4: 1in + 72pt;
foo5: 1in + 6pc;
}


Best regards,
Dario Teixeira

[1] http://forge.ocamlcore.org/scm/viewvc.php/?root=ccss

Daniel Bünzli

unread,
Mar 12, 2010, 8:10:13 AM3/12/10
to Dario Teixeira, caml...@yquem.inria.fr
> which I posit should rarely be an issue, precisely because
> they live in different contexts.

Example, a box whose height is a picture followed by three lines of text.

> But anyway, I've implemented unit conversion, which you can find in SVN [1].
> In the next release this feature may be activated at user discretion.

Great, thanks.

Daniel

Dario Teixeira

unread,
Mar 12, 2010, 10:44:17 AM3/12/10
to Daniel Bünzli, caml...@yquem.inria.fr
Hi,

In the meantime I've released version 1.1, which includes the requested
unit conversion feature. It works as I described in a previous email,
but is not activated by default. If you really need this feature, simply
provide option '--convert' (short version '-c') upon command line invocation.

For more information: http://ccss.forge.ocamlcore.org/

Hope you find it useful!
Best regards,
Dario Teixeira

0 new messages