summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar Adam Chlipala <adam@chlipala.net>2012-12-27 15:34:11 -0500
committerGravatar Adam Chlipala <adam@chlipala.net>2012-12-27 15:34:11 -0500
commit53c633b53e8825cb9058fb88e86d1ca7828b83e6 (patch)
tree94682452c654491c184a8e2d43d3dbfdb4e46cf9 /src
parentbf6fbd81d4e60a87b19f8c8149349217b4620360 (diff)
Add some name-mangling rules to allow XML attribute 'name' and attributes with dashes
Diffstat (limited to 'src')
-rw-r--r--src/monoize.sml5
-rw-r--r--src/urweb.grm11
-rw-r--r--src/urweb.lex3
3 files changed, 14 insertions, 5 deletions
diff --git a/src/monoize.sml b/src/monoize.sml
index 39e4853b..d324b235 100644
--- a/src/monoize.sml
+++ b/src/monoize.sml
@@ -3364,8 +3364,13 @@ fun monoExp (env, st, fm) (all as (e, loc)) =
val x =
case x of
"Typ" => "Type"
+ | "Nam" => "Name"
| "Link" => "Href"
| _ => x
+
+ val x = String.translate (fn #"_" => "-"
+ | ch => String.str ch) x
+
val xp = " " ^ lowercaseFirst x ^ "=\""
val (e, fm) = fooify env fm (e, t)
diff --git a/src/urweb.grm b/src/urweb.grm
index a45c7ffa..c2a48742 100644
--- a/src/urweb.grm
+++ b/src/urweb.grm
@@ -35,6 +35,12 @@ val dummy = ErrorMsg.dummySpan
fun capitalize "" = ""
| capitalize s = str (Char.toUpper (String.sub (s, 0))) ^ String.extract (s, 1, NONE)
+fun makeAttr s =
+ case s of
+ "type" => "Typ"
+ | "name" => "Nam"
+ | _ => capitalize (String.translate (fn ch => if ch = #"-" then "_" else str ch) s)
+
fun entable t =
case #1 t of
TRecord c => c
@@ -1648,10 +1654,7 @@ attr : SYMBOL EQ attrv (case SYMBOL of
| "dynStyle" => DynStyle attrv
| _ =>
let
- val sym =
- case SYMBOL of
- "type" => "Typ"
- | x => capitalize x
+ val sym = makeAttr SYMBOL
in
Normal ((CName sym, s (SYMBOLleft, SYMBOLright)),
if (sym = "Href" orelse sym = "Src")
diff --git a/src/urweb.lex b/src/urweb.lex
index 0994ecec..293c6dc6 100644
--- a/src/urweb.lex
+++ b/src/urweb.lex
@@ -177,6 +177,7 @@ fun unescape loc s =
%s COMMENT STRING CHAR XML XMLTAG;
id = [a-z_][A-Za-z0-9_']*;
+xmlid = [A-Za-z][A-Za-z0-9-_]*;
cid = [A-Z][A-Za-z0-9_]*;
ws = [\ \t\012\r];
intconst = [0-9]+;
@@ -313,7 +314,7 @@ xint = x[0-9a-fA-F][0-9a-fA-F];
<XMLTAG> {ws}+ => (lex ());
-<XMLTAG> {id} => (Tokens.SYMBOL (yytext, yypos, yypos + size yytext));
+<XMLTAG> {xmlid} => (Tokens.SYMBOL (yytext, yypos, yypos + size yytext));
<XMLTAG> "=" => (Tokens.EQ (yypos, yypos + size yytext));
<XMLTAG> {intconst} => (case Int64.fromString yytext of