changeset 1128:e1cf925e2074

Allow escaped backslashes in literals; conversion betwixt int and char
author Adam Chlipala <adamc@hcoop.net>
date Tue, 12 Jan 2010 16:09:13 -0500
parents f93dc2ea30c1
children 4f3a1aa3b66d
files include/urweb.h lib/ur/basis.urs lib/ur/char.ur lib/ur/char.urs src/c/urweb.c src/urweb.lex
diffstat 6 files changed, 20 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/include/urweb.h	Tue Jan 12 11:19:02 2010 -0500
+++ b/include/urweb.h	Tue Jan 12 16:09:13 2010 -0500
@@ -258,6 +258,9 @@
 uw_Basis_char uw_Basis_tolower(uw_context, uw_Basis_char);
 uw_Basis_char uw_Basis_toupper(uw_context, uw_Basis_char);
 
+uw_Basis_int uw_Basis_ord(uw_context, uw_Basis_char);
+uw_Basis_char uw_Basis_chr(uw_context, uw_Basis_int);
+
 uw_Basis_string uw_Basis_currentUrl(uw_context);
 void uw_set_currentUrl(uw_context, char *);
 
--- a/lib/ur/basis.urs	Tue Jan 12 11:19:02 2010 -0500
+++ b/lib/ur/basis.urs	Tue Jan 12 16:09:13 2010 -0500
@@ -68,7 +68,8 @@
 val isxdigit : char -> bool
 val tolower : char -> char
 val toupper : char -> char
-
+val ord : char -> int
+val chr : int -> char
 
 (** String operations *)
 
--- a/lib/ur/char.ur	Tue Jan 12 11:19:02 2010 -0500
+++ b/lib/ur/char.ur	Tue Jan 12 16:09:13 2010 -0500
@@ -14,3 +14,6 @@
 val isXdigit = Basis.isxdigit
 val toLower = Basis.tolower
 val toUpper = Basis.toupper
+
+val toInt = Basis.ord
+val fromInt = Basis.chr
--- a/lib/ur/char.urs	Tue Jan 12 11:19:02 2010 -0500
+++ b/lib/ur/char.urs	Tue Jan 12 16:09:13 2010 -0500
@@ -14,3 +14,6 @@
 val isXdigit : t -> bool
 val toLower : t -> t
 val toUpper : t -> t
+
+val toInt : t -> int
+val fromInt : int -> t
--- a/src/c/urweb.c	Tue Jan 12 11:19:02 2010 -0500
+++ b/src/c/urweb.c	Tue Jan 12 16:09:13 2010 -0500
@@ -3375,6 +3375,14 @@
   return toupper(c);
 }
 
+uw_Basis_int uw_Basis_ord(uw_context ctx, uw_Basis_char c) {
+  return (unsigned char)c;
+}
+
+uw_Basis_char uw_Basis_chr(uw_context ctx, uw_Basis_int n) {
+  return n;
+}
+
 uw_Basis_string uw_Basis_currentUrl(uw_context ctx) {
   return ctx->current_url;
 }
--- a/src/urweb.lex	Tue Jan 12 11:19:02 2010 -0500
+++ b/src/urweb.lex	Tue Jan 12 16:09:13 2010 -0500
@@ -198,6 +198,7 @@
 <STRING,CHAR> "\\\""  => (str := #"\"" :: !str; continue());
 <STRING,CHAR> "\\'"   => (str := #"'" :: !str; continue());
 <STRING,CHAR> "\\n"   => (str := #"\n" :: !str; continue());
+<STRING,CHAR> "\\\\"  => (str := #"\\" :: !str; continue());
 <STRING,CHAR> "\\t"   => (str := #"\t" :: !str; continue());
 <STRING,CHAR> "\n"    => (newline yypos;
 			  str := #"\n" :: !str; continue());