parse.bend checks
raw source on the hub · import element-css-syntax@0.1.0.0/parse.bend as Parse
1 import
import Base
Types
type Decl source · line 18 · raw
Data
Decl@prop:String -> @value:String -> Decl
type Rule source · line 21 · raw
Data
Rule@selector:String -> @decls:List<&2, Decl> -> Rule
type M source · line 56 · raw
Data
Where the scanner is: selector text, declarations, an at-rule prelude, an at-rule block (with its brace depth), or a quoted string in declarations.
MSelM
MDeclM
MPreM
MAt@depth:U32 -> @kf:String -> M
MStr@q:Char -> M
MEsc@q:Char -> M
MMSel@q:String -> M
inside
@media q { ... }: its style rules, a quoted string in one, and another at-rule nested in it (skipped as MPre/MAt skip)MMDecl@q:String -> M
MMStr@q:String -> @quote:Char -> M
MMEsc@q:String -> @quote:Char -> M
MMPre@q:String -> M
MMAt@q:String -> @depth:U32 -> M
type St source · line 72 · raw
Data
St@mode:M -> @sel:List<&2, Char> -> @body:List<&2, Char> -> @rules:List<&2, Rule> -> St
type Fr source · line 349 · raw
Data
A block being read: kind 0 a style rule (its resolved selector, its declarations so far reversed, the at-rules wrapping it and their closing braces), 1 a group at-rule (@media, @supports... holding rules), 2 a block copied as written (@keyframes, @font-face...) with its brace depth.
Fr@kind:U32 -> @sel:String -> @decls:List<&2, Char> -> @wrap:String -> @unwrap:String -> @depth:U32 -> Fr
type NS source · line 352 · raw
Data
NS@stack:List<&2, Fr> -> @cur:List<&2, Char> -> @out:List<&2, Char> -> @q:U32 -> @paren:U32 -> @nested:Bool -> NS
Definitions
def rev_str source · line 24 · raw
@cs:List<&2, Char> -> String
def strip_go source · line 31 · raw
@s:String -> @+st:U32 -> @+out:List<&2, Char> -> List<&2, Char>
One fold; st: 0 text, 1 saw '/', 2 inside a comment, 3 inside a comment
after '*'. A comment becomes a single space.
def strip_comments source · line 49 · raw
@s:String -> String
def media_sep source · line 77 · raw
String
Between a media query and the selector it guards (U+0001: no selector or query holds it).
def trim_go source · line 81 · raw
@s:String -> @+on:Bool -> @+out:List<&2, Char> -> List<&2, Char>
Leading whitespace dropped: one fold, on latches at the first non-space.
def trim_left source · line 90 · raw
@s:String -> String
def trim source · line 94 · raw
@+s:String -> String
def media_query source · line 102 · raw
@+pre:String -> String
A prelude that opens @media: its query ("" when it is another at-rule).
@layer name { opens the same way, its query U+0002 and the layer's name:
its rules are ordinary ones in that cascade layer (css.bend resolve_one
and compile rank them).
def keyframes_name source · line 109 · raw
@+pre:String -> String
The name a @keyframes (or @-webkit-keyframes) prelude declares, else "".
def open_at source · line 117 · raw
@+q:String -> @+kf:String -> @+rules:List<&2, Rule> -> St
Opening an at-rule's block: @media parses its rules, any other is skipped (a @keyframes block remembers its name).
def has_colon source · line 120 · raw
@s:String -> Bool
def before_colon source · line 128 · raw
@s:String -> String
def before_bang source · line 136 · raw
@s:String -> String
def drop_important source · line 145 · raw
@+v:String -> String
"red !important" -> "red"
def after_colon source · line 149 · raw
@s:String -> String
def decls_of source · line 157 · raw
@xs:List<&2, String> -> List<&2, Decl>
def split_out source · line 171 · raw
@cut:Bool -> @+cur:List<&2, Char> -> @+out:List<&2, String> -> List<&2, String>
The pieces so far, with the current one closed at a cut. (A pick here reversed the current piece at every char, cut or not: a split was quadratic in its pieces' length.)
def split_go source · line 183 · raw
@s:String -> @+sep:Char -> @+paren:U32 -> @+q:U32 -> @+esc:Bool -> @+cur:List<&2, Char> -> @+out:List<&2, String> -> List<&2, String>
Split at every sep outside parentheses and quotes. q is the open quote
character's code, 0 when outside a string. esc: the char before was a
backslash, so this one is text: Tailwind's .shadow-\[0_0_0_1px_x\,0_0_0_3px_y\]
is one selector, and a cut at its escaped comma made two no engine reads
(each "may match anything": every element refused box-shadow).
def split source · line 206 · raw
@+s:String -> @+sep:Char -> List<&2, String>
def declarations source · line 210 · raw
@+text:String -> List<&2, Decl>
def close_mrule source · line 215 · raw
@done:Bool -> @+q:String -> @+sel:List<&2, Char> -> @+body:List<&2, Char> -> @+rules:List<&2, Rule> -> @+c:Char -> St
A rule inside @media closes as its selector guarded by the query.
def close_rule source · line 225 · raw
@done:Bool -> @+sel:List<&2, Char> -> @+body:List<&2, Char> -> @+rules:List<&2, Rule> -> @+c:Char -> St
Closing a rule builds it once (a match, so the declarations are not split again at every character).
def guard_at source · line 238 · raw
@+q:String -> @+label:String -> String
An at-rule's block inside @media Q keeps Q as its guard ("@media Q"
U+0001 "@sel"): a query that does not hold leaves it out, as any rule
under Q. It lost Q, so .x { @media (display-mode: standalone) {
@supports (...) { display: none } } } made display unsure on
every .x though Element answers that the query does not hold. A layer's
block (Q starting U+0002) keeps the "@" label alone, as before.
def at_rule source · line 243 · raw
@outer:Bool -> @+label:String -> @+body:List<&2, Char> -> @+rules:List<&2, Rule> -> List<&2, Rule>
The declarations a nested block of an at-rule held, as an "@" rule; the at-rule's own closing brace (depth 1) holds none.
def at_label source · line 255 · raw
@+kf:String -> @+sel:List<&2, Char> -> String
What a nested block of a skipped at-rule may reach, for a reader to match: "@kf:NAME" for a keyframe of @keyframes NAME (it applies only through an animation naming it), "@" and the block's selector for a style rule inside @supports, @layer, @container... (only what that selector matches), and "@" alone when there is no selector (anything).
def at_start source · line 259 · raw
@is_at:Bool -> @+sel:List<&2, Char> -> Bool
def layer_rules source · line 269 · raw
@xs:List<&2, String> -> @+rules:List<&2, Rule> -> List<&2, Rule>
@layer a, b; declares the layers' order: an empty rule per name, its
layer before its (empty) selector, so the order is seen where it is
declared (css.bend layer_names); it styles nothing.
def layer_stmt source · line 276 · raw
@+pre:String -> @+rules:List<&2, Rule> -> List<&2, Rule>
def step source · line 281 · raw
@st:St -> @+c:Char -> St
One character of the sheet.
def top_kind source · line 355 · raw
@xs:List<&2, Fr> -> U32
def fl_act source · line 368 · raw
@+k:U32 -> @+q:U32 -> @+paren:U32 -> @+c:Char -> U32
What a character does: 0 text, 1 a quote, 2 '(', 3 ')', 4 ';' in a style rule, 5 ';' outside one, 6 '{' outside a style rule, 7 '{' inside one (a nested rule), 8 '}' closing a style rule, 9 '}' closing a group, 10 inside a block copied as written.
def rev_onto source · line 379 · raw
@+s:String -> @+out:List<&2, Char> -> List<&2, Char>
def amp_join source · line 384 · raw
@is_amp:Bool -> @+c:Char -> @+p:String -> @+rest:String -> String
& in a nested selector, the parent in its place (one recursive call per
character, given to a match: a pick would build both arms each step).
def amp_go source · line 395 · raw
@s:String -> @+esc:Bool -> @+p:String -> String
(esc: the char before was a backslash, so this one is text: an escaped
\& is part of a name, as in Tailwind's .\[a\&\]\:hover\:bg-accent,
the class "[a&]:hover:bg-accent"; replaced, it made a selector no engine
reads, and Element refused every element's background-color for it)
def amp source · line 402 · raw
@+s:String -> @+p:String -> String
def has_amp_go source · line 405 · raw
@s:String -> @+esc:Bool -> Bool
def has_amp source · line 412 · raw
@+s:String -> Bool
def nest_one source · line 415 · raw
@+n:String -> @+p:String -> String
def nest_parents source · line 418 · raw
@ps:List<&2, String> -> @+n:String -> List<&2, String>
def nest_all source · line 425 · raw
@ns:List<&2, String> -> @+ps:List<&2, String> -> List<&2, String>
def join_commas source · line 432 · raw
@xs:List<&2, String> -> String
def resolve source · line 439 · raw
@+nested:String -> @+parent:String -> String
def flush source · line 444 · raw
@+f:Fr -> @+out:List<&2, Char> -> List<&2, Char>
A style rule's declarations so far, written out as a rule (nothing when there are none).
def with_decls source · line 450 · raw
@+f:Fr -> @+ds:List<&2, Char> -> Fr
def fr_decls source · line 455 · raw
@f:Fr -> List<&2, Char>
def is_group source · line 460 · raw
@+pre:String -> Bool
def is_layer_block source · line 470 · raw
@+pre:String -> Bool
'{' outside a style rule: a group at-rule, a block copied as written, or a
style rule (its own selector: at this level nothing encloses it).
@layer name { opens like a style rule whose selector is the layer's
marker (U+0003 name U+0003): its rules come out as "<marker> sel" and a
nested @media wraps them, as nesting does; css.bend reads the marker.
def layer_mark source · line 474 · raw
@+pre:String -> String
def open_top source · line 477 · raw
@+pre:String -> @+stack:List<&2, Fr> -> @+out:List<&2, Char> -> @+q:U32 -> @+nested:Bool -> NS
def open_nested source · line 486 · raw
@stack:List<&2, Fr> -> @+pre:String -> @+out:List<&2, Char> -> NS
'{' inside a style rule: what it held so far is written, then the nested rule (a selector resolved against the parent's, or an at-rule wrapping the parent's selector) is read.
def close_style source · line 500 · raw
@stack:List<&2, Fr> -> @+cur:List<&2, Char> -> @+out:List<&2, Char> -> @+nested:Bool -> NS
'}' closing a style rule: its declarations (and an unterminated last one).
def pop_group source · line 507 · raw
@stack:List<&2, Fr> -> List<&2, Fr>
def raw_char source · line 515 · raw
@stack:List<&2, Fr> -> @+c:Char -> @+cur:List<&2, Char> -> @+out:List<&2, Char> -> @+nested:Bool -> NS
A character inside a block copied as written: its braces counted.
def push_decl source · line 526 · raw
@stack:List<&2, Fr> -> @+cur:List<&2, Char> -> List<&2, Fr>
def fl_do source · line 533 · raw
@+st:NS -> @+a:U32 -> @+c:Char -> NS
def fl_step source · line 561 · raw
@st:NS -> @+c:Char -> NS
def fl_go source · line 566 · raw
@s:String -> @+st:NS -> NS
def fl_result source · line 573 · raw
@st:NS -> @+orig:String -> String
def flatten source · line 579 · raw
@+s:String -> String
The sheet with its nested rules flattened, or as written when none nest.
def go source · line 582 · raw
@s:String -> @+st:St -> St
def rules_of source · line 589 · raw
@st:St -> List<&2, Rule>
def parse source · line 595 · raw
@s:String -> List<&2, Rule>
The style rules of a sheet, in order.