1
0
forked from GitHub/gf-core

Improving unicode menus, e.g. in Letter.

This commit is contained in:
aarne
2004-01-29 12:03:23 +00:00
parent 4c31deb839
commit fdddeca0d0
10 changed files with 1224 additions and 2 deletions

287
examples/letter/Letter.gfcm Normal file

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,80 @@
--1 An Abstract Syntax for Business and Love Letters
--
-- This file defines the abstract syntax of a grammar set whose concrete syntax
-- has so far been written to five languages: English, Finnish, French, Russian,
-- and Swedish.
--
-- The main category of the grammar is $Letter$. The other categories are
-- parts of the letter.
flags startcat=Letter ;
cat
Letter ;
Recipient ; Author ;
Message ;
Heading ; Ending ;
Mode ; Sentence ; NounPhrase ; Position ;
-- There is just one top-level letter structure.
fun
MkLetter : Heading -> Message -> Ending -> Letter ;
-- The heading consists of a greeting of the recipient. The $JustHello$
-- function will actually suppress the name (and title) of the recipient,
-- but the $Recipient$ argument keeps track of the gender and number.
DearRec : Recipient -> Heading ;
PlainRec : Recipient -> Heading ;
HelloRec : Recipient -> Heading ;
JustHello : Recipient -> Heading ;
-- A message is a sentence with of without a *mode*, which is either
-- regret or honour.
ModeSent : Mode -> Sentence -> Message ;
PlainSent : Sentence -> Message ;
Honour, Regret : Mode ;
-- The ending is either formal or informal. It does not currently depend on
-- the heading: making it so would eliminate formality mismatches between
-- the heading and the ending.
FormalEnding : Author -> Ending ;
InformalEnding : Author -> Ending ;
-- The recipient is either a colleague, colleagues, or darling.
-- It can also be a named person. The gender distinction is made
-- because there are things in the body of the letter that depend on it.
ColleagueHe, ColleagueShe : Recipient ;
ColleaguesHe, ColleaguesShe : Recipient ;
DarlingHe, DarlingShe : Recipient ;
NameHe, NameShe : String -> Recipient ;
-- For the author, there is likewise a fixed set of titles, plus the named author.
-- Gender distinctions could be useful even here, for the same reason as with
-- $Recipient$. Notice that the rendering of $Spouse$ will depend on the
-- gender of the recipient.
President, Mother, Spouse, Dean : Author ;
Name : String -> Author ;
-- As for the message body, no much choice is yet available: one can say that
-- the recipient is promoted to some position, that someone has gone bankrupt,
-- or that the author loves the recipient.
BePromoted : Position -> Sentence ;
GoBankrupt : NounPhrase -> Sentence ;
ILoveYou : Sentence ;
Competitor : NounPhrase ;
Company : NounPhrase ;
OurCustomers : NounPhrase ;
Senior : Position ;
ProjectManager : Position ;

View File

@@ -0,0 +1,151 @@
--1 An English Concrete Syntax for Business and Love Letters
--
-- This file defines the English syntax of the grammar set
-- whose abstract syntax is $letter.Abs.gf$.
include letter.Abs.gf ;
flags lexer=textlit ; unlexer=textlit ;
param Sex = masc | fem ;
param Num = sg | pl ;
param Kas = nom | acc ;
param DepNum = depnum | cnum Num ;
lintype SS = {s : Str} ;
lintype SSDep = {s : Num => Sex => Str} ; -- needs Num and Sex
lintype SSSrc = {s : Str ; n : Num ; x : Sex} ; -- gives Num and Sex
lintype SSSrc2 = {s : Num => Sex => Str ; n : DepNum ; x : Sex} ; -- gives and needs
lintype SSDep2 = {s : DepNum => Sex => Num => Sex => Str} ; -- needs Auth's & Recp's
lintype SSSrcNum = {s : Str ; n : Num} ; -- gives Num only
oper
ss : Str -> SS = \s -> {s = s} ;
constNX : Str -> Num -> Sex -> SSSrc2 = \str,num,sex ->
{s = table {_ => table {_ => str}} ; n = cnum num ; x = sex} ;
dep2num : DepNum -> Num -> Num = \dn,n -> case dn of {
depnum => n ;
cnum cn => cn
} ;
lincat
Letter = SS ;
Recipient = SSSrc ;
Author = SSSrc2 ;
Message = SSDep2 ;
Heading = SSSrc ;
Ending = SSSrc2 ;
Mode = SSDep2 ;
Sentence = SSDep2 ;
NounPhrase = SSSrcNum ;
Position = SSDep ;
lin
MkLetter head mess end =
ss (head.s ++ "," ++ "<p>" ++
mess.s ! end.n ! end.x ! head.n ! head.x ++ "." ++ "<p>" ++
end.s ! head.n ! head.x) ;
DearRec rec = {s = "Dear" ++ rec.s ; n = rec.n ; x = rec.x} ;
PlainRec rec = rec ;
HelloRec rec = {s = "Hello" ++ rec.s ; n = rec.n ; x = rec.x} ;
JustHello rec = {s = "Hello" ; n = rec.n ; x = rec.x} ;
ModeSent mode sent =
{s =
table {dna => table {xa => table {nr => table {xr =>
mode.s ! dna ! xa ! nr ! xr ++ sent.s ! dna ! xa ! nr ! xr}}}}
} ;
PlainSent sent = sent ;
FormalEnding auth =
{s = table {n => table {x =>
["Sincerely yours <p>"] ++ auth.s ! n ! x}} ; n = auth.n ; x = auth.x} ;
InformalEnding auth =
{s = table {n => table {x =>
["With best regards <p>"] ++ auth.s ! n ! x}} ; n = auth.n ; x = auth.x} ;
ColleaguesHe = {s = kollega ! pl ; n = pl ; x = masc} ;
ColleaguesShe = {s = kollega ! pl ; n = pl ; x = fem} ;
ColleagueHe = {s = kollega ! sg ; n = sg ; x = masc} ;
ColleagueShe = {s = kollega ! sg ; n = sg ; x = fem} ;
DarlingHe = {s = "darling" ; n = sg ; x = masc} ;
DarlingShe = {s = "darling" ; n = sg ; x = fem} ;
NameHe s = {s = s.s ; n = sg ; x = masc} ;
NameShe s = {s = s.s ; n = sg ; x = fem} ;
Honour = {s =
table {dna => table {xa => table {nr => table {xr =>
let {na = dep2num dna nr} in
ego ! na ! nom ++ ["have the honour to inform you that"]}}}}
} ;
Regret = {s =
table {dna => table {xa => table {nr => table {xr =>
let {na = dep2num dna nr} in
ego ! na ! nom ++ am ! na ++ ["sorry to inform you that"]}}}}
} ;
President = constNX ["the President"] sg masc ;
Mother = constNX "Mom" sg fem ;
Spouse = {s = table {