]> matita.cs.unibo.it Git - helm.git/blob - helm/www/lambdadelta/bin/xhtbl/textParser.mly
- we begin the new site based on ld_web
[helm.git] / helm / www / lambdadelta / bin / xhtbl / textParser.mly
1 %{
2
3 module S = Str
4 module L = List
5 module T = Table
6
7 let split s =
8    S.split (S.regexp "[ \r\n\t]+") s
9
10 let mk_atom s rs =
11    let map c (b, (x1, x2)) = c, b, x1, x2 in 
12    L.map (map (split s)) rs
13
14 %}
15
16 %token <int> NUM
17 %token <string> TEXT 
18 %token SPACE NAME TABLE CSS SR OC CC OB CB PS OP CP AT EOF
19
20 %start script
21 %type <(string * string) list * (string * Table.table * Css.atoms) list> script
22
23 %%
24
25 space:
26    | SPACE TEXT TEXT { $2, $3 }
27 ;
28
29 spaces:
30    |              { []       }
31    | space spaces { $1 :: $2 }
32 ;
33
34 text:
35    | TEXT               { T.Plain $1 }
36    | AT OP TEXT TEXT CP { T.Link ($3, $4) }
37 ;
38
39 texts:
40   | text          { [$1]     }
41   | text PS texts { $1 :: $3 }
42 ;
43
44 key:
45    | texts { T.Text $1        }
46    | SR    { T.Glue None      }
47    | NUM   { T.Glue (Some $1) }
48 ;
49
50 css:
51    |          { []       }
52    | CSS TEXT { split $2 }
53 ;
54
55 table:
56    | css key          { T.mk_key        $2 $1 }
57    | css OC tables CC { T.mk_line false $3 $1 }
58    | css OB tables CB { T.mk_line true  $3 $1 }
59 ;
60
61 tables:
62    |              { []       }
63    | table tables { $1 :: $2 }
64 ;
65
66 name:
67    |           { "" }
68    | NAME TEXT { $2 }
69 ;
70
71 interval:
72    | NUM     { Some $1, Some $1 }
73    | SR      { None, None       } 
74    | NUM NUM { Some $1, Some $2 }
75    | NUM SR  { Some $1, None    }
76    | SR NUM  { None, Some $2    }
77    | SR SR   { None, None       }
78 ;
79
80 range:
81    | OB interval CB { true, $2  }
82    | OC interval CC { false, $2 }
83 ;
84
85 ranges:
86    |              { []       }
87    | range ranges { $1 :: $2 }
88 ;
89
90 atom:
91    | CSS TEXT ranges { mk_atom $2 $3 }
92 ;
93
94 atoms:
95    |            { []      }
96    | atom atoms { $1 @ $2 }
97 ;
98
99 directive:
100    | name TABLE table atoms { $1, $3, $4 }
101 ;
102
103 directives:
104    |                      { []       }
105    | directive directives { $1 :: $2 }
106 ;
107
108 script:
109    | spaces directives EOF { $1, $2 }
110 ;