summaryrefslogtreecommitdiff
path: root/examples/tutorial/syntax/GrammarIta.gf
blob: 81c0e79fe3b40841cd55e5f02318a0210676b349 (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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
--# -path=.:prelude

concrete GrammarIta of Grammar = open Prelude, MorphoIta in {

  lincat
    Phr  = {s : Str} ;
    S    = {s : Str} ;
    QS   = {s : Str} ;
    Cl   = Clause ;
    QCl  = Clause ;
    NP   = NounPhrase ;
    IP   = NounPhrase ;
    CN   = Noun ;
    Det  = {s : Gender => Str ; n : Number} ;
    IDet = {s : Gender => Str ; n : Number} ;
    AP   = {s : Gender => Number => Str} ;
    AdA  = {s : Str} ;
    VP   = VerbPhrase ;
    N    = Noun ;
    A    = Adjective ;
    V    = Verb ;
    V2   = Verb2 ;
    Conj = {s : Str} ;
    Subj = {s : Str} ;
    Pol  = {s : Str ; p : Bool} ;

  oper
    Clause     : Type = {s : Bool => Str} ;
    NounPhrase : Type = {s : Str ; g : Gender ; n : Number} ;
    VerbPhrase : Type = {s : Bool => Gender => Number => Str} ; 
  lin
    PhrS = postfixSS "." ;
    PhrQS = postfixSS "?" ;

    UseCl  pol cl  = {s = pol.s ++ cl.s  ! pol.p} ;
    UseQCl pol qcl = {s = pol.s ++ qcl.s ! pol.p} ;

    QuestCl cl = cl ;

    SubjS subj s = {s = subj.s ++ s.s} ;

    PredVP  = predVP ;

    QuestVP = predVP ;

    QuestV2 ip np v2 = 
      {s = \\b => v2.c ++ ip.s ++ posneg b ++ v2.s ! np.n ++ np.s} ;
 
    ComplV2 v2 np = {s = \\b,_,n => posneg b ++ v2.s ! n ++ v2.c ++ np.s} ;
    ComplAP ap    = {s = \\b,g,n => posneg b ++ copula n ++ ap.s ! g ! n} ;

    DetCN  det cn = {s = det.s ! cn.g ++ cn.s ! det.n ; g = cn.g ; n = det.n} ;

    ModCN ap cn  = {s = \\n => cn.s ! n ++ ap.s ! cn.g ! n ; g = cn.g} ;

    AdVP adv vp  = {s = \\p,n,g => vp.s ! p ! n ! g ++ adv.s} ;
    AdAP ada ap  = {s = \\n,g => ada.s ++ ap.s ! n ! g} ;

    IDetCN det cn = {s = det.s ! cn.g ++ cn.s ! det.n ; g = cn.g ; n = det.n} ;

    ConjS c a b = {s = a.s ++ c.s ++ b.s} ;
    ConjNP c a b = {s = a.s ++ c.s ++ b.s ; n = Pl ; g = conjGender a.g b.g} ;

    UseN n = n ;
    UseA a = a ;
    UseV v = {s = \\b,_,n => posneg b ++ v.s ! n} ;

    this_Det = mkDet Sg (regAdjective "questo") ;
    that_Det = mkDet Sg quello ;
    these_Det = mkDet Pl (regAdjective "questo") ;
    those_Det = mkDet Pl quello ;
    every_Det = {s = \\_ => "ogni" ; n = Sg} ;
    theSg_Det = {s = artDef Sg ; n = Sg} ;
    thePl_Det = {s = artDef Pl ; n = Pl} ;
    indef_Det = {s = artIndef ; n = Sg} ;
    plur_Det = {s = \\_ => [] ; n = Pl} ;
    two_Det = {s = \\_ => "due" ; n = Pl} ;
    today_Adv = {s = "oggi"} ;
    very_AdA = {s = "molto"} ;
    which_IDet   = {s = \\_ => "quale" ; n = Sg} ;
    and_Conj = {s = "e"} ;
    because_Subj = {s = "perché"} ;

    PPos = {s = [] ; p = True} ;
    PNeg = {s = [] ; p = False} ;

  oper
    predVP : NounPhrase -> VerbPhrase -> Clause = \np,vp -> 
      {s = \\b => np.s ++ vp.s ! b ! np.g ! np.n} ;

    copula : Number -> Str = \n -> case n of {
      Sg => "è" ;
      Pl => "sono"
      } ;

    posneg : Bool -> Str = \b -> case b of {
      True => [] ;
      False => "non"
      } ;

    mkDet : Number -> Adjective -> Det = \n,adj -> {
      s = \\g => adj.s ! g ! n ;
      n = n ;
      lock_Det = <>
      } ;

    artDef : Number -> Gender => Str = \n -> case n of {
      Sg => table {
        Masc => pre {"il"  ; "lo" / sImpuro} ;
        Fem  => "la"
        } ;
      Pl => table {
        Masc => pre {"i"  ; "gli" / sImpuro ; "gli" / vowel} ;
        Fem  => "le"
        }
      } ;

    artIndef : Gender => Str = table {
      Masc => pre {"un"  ; "uno" / sImpuro} ;
      Fem  => pre {"una" ; "un'" / vowel}
      } ;

    conjGender : Gender -> Gender -> Gender = \g,h -> case g of {
      Masc => Masc ;
      _ => h
    } ;

    quello : Adjective = 
      let 
        quel = pre {"quel"  ; "quello" / sImpuro ; "quell'" / vowel} ;
        quei = pre {"quei"  ; "quegli" / sImpuro ; "quegli" / vowel} ;
      in mkAdjective quel "quella" quei "quelle" ;

    sImpuro : Strs = strs {"sb" ; "sp" ; "sy" ; "z"} ;
    vowel   : Strs = strs {"a" ; "e" ; "i" ; "o" ; "u"} ;


}