summaryrefslogtreecommitdiff
path: root/gf-book/examples/chapter3/Arabic.gf
blob: e00d02c23baa224846678359e832fc3cd5d21b2c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
resource Arabic = {
oper
  Root    : Type = {F,C,L : Str} ;
  Pattern : Type = Root -> Str ;

  Filling : Type = {F,FC,CL,L : Str} ;

  fill : Filling -> Root -> Str = \p,r ->
    p.F + r.F + p.FC + r.C + p.CL + r.L + p.L ;

  dfill : Filling -> Root -> Str = \p,r ->
    p.F + r.F + p.FC + r.C + r.C + p.CL + r.L + p.L ;

  getRoot : Str -> Root = \s -> case s of {
    F@? + C@? + L@? => {F = F ; C = C ; L = L} ;
    _ => Predef.error ("cannot get root from" ++ s)
    } ;

  getPattern : Str -> Pattern = \s -> case s of {
    F + "F" + FC + "CC" + CL + "L" + L => 
      dfill {F = F ; FC = FC ; CL = CL ; L = L} ;
    F + "F" + FC + "C" + CL + "L" + L => 
      fill {F = F ; FC = FC ; CL = CL ; L = L} ;
    _ => Predef.error ("cannot get pattern from" ++ s)
    } ;

  word : Str -> Str -> Str = \p,r ->
    getPattern p (getRoot r) ;

param
  Number = Sg | Dl | Pl ;
  Gender = Masc | Fem ;
  Tense  = Perf | Impf ;

  VPer = Vp3 Number Gender | Vp2Sg Gender | Vp2Dl | Vp2Pl Gender | Vp1Sg | Vp1Pl ;

oper
  Verb : Type = {s : Tense => VPer => Str} ;  

  pattV_u : Tense -> VPer -> Pattern = \t,v -> getPattern (case t of {
    Perf => case v of {
      Vp3 Sg Masc => "FaCaLa" ;
      Vp3 Sg Fem  => "FaCaLat" ;
      Vp3 Dl Masc => "FaCaLaA" ;
      Vp3 Dl Fem  => "FaCaLataA" ;
      Vp3 Pl Masc => "FaCaLuwA" ;
      Vp3 Pl Fem  => "FaCaLona" ;

      Vp2Sg  Masc => "FaCaLota" ;
      Vp2Sg  Fem  => "FaCaLoti" ;
      Vp2Dl       => "FaCaLotumaA" ;
      Vp2Pl  Masc => "FaCaLotum" ;
      Vp2Pl  Fem  => "FaCaLotunv2a" ;
       
      Vp1Sg       => "FaCaLotu" ;
      Vp1Pl       => "FaCaLonaA"
      } ;
    Impf => case v of {
      Vp3 Sg Masc => "yaFoCuLu" ;
      Vp3 Sg Fem  => "taFoCuLu" ;
      Vp3 Dl Masc => "yaFoCuLaAni" ;
      Vp3 Dl Fem  => "taFoCuLaAni" ;
      Vp3 Pl Masc => "yaFoCuLuwna" ;
      Vp3 Pl Fem  => "yaFoCuLna" ;

      Vp2Sg  Masc => "taFoCuLu" ;
      Vp2Sg  Fem  => "taFoCuLiyna" ;
      Vp2Dl       => "taFoCuLaAni" ;
      Vp2Pl  Masc => "taFoCuLuwna" ;
      Vp2Pl  Fem  => "taFoCuLona" ;
       
      Vp1Sg       => "A?aFoCuLu" ;
      Vp1Pl       => "naFoCuLu"
      }
   }) ;

  u_Verb : Str -> Verb = \s -> {
    s = \\t,p => pattV_u t p (getRoot s) ;
    } ;

-- for html

  tag : Str -> Str = \t -> "<" + t + ">" ;
  etag : Str -> Str = \t -> "</" + t + ">" ;
  atag : Str -> Str -> Str = \t,a -> "<" + t ++ a + ">" ;

  intag : Str -> Str -> Str = \t,s -> tag t ++ s ++ etag t ;
  intagAttr : Str -> Str -> Str -> Str = \t,a,s -> atag t a ++ s ++ etag t ;

  verbTable : Verb -> Str = \v -> 
    let 
      vsp = v.s ! Perf ;
      vsi = v.s ! Impf ;
      tr : Str -> Str = intag "tr" ;
      td : Str -> Str = intag "td" ;
      ts : Str -> Str = \s -> td ("\"" ++ s ++ "\"") ;
      trs : Str -> Str -> VPer -> Str = \s,n,v -> 
        tr (td s ++ td n ++ ts (vsp ! v) ++ ts (vsi ! v))
    in 
    intagAttr "table" "border=1" (
       tr ((td "Persona") ++ (td "Numerus") ++ (td "Perfectum") ++ (td "Imperfectum")) ++
       trs "3. masc." "sing." (Vp3 Sg Masc) ++
       trs "3. fem."  "sing." (Vp3 Sg Fem) ++
       trs "2. masc." "sing." (Vp2Sg Masc) ++
       trs "2. fem."  "sing." (Vp2Sg Fem) ++
       trs "1."       "sing." (Vp1Sg) ++
       trs "3. masc." "dual." (Vp3 Dl Masc) ++
       trs "3. fem."  "dual." (Vp3 Dl Fem) ++
       trs "2."       "dual." (Vp2Dl) ++
       trs "3. masc." "plur." (Vp3 Pl Masc) ++
       trs "3. fem."  "plur." (Vp3 Pl Fem) ++
       trs "2. masc." "plur." (Vp2Pl Masc) ++
       trs "2. fem."  "plur." (Vp2Pl Fem) ++
       trs "1."       "plur." (Vp1Pl)
      ) ;


}