types.ml 2.64 KB
Newer Older
1
type expr =
2 3 4
  | Ident of string
  | Strlit of string
  | Uri of string
5 6 7
  | Concat of expr list
  | Number of float * string option
  | Function of string * expr
8
  | Hexcolor of string
9 10
  | Unary of string * expr
  | Nary of string * expr list
11
  | Key_value of string * string * expr
12

13
type declaration = string * expr * bool
14

15 16 17 18 19 20
type selector =
  | No_element
  | All_elements
  | Element of string
  | Id of selector * string
  | Class of selector * string
21
  | Pseudo_class of selector * string * pseudo_class_arg list option
22
  | Pseudo_element of selector * string
23 24
  | Attribute of selector * string * (string * expr) option
  | Combinator of selector * string * selector
25 26 27 28 29 30
and pseudo_class_arg =
  | Nested_selector of selector
  | Nth of nth
and nth =
  | Even | Odd
  | Formula of int * int
31
  (* a and b in an+b *)
32

33 34 35
type media_expr = string * expr option
type media_query = string option * string option * media_expr list

36 37 38 39
type descriptor_declaration = string * expr

type keyframe_ruleset = expr * declaration list

40 41
type supports_declaration = string * expr

42 43 44 45
type condition =
  | Not of condition
  | And of condition list
  | Or of condition list
46
  | Decl of supports_declaration
47 48
  (*XXX: | Enclosed of expr*)

49 50 51
type statement =
  | Ruleset of selector list * declaration list
  (* <selectors> { <declarations> } *)
52
  | Media of media_query list * statement list
53
  (* @media <queries> { <rulesets> } *)
54
  | Import of expr * media_query list
55
  (* @import <target> [<media>]; *)
56 57 58 59
  | Charset of string
  (* @charset "<charset>"; *)
  | Page of string option * declaration list
  (* @page [<pseudo_page>] { <declarations> } *)
60
  | Font_face of descriptor_declaration list
61
  (* @font-face { <declarations> } *)
62
  | Namespace of string option * expr
63
  (* @namespace [<prefix>] "<uri>"; *)
64 65
  | Keyframes of string * string * keyframe_ruleset list
  (* @[-<prefix>-]keyframes <id> { <rulesets> } *)
66 67
  | Supports of condition * statement list
  (* @supports <condition> { <rulesets> } *)
68 69
  | Viewport of string * declaration list
  (* @[-<prefix>-]viewport { <declarations> } *)
70

71 72
type stylesheet = statement list

Taddeüs Kroes's avatar
Taddeüs Kroes committed
73
type box =
74 75 76
  | Expr of expr
  | Declaration of declaration
  | Selector of selector
77
  | Pseudo_class_arg of pseudo_class_arg
78 79 80 81 82 83 84 85 86 87
  | Media_expr of media_expr
  | Media_query of media_query
  | Descriptor_declaration of descriptor_declaration
  | Keyframe_ruleset of keyframe_ruleset
  | Supports_declaration of supports_declaration
  | Condition of condition
  | Statement of statement
  | Stylesheet of stylesheet
  | Clear

88 89
type loc = string * int * int * int * int

90
exception Syntax_error of string
91

92
exception Loc_error of loc * string
93 94

exception Box_error of box * string
95 96

exception Exit_success