package css-parser

Not available on OCaml 5.5
  1. Overview
  2. Docs
A CSS parser written in OCaml

Install

dune-project
 Dependency

Authors

Maintainers

Sources

v0.2.5.tar.gz
sha256=e0bfecfb4c1abdc928d1253822877fafc6d16129877f59952cd77d60ac932fc4
md5=dfdf7b821957ac719b47adc5abc6678b

Description

Parses a CSS Level 3 string and produces an AST.

Added to opam-repository:

README

ocaml-css-parser

A CSS parser written in OCaml.

Parses a CSS string and produces an AST.

Build

npm install -g esy
esy
# to build and run tests
esy dune runtest

Example

let css =
{|
  {
    color: red !important;
    width: 100%;
  }
|} in
  let ast = Css.Parser.parse_stylesheet css in
  (* ast is a value of type Css.Stylesheet.t defined in lib/types.mli *)
  (* that looks like that:
    ([Rule.Style_rule
        {Style_rule.prelude = ([], Location.none);
         block =
           ([Declaration_list.Declaration
               {Declaration.name = ("color", Location.none);
                  value = ([(Component_value.Ident "blue", Location.none)], Location.none);
                  important = (true, Location.none);
                  loc = Location.none;
                 };
               {Declaration.name = ("width", Location.none);
                  value = ([(Component_value.Percentage "100", Location.none)], Location.none);
                  important = (false, Location.none);
                  loc = Location.none;
                };
            ], Location.none);
         loc = Location.none;
        };
     ], Location.none)
  *)

Remarks

Whitespaces and comments are discarded by the lexer, so they are not available to the parser. An exception is made for significant whitespaces in rule preludes, to disambiguate between selectors like p :first-child and p:first-child. These whitespaces are replaced with * to keep CSS semantics intact. So, e.g., p :first-child is parsed as p *:first-child, p .class as p *.class, and p #id as p *#id.

Dependencies (3)

  1. sedlex >= "2.0" & < "2.4"
  2. menhir >= "20200211"
  3. dune >= "2.4"

Dev Dependencies (1)

  1. alcotest with-test

Optional Dependencies

None

Used by

None

Conflicts

None

Build status

Results of building css-parser with each compiler on check.ci.ocaml.org, run of against opam-repository 7cdc698. All results for this package.

Each result links to its build log. To keep crawlers from overloading the site, build logs require a GitHub sign-in (see ocurrent/opam-health-check). On your first log, GitHub asks you to “Authorize opam-health-check”, the OCurrent app that runs these checks; it sees only your public profile, not your repositories. The sign-in lasts 30 days.

Version OCaml 4.11 OCaml 4.14 OCaml 5.2 OCaml 5.4 OCaml 5.5
0.2.5 (this version) good good n/a n/a n/a
  • good Package successfully built
  • partial One of the dependencies failed to build
  • bad Package failed to build
  • n/a Package is not available in this environment
  • internal Internal failure