]> matita.cs.unibo.it Git - helm.git/blob - helm/www/lambda_delta/bin/xhtbl/textParser.mly
update ...
[helm.git] / helm / www / lambda_delta / 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 NAME TABLE CSS SR OC CC OB CB EOF
19
20 %start script
21 %type <(string * Table.table * Css.atoms) list> script
22
23 %%
24
25 key:
26    | TEXT { T.Text $1        }
27    | SR   { T.Glue None      }
28    | NUM  { T.Glue (Some $1) }
29 ;
30
31 css:
32    |          { []       }
33    | CSS TEXT { split $2 }
34 ;
35
36 table:
37    | css key          { T.mk_key        $2 $1 }
38    | css OC tables CC { T.mk_line false $3 $1 }
39    | css OB tables CB { T.mk_line true  $3 $1 }
40 ;
41
42 tables:
43    |              { []       }
44    | table tables { $1 :: $2 }
45 ;
46
47 name:
48    |           { "" }
49    | NAME TEXT { $2 }
50 ;
51
52 interval:
53    | NUM     { Some $1, Some $1 }
54    | SR      { None, None       } 
55    | NUM NUM { Some $1, Some $2 }
56    | NUM SR  { Some $1, None    }
57    | SR NUM  { None, Some $2    }
58    | SR SR   { None, None       }
59 ;
60
61 range:
62    | OB interval CB { true, $2  }
63    | OC interval CC { false, $2 }
64 ;
65
66 ranges:
67    |              { []       }
68    | range ranges { $1 :: $2 }
69 ;
70
71 atom:
72    | CSS TEXT ranges { mk_atom $2 $3 }
73 ;
74
75 atoms:
76    |            { []      }
77    | atom atoms { $1 @ $2 }
78 ;
79
80 directive:
81    | name TABLE table atoms { $1, $3, $4 }
82 ;
83
84 script:
85    | EOF              { []       }
86    | directive script { $1 :: $2 }
87 ;