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