Commit 55e45b29 authored by Pietro Abate's avatar Pietro Abate
Browse files

[r2002-11-16 14:34:49 by cvscast] Empty log message

Original author: cvscast
Date: 2002-11-16 14:35:45+00:00
parent 51d34f88
......@@ -60,6 +60,9 @@ all.cmxa: $(XOBJECTS)
$(OCAMLOPT) -a -o $@ $(XOBJECTS)
memento.html: cduce tests/memento.cd tests/memento.xml
./cduce -quiet tests/memento.cd
cduce: $(CDUCE)
$(OCAMLC) $(DEBUG) -linkpkg -o $@ gramlib.cma $(CDUCE)
......@@ -143,7 +146,7 @@ driver/examples.ml: cduce tests/web.cd tests/examples.xml
# Site-specific installation
build_web:
rsh cedre ". .env; cd IMPLEM/CDUCE; make webiface"
rsh cedre ". .env; cd IMPLEM/CDUCE; make webiface memento.html"
install_web:
ssh cduce@iris "cp ~frisch/IMPLEM/CDUCE/webiface cgi-bin/cduce2; chmod +s cgi-bin/cduce2"
ssh cduce@iris "cp ~frisch/IMPLEM/CDUCE/webiface cgi-bin/cduce2; cp ~frisch/IMPLEM/CDUCE/memento.html public_html/; chmod +s cgi-bin/cduce2"
......@@ -117,6 +117,7 @@ EXTEND
| LIDENT "print"
| LIDENT "raise"
| LIDENT "int_of"
| LIDENT "string_of"
];
e = expr -> mk loc (Op (op,[e]))
| op = [ LIDENT "dump_to_file" ];
......
......@@ -121,10 +121,10 @@ let lex_tables = {
\033\000\006\000\007\000\036\000\036\000\036\000\036\000\035\000\
\035\000\035\000\035\000\032\000\033\000\033\000\033\000\033\000\
\033\000\033\000\034\000\035\000\035\000\035\000\035\000\036\000\
\036\000\036\000\036\000\037\000\000\000\000\000\000\000\000\000\
\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\
\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\
\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\
\036\000\036\000\036\000\037\000\000\000\000\000\000\000\036\000\
\000\000\000\000\000\000\035\000\000\000\000\000\000\000\000\000\
\000\000\000\000\033\000\000\000\000\000\000\000\000\000\035\000\
\000\000\000\000\000\000\036\000\000\000\000\000\000\000\000\000\
\000\000\000\000";
Lexing.lex_check =
"\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\
......@@ -136,10 +136,10 @@ let lex_tables = {
\022\000\003\000\003\000\019\000\019\000\019\000\019\000\020\000\
\020\000\020\000\020\000\032\000\032\000\032\000\033\000\033\000\
\033\000\033\000\034\000\035\000\035\000\035\000\035\000\036\000\
\036\000\036\000\036\000\037\000\255\255\255\255\255\255\255\255\
\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\
\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\
\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\
\036\000\036\000\036\000\037\000\255\255\255\255\255\255\019\000\
\255\255\255\255\255\255\020\000\255\255\255\255\255\255\255\255\
\255\255\255\255\033\000\255\255\255\255\255\255\255\255\035\000\
\255\255\255\255\255\255\036\000\255\255\255\255\255\255\255\255\
\255\255\255\255"
}
......
......@@ -38,7 +38,7 @@ classes
}
let identchar = lowercase | uppercase | ascii_digit | '_'
let identchar = lowercase | uppercase | ascii_digit | '_' | '\''
rule token = parse
blank+ { token engine lexbuf }
......
......@@ -64,6 +64,7 @@ let rec eval env e0 =
| Typed.Op ("print_xml", [e]) -> eval_print_xml (eval env e)
| Typed.Op ("print", [e]) -> eval_print (eval env e)
| Typed.Op ("int_of", [e]) -> eval_int_of (eval env e)
| Typed.Op ("string_of", [e]) -> eval_string_of (eval env e)
| Typed.Op ("dump_to_file", [e1; e2]) ->
eval_dump_to_file (eval env e1) (eval env e2)
| Typed.Dot (e, l) -> eval_dot l (eval env e)
......@@ -151,3 +152,11 @@ and eval_dump_to_file f v =
close_out oc;
Value.nil
and eval_string_of v =
let b = Buffer.create 16 in
let ppf = Format.formatter_of_buffer b in
Value.print ppf v;
Format.pp_print_flush ppf ();
string (Buffer.contents b)
......@@ -13,7 +13,7 @@ type Misc = Empty;;
type Html = <html>[ Head Body ];;
type Head = <head>[ Title ];;
type Title = <title>[ PCDATA ];;
type Body = <body>[ Block* ];;
type Body = <body bgcolor=String>[ Block* ];;
type Div = <div>[ Flow* ];;
type P = <p>[ Inline* ];;
......@@ -38,44 +38,61 @@ type B = <b>[ Inline* ];;
type Big = <big>[ Inline* ];;
type Small = <small>[ Inline* ];;
type Table = Empty;;
type Table = <table border=?String; bgcolor=String; width=String>
[ <tr>[ <td>[ Flow* ]+ ]+ ];;
(* Input document *)
type Page = <page filename=String>[ <title>String; Content ];;
type Content = [ (Box | Section)* ];;
type Content' = [ (Box | Section')* ];;
type Box = <box>Text;;
type Section = <section>[ <title>String ; Text ];;
type Text = [ (Char | <duce>String | <ul>[<li>Text +])* ];;
let (fname, title, content) =
match load_xml "tests/memento.xml" with
| <page filename=x>[ <title>x ; x ] & Page -> x
| _ -> raise "Invalid input document!";;
type Section' = <section no=Int>[ <title>String ; Text ];;
type Text = [ (Char | <duce>String | <ul>[<li>Text +]
| <a href=String>String | <br>[])* ];;
let fun box(c : [Flow*]) : Block = <div>c;;
let fun box(c : [Flow*]) : [Block*] =
[ <table bgcolor="white"; width="100%"; border="1">[ <tr>[ <td>c ] ]
<p>[] ];;
let fun format (Box | Section -> Block; Text -> [Flow*]; Content -> [Block*] )
let fun format (Box | Section' | Content' -> [Block*]; Text -> [Flow*])
| <box>s -> box (format s)
| <section>[ <title>t ; s ] -> box [ <h2>t; format s ]
| <section no=i>[ <title>t ; s ] ->
box [ <h2>[!(string_of i) '. ' !t] <a name=string_of i>[];
format s ]
| txt & Text -> (map txt with
| <duce>c -> <b>[<tt>c]
| <ul>l -> <ul>(map l with <li>c -> <li>(format c) )
| c -> c)
| c & Content -> (map c with x -> format x);;
| c & Content' -> (transform c with x -> format x);;
let summary (Content -> Block)
let fun summary (Content' -> [Block*])
c ->
let s = transform c with <section>[<title>t] -> [<li>t] in
match s with [] -> [] | lis -> <ul>lis;;
let s = transform c with <section no=i>[<title>t; _] ->
[<li>[<a href="#" @ string_of i>t]] in
match s with [] -> [] | lis -> box [<ul>lis];;
let (fname, title, content) =
match load_xml "tests/memento.xml" with
| <page filename=f>[ <title>t ; c ] & Page ->
let fun aux ((Int,Content) -> Content')
| (_,[]) -> []
| (i,(<section>s,rem)) -> [ <section no=i>s !(aux (i+1,rem)) ]
| (i,(x,rem)) -> [ x !(aux (i,rem)) ]
in
(f,t,aux (1,c))
| _ -> raise "Invalid input document!";;
let out : Html =
<html>[
<head>[ <title>title ]
<body>[ (box [<h1>title]) !(format content) ]
<body bgcolor="#BBDDFF">
[ !(box [<h1>title]) !(summary content) !(format content) ]
];;
dump_to_file fname (print_xml out);;
......@@ -3,8 +3,8 @@
<box>
This page briefly presents the syntax of the CDuce language.
You can experiment with the online demo, which includes a few built-in
examples.
You can experiment with the <a href="/cgi-bin/cduce">online demo</a>,
which includes a few built-in examples.
</box>
<section>
......@@ -15,6 +15,7 @@ examples.
<li>Values: <duce>0,1,2,3,...</duce> </li>
<li>Types: intervals <duce>-*--10, 20--30, 50--*, ...</duce>,
singletons <duce>0,1,2,3,...</duce> </li>
<li>Operators: <duce>+,-,/,*, int_of</duce> </li>
</ul>
</li>
<li>Unicode characters:
......@@ -52,7 +53,8 @@ examples.
<ul>
<li>Expressions: <duce>[ 1 2 3 ]</duce>,
which is syntactic sugar for <duce>(1,(2,(3,`nil)))</duce> </li>
<li>A sub-sequence can be escaped by !: <duce>[ 1 2 ![ 3 4 ] 5 ]</duce>. </li>
<li>A sub-sequence can be escaped by !: <duce>[ 1 2 ![ 3 4 ] 5
]</duce>. </li>
<li>Types and patterns : <duce>[ R ]</duce> where <duce>R</duce> is
a regular expression built on types and patterns:
<ul>
......@@ -67,7 +69,96 @@ examples.
</li>
<li>It is possible to specify a tail, for expressions, types, and patterns;
e.g.: <duce>[ x::Int*; q ]</duce> </li>
<li>Map: <duce>map e with p1 -> e1 | ... | pn -> en</duce>.
Each element of e must be matched. </li>
<li>Transform: <duce>transform e with p1 -> e1 | ... | pn -> en</duce>.
Unmatched elements are discarded; each branch returns a sequence
and all the resulting sequences are concatenated together. </li>
<li>Operators: concatenation <duce>e1 @ e2 = [ !e1 !e2 ]</duce>,
flattening <duce>flatten e = transform e with x -> x</duce>.
</li>
</ul>
</section>
<section>
<title>Strings</title>
<ul>
<li>Strings are actually sequences of characters.</li>
<li>Expressions: <duce>"abc", [ 'abc' ], [ 'a' 'b' 'c' ]</duce>. </li>
<li>Operators: <duce>string_of, print, dump_to_file</duce></li>
<li><duce>PCDATA</duce> means <duce>Char*</duce> inside regular expressions</li>
</ul>
</section>
<section>
<title>XML elements</title>
<ul>
<li>Expressions: <duce> &lt;(tag) (attr)>content</duce> </li>
<li>If the tag is an atom <duce>`X</duce>, it can be written
<duce>X</duce> (without the <duce>(..)</duce>).
Similarly, parenthesis and curly braces may be omitted
when attr is a record <duce>l1=e1;...;ln=en</duce>.
E.g: <duce>&lt;a href="abc">[ 'abc' ]</duce>.</li>
<li>Types and patterns: same notations.</li>
<li>Operators: <duce>load_xml : String -> Any; print_xml : Any -> String</duce></li>
</ul>
</section>
<section>
<title>Functions</title>
<ul>
<li>Expressions:
<ul>
<li>General form: <duce>fun f (t1->s1;...;tn->sn)
p1 -> e1 | ... | pn -> en</duce> (<duce>f</duce> is optional) </li>
<li>Simple function: <duce>fun f (p : t) : s = e</duce>,
equivalent to <duce>fun f (t -> s) p -> e</duce> </li>
<li>Multiple arguments: <duce>fun f (p1 : t1, p2 : t2,...) : s =
e</duce>, equivalent to <duce>fun f ((p1,p2,...):(t1,t2,...)) : s
= e</duce> </li>
</ul>
</li>
<li>Types: <duce>t -> s</duce> </li>
</ul>
</section>
<section>
<title>Pattern matching, exceptions, ...</title>
<ul>
<li>Type restriction: <duce>(e : t)</duce> (forgets any more precise
type for <duce>e</duce>) </li>
<li>Pattern matching: <duce>match e with p1 -> e1 | ... | pn ->
en</duce></li>
<li>Local binding: <duce>let p = e1 in e2</duce>, equivalent to
<duce>match e1 with p -> e2</duce>;
<duce>let p : t = e1 in e2</duce> equivalent to
<duce>let p = (e1 : t) in e2</duce> </li>
<li>Exceptions: <ul>
<li>Raise exception: <duce>raise e</duce></li>
<li>Handle exception: <duce>try e with p1 -> e1 | ... | pn ->
en</duce></li>
</ul> </li>
</ul>
</section>
<section>
<title>More about types and patterns</title>
<ul>
<li>Boolean connectives: <duce>&amp;,|,\</duce> (<duce>|</duce> is
first-match). </li>
<li>Empty and universal types: <duce>Empty,Any</duce> or <duce>_</duce>.</li>
<li>Capture variable: <duce>x</duce>. </li>
<li>Default values: <duce>(x := c)</duce>. </li>
</ul>
</section>
<box>
This page has been generated by a CDuce program.
<br/>
Todo: records, toplevel phrases, recursives types and patterns.
<br/><a href="/">Home page</a>
<br/><a href="mailto:Alain.Frisch@ens.fr">Webmaster</a>
</box>
</page>
......@@ -802,6 +802,8 @@ and type_op loc op args =
if not (Types.subtype t1 Builtin.intstr) then
warning loc "This application of int_of may fail";
Types.interval Intervals.any
| "string_of", [loc1,t1] ->
Sequence.string
| _ -> assert false
and type_int_binop f loc1 t1 loc2 t2 =
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment