Skip to main content

rust_css_parser/validation/compiled/
builtins.rs

1//! Port of `src/validation/compiled/builtins.ts`.
2
3/// the types validated by the code of [`match_property`](crate::validation::match_property::match_property), before
4/// their definition (if any): the compiled matchers call `match_property()` for them (see `Node::Leaf`). the other
5/// types are compiled from their definition. keep in sync with `match_property()` and with its calc() types
6pub const BUILTIN_TYPES: &[&str] = &[
7    "calc-product",
8    "declaration-value",
9    "calc-sum",
10    "an+b",
11    "quote",
12    "display-box",
13    "display-inside",
14    "display-internal",
15    "display-outside",
16    "display-legacy",
17    "content-position",
18    "mf-name",
19    "dashed-ident",
20    "extension-name",
21    "custom-property-name",
22    "namespace-prefix",
23    "ident",
24    "ident-token",
25    "custom-ident",
26    "counter-name",
27    "counter-style-name",
28    "any-value",
29    "unicode-range-token",
30    "hash-token",
31    "string",
32    "wq-name",
33    "number",
34    "zero",
35    "integer",
36    "dimension",
37    "angle",
38    "angle-percentage",
39    "percentage",
40    "length-percentage",
41    "flex",
42    "length",
43    "resolution",
44    "frequency",
45    "decibel",
46    "semitones",
47    "time",
48    "color",
49    "color-function",
50    "type-selector",
51    "compound-selector",
52    "complex-selector",
53    "subclass-selector",
54    "attribute-selector",
55    "complex-selector-unit",
56    "pseudo-compound-selector",
57    "forgiving-relative-selector-list",
58    "complex-selector-list",
59    "function-token",
60    "language-code",
61    "size-feature",
62    "style-feature",
63    "url",
64    "css-type",
65    "dashed-function",
66    "block-contents",
67];
68
69/// the built in types that read the whitespace or the tokens after the value being matched: the compiled matchers
70/// skip the whitespace, the interpreter validates the values of these types
71pub const RAW_TYPES: &[&str] = &[
72    "type-selector",
73    "compound-selector",
74    "complex-selector",
75    "subclass-selector",
76    "attribute-selector",
77    "complex-selector-unit",
78    "pseudo-compound-selector",
79    "forgiving-relative-selector-list",
80    "complex-selector-list",
81    "size-feature",
82    "style-feature",
83    "css-type",
84];
85
86/// true if the type is built in, see [`BUILTIN_TYPES`]
87pub fn is_builtin_type(name: &str) -> bool {
88    BUILTIN_TYPES.contains(&name)
89}
90
91/// true if the type reads the whitespace, see [`RAW_TYPES`]
92pub fn is_raw_type(name: &str) -> bool {
93    RAW_TYPES.contains(&name)
94}