GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - astrada/ocaml-css-parser: A CSS parser written in OCaml

BranchesTags
Open more actions menu

Latest commit

 

History

26 Commits
26 Commits

Folders and files

NameName
Last commit message
Last commit date
.github/workflows
.github/workflows
 
 
esy.lock
esy.lock
 
 
lib
lib
 
 
test
test
 
 
.gitignore
.gitignore
 
 
.ocamlformat
.ocamlformat
 
 
.travis.yml
.travis.yml
 
 
LICENSE
LICENSE
 
 
README.md
README.md
 
 
css-parser.opam
css-parser.opam
 
 
dune
dune
 
 
dune-project
dune-project
 
 
package.json
package.json
 
 

Repository files navigation

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.

About

A CSS parser written in OCaml

Topics

cssocamlparser

Resources

Readme
MIT license
Activity

Stars

31 stars

Watchers

4 watching

Forks

5 forks
Report repository

Releases

Packages

Used by

Contributors

Languages

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.