comparison src/urweb.grm @ 2008:93ff76058825

HTML5 data-* attributes
author Adam Chlipala <adam@chlipala.net>
date Fri, 02 May 2014 15:32:10 -0400
parents c3b03d099e04
children 799be3911ce3
comparison
equal deleted inserted replaced
2007:d3a0f2b8af28 2008:93ff76058825
223 "table" => "tabl" 223 "table" => "tabl"
224 | _ => bt 224 | _ => bt
225 225
226 datatype prop_kind = Delete | Update 226 datatype prop_kind = Delete | Update
227 227
228 datatype attr = Class of exp | DynClass of exp | Style of exp | DynStyle of exp | Normal of con * exp 228 datatype attr = Class of exp | DynClass of exp | Style of exp | DynStyle of exp | Normal of con * exp | Data of string * exp
229 229
230 fun patType loc (p : pat) = 230 fun patType loc (p : pat) =
231 case #1 p of 231 case #1 p of
232 PAnnot (_, t) => t 232 PAnnot (_, t) => t
233 | _ => (CWild (KType, loc), loc) 233 | _ => (CWild (KType, loc), loc)
451 | patS of pat 451 | patS of pat
452 | pterm of pat 452 | pterm of pat
453 | rpat of (string * pat) list * bool 453 | rpat of (string * pat) list * bool
454 | ptuple of pat list 454 | ptuple of pat list
455 455
456 | attrs of exp option * exp option * exp option * exp option * (con * exp) list 456 | attrs of exp option * exp option * exp option * exp option * (string * exp) list * (con * exp) list
457 | attr of attr 457 | attr of attr
458 | attrv of exp 458 | attrv of exp
459 459
460 | query of exp 460 | query of exp
461 | query1 of exp 461 | query1 of exp
1600 val eo = case #4 attrs of 1600 val eo = case #4 attrs of
1601 NONE => (EVar (["Basis"], "None", Infer), pos) 1601 NONE => (EVar (["Basis"], "None", Infer), pos)
1602 | SOME e => (EApp ((EVar (["Basis"], "Some", Infer), pos), 1602 | SOME e => (EApp ((EVar (["Basis"], "Some", Infer), pos),
1603 e), pos) 1603 e), pos)
1604 val e = (EApp (e, eo), pos) 1604 val e = (EApp (e, eo), pos)
1605 val e = (EApp (e, (ERecord (#5 attrs), pos)), pos) 1605
1606 val atts = case #5 attrs of
1607 [] => #6 attrs
1608 | data :: datas =>
1609 let
1610 fun doOne (name, value) =
1611 let
1612 val e = (EVar (["Basis"], "data_attr", Infer), pos)
1613 val e = (EApp (e, (EPrim (Prim.String name), pos)), pos)
1614 in
1615 (EApp (e, value), pos)
1616 end
1617
1618 val datas' = foldl (fn (nv, acc) =>
1619 let
1620 val e = (EVar (["Basis"], "data_attrs", Infer), pos)
1621 val e = (EApp (e, acc), pos)
1622 in
1623 (EApp (e, doOne nv), pos)
1624 end) (doOne data) datas
1625 in
1626 ((CName "Data", pos), datas') :: #6 attrs
1627 end
1628
1629 val e = (EApp (e, (ERecord atts, pos)), pos)
1606 val e = (EApp (e, (EApp (#2 tagHead, 1630 val e = (EApp (e, (EApp (#2 tagHead,
1607 (ERecord [], pos)), pos)), pos) 1631 (ERecord [], pos)), pos)), pos)
1608 in 1632 in
1609 (tagHead, #1 attrs, #2 attrs, e) 1633 (tagHead, #1 attrs, #2 attrs, e)
1610 end) 1634 end)
1616 (bt, 1640 (bt,
1617 (EVar ([], bt, Infer), pos)) 1641 (EVar ([], bt, Infer), pos))
1618 end) 1642 end)
1619 | tagHead LBRACE cexp RBRACE (#1 tagHead, (ECApp (#2 tagHead, cexp), s (tagHeadleft, RBRACEright))) 1643 | tagHead LBRACE cexp RBRACE (#1 tagHead, (ECApp (#2 tagHead, cexp), s (tagHeadleft, RBRACEright)))
1620 1644
1621 attrs : (NONE, NONE, NONE, NONE, []) 1645 attrs : (NONE, NONE, NONE, NONE, [], [])
1622 | attr attrs (let 1646 | attr attrs (let
1623 val loc = s (attrleft, attrsright) 1647 val loc = s (attrleft, attrsright)
1624 in 1648 in
1625 case attr of 1649 case attr of
1626 Class e => 1650 Class e =>
1627 (case #1 attrs of 1651 (case #1 attrs of
1628 NONE => () 1652 NONE => ()
1629 | SOME _ => ErrorMsg.errorAt loc "Multiple classes specified for tag"; 1653 | SOME _ => ErrorMsg.errorAt loc "Multiple classes specified for tag";
1630 (SOME e, #2 attrs, #3 attrs, #4 attrs, #5 attrs)) 1654 (SOME e, #2 attrs, #3 attrs, #4 attrs, #5 attrs, #6 attrs))
1631 | DynClass e => 1655 | DynClass e =>
1632 (case #2 attrs of 1656 (case #2 attrs of
1633 NONE => () 1657 NONE => ()
1634 | SOME _ => ErrorMsg.errorAt loc "Multiple dynamic classes specified for tag"; 1658 | SOME _ => ErrorMsg.errorAt loc "Multiple dynamic classes specified for tag";
1635 (#1 attrs, SOME e, #3 attrs, #4 attrs, #5 attrs)) 1659 (#1 attrs, SOME e, #3 attrs, #4 attrs, #5 attrs, #6 attrs))
1636 | Style e => 1660 | Style e =>
1637 (case #3 attrs of 1661 (case #3 attrs of
1638 NONE => () 1662 NONE => ()
1639 | SOME _ => ErrorMsg.errorAt loc "Multiple styles specified for tag"; 1663 | SOME _ => ErrorMsg.errorAt loc "Multiple styles specified for tag";
1640 (#1 attrs, #2 attrs, SOME e, #4 attrs, #5 attrs)) 1664 (#1 attrs, #2 attrs, SOME e, #4 attrs, #5 attrs, #6 attrs))
1641 | DynStyle e => 1665 | DynStyle e =>
1642 (case #4 attrs of 1666 (case #4 attrs of
1643 NONE => () 1667 NONE => ()
1644 | SOME _ => ErrorMsg.errorAt loc "Multiple dynamic classes specified for tag"; 1668 | SOME _ => ErrorMsg.errorAt loc "Multiple dynamic classes specified for tag";
1645 (#1 attrs, #2 attrs, #3 attrs, SOME e, #5 attrs)) 1669 (#1 attrs, #2 attrs, #3 attrs, SOME e, #5 attrs, #6 attrs))
1670 | Data xe =>
1671 (#1 attrs, #2 attrs, #3 attrs, #4 attrs, xe :: #5 attrs, #6 attrs)
1646 | Normal xe => 1672 | Normal xe =>
1647 (#1 attrs, #2 attrs, #3 attrs, #4 attrs, xe :: #5 attrs) 1673 (#1 attrs, #2 attrs, #3 attrs, #4 attrs, #5 attrs, xe :: #6 attrs)
1648 end) 1674 end)
1649 1675
1650 attr : SYMBOL EQ attrv (case SYMBOL of 1676 attr : SYMBOL EQ attrv (case SYMBOL of
1651 "class" => Class attrv 1677 "class" => Class attrv
1652 | "dynClass" => DynClass attrv 1678 | "dynClass" => DynClass attrv
1653 | "style" => Style attrv 1679 | "style" => Style attrv
1654 | "dynStyle" => DynStyle attrv 1680 | "dynStyle" => DynStyle attrv
1655 | _ => 1681 | _ =>
1656 let 1682 if String.isPrefix "data-" SYMBOL then
1657 val sym = makeAttr SYMBOL 1683 Data (String.extract (SYMBOL, 5, NONE), attrv)
1658 in 1684 else
1659 Normal ((CName sym, s (SYMBOLleft, SYMBOLright)), 1685 let
1660 if (sym = "Href" orelse sym = "Src") 1686 val sym = makeAttr SYMBOL
1661 andalso (case #1 attrv of 1687 in
1662 EPrim _ => true 1688 Normal ((CName sym, s (SYMBOLleft, SYMBOLright)),
1663 | _ => false) then 1689 if (sym = "Href" orelse sym = "Src")
1664 let 1690 andalso (case #1 attrv of
1665 val loc = s (attrvleft, attrvright) 1691 EPrim _ => true
1666 in 1692 | _ => false) then
1667 (EApp ((EVar (["Basis"], "bless", Infer), loc), 1693 let
1668 attrv), loc) 1694 val loc = s (attrvleft, attrvright)
1669 end 1695 in
1670 else 1696 (EApp ((EVar (["Basis"], "bless", Infer), loc),
1671 attrv) 1697 attrv), loc)
1672 end) 1698 end
1699 else
1700 attrv)
1701 end)
1673 1702
1674 attrv : INT (EPrim (Prim.Int INT), s (INTleft, INTright)) 1703 attrv : INT (EPrim (Prim.Int INT), s (INTleft, INTright))
1675 | FLOAT (EPrim (Prim.Float FLOAT), s (FLOATleft, FLOATright)) 1704 | FLOAT (EPrim (Prim.Float FLOAT), s (FLOATleft, FLOATright))
1676 | STRING (EPrim (Prim.String STRING), s (STRINGleft, STRINGright)) 1705 | STRING (EPrim (Prim.String STRING), s (STRINGleft, STRINGright))
1677 | LBRACE eexp RBRACE (eexp) 1706 | LBRACE eexp RBRACE (eexp)