Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

A CSS parser written in OCaml

License

NotificationsYou must be signed in to change notification settings

astrada/ocaml-css-parser

Repository files navigation

A CSS parser written in OCaml.

Parses a CSS string and produces an AST.

Build

npm install -g esyesy# to build and run testsesy dune runtest

Example

let css={|  {color:red!important;width:100%;  }|}inlet ast=Css.Parser.parse_stylesheet cssin(* 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 availableto the parser. An exception is made for significant whitespaces in rulepreludes, to disambiguate between selectors likep :first-child andp:first-child. These whitespaces are replaced with* to keep CSS semanticsintact. So, e.g.,p :first-child is parsed asp *:first-child,p .classasp *.class, andp #id asp *#id.

About

A CSS parser written in OCaml

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors4

  •  
  •  
  •  
  •  

[8]ページ先頭

©2009-2025 Movatter.jp