forked from GitHub/gf-core
New numeral grammars.
This commit is contained in:
44
grammars/numerals/NumSwedish.gf
Normal file
44
grammars/numerals/NumSwedish.gf
Normal file
@@ -0,0 +1,44 @@
|
||||
--# -path=.:../prelude
|
||||
|
||||
concrete NumSwedish of Numerals = open ResNumSwedish, Prelude in {
|
||||
|
||||
flags startcat = Numeral ; lexer=unglue ; unlexer=glue ;
|
||||
|
||||
lincat Digit = {
|
||||
s : DForm => Str
|
||||
} ;
|
||||
lincat Sub10 = {
|
||||
s : DForm => Str
|
||||
} ;
|
||||
lin n2 = mkTal "två" "tolv" "tjugo" ;
|
||||
lin n3 = mkTal "tre" "tretton" "trettio" ;
|
||||
lin n4 = mkTal "fyra" "fjorton" "fyrtio" ;
|
||||
lin n5 = regTal "fem" ;
|
||||
lin n6 = regTal "sex" ;
|
||||
lin n7 = mkTal "sju" "sjutton" "sjuttio" ;
|
||||
lin n8 = mkTal "åtta" "arton" "åttio" ;
|
||||
lin n9 = mkTal "nio" "nitton" "nittio" ;
|
||||
lin num = \x -> x ;
|
||||
lin pot0 = \d -> {
|
||||
s = table {
|
||||
f => d.s ! f
|
||||
}
|
||||
} ;
|
||||
lin pot01 = {
|
||||
s = table {
|
||||
f => "ett"
|
||||
}
|
||||
} ;
|
||||
lin pot0as1 = \n -> ss (n.s ! ental);
|
||||
lin pot1 = \ d -> ss (d.s ! tiotal);
|
||||
lin pot110 = ss "tio" ;
|
||||
lin pot111 = ss "elva" ;
|
||||
lin pot1as2 = \ n -> n ;
|
||||
lin pot1plus = \ d -> \ e -> ss (glueOpt (d.s ! tiotal) (e.s ! ental)) ;
|
||||
lin pot1to19 = \ d -> ss (d.s ! ton);
|
||||
lin pot2 = \ d -> ss (glueOpt (d.s ! ental) "hundra") ;
|
||||
lin pot2as3 = \ n -> n ;
|
||||
lin pot2plus = \ d -> \ e -> ss (glueOpt (glueOpt (d.s ! ental) "hundra") e.s);
|
||||
lin pot3 = \ n -> ss (glueOpt n.s "tusen");
|
||||
lin pot3plus = \ n -> \ m -> ss (noglueOpt (glueOpt n.s "tusen") m.s);
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
-- numerals from 1 to 999999 in decimal notation. AR 1998 -- 2003
|
||||
-- numerals from 1 to 999999 in decimal notation
|
||||
|
||||
abstract Numerals = {
|
||||
|
||||
@@ -31,10 +31,4 @@ fun
|
||||
pot2as3 : Sub1000 -> Sub1000000 ; -- coercion of 1..999
|
||||
pot3 : Sub1000 -> Sub1000000 ; -- m * 1000
|
||||
pot3plus : Sub1000 -> Sub1000 -> Sub1000000 ; -- m * 1000 + n
|
||||
|
||||
data
|
||||
Numeral = num ;
|
||||
Digit = n2 | n3 | n4 | n5 | n6 | n7 | n8 | n9 ;
|
||||
Sub10 = pot01 | pot0 ;
|
||||
Sub100 = pot110 | pot111 | pot1to19 | pot0as1 | pot1 | pot1plus ;
|
||||
}
|
||||
|
||||
23
grammars/numerals/ResNumSwedish.gf
Normal file
23
grammars/numerals/ResNumSwedish.gf
Normal file
@@ -0,0 +1,23 @@
|
||||
resource ResNumSwedish = {
|
||||
param DForm = ental | ton | tiotal ;
|
||||
oper mkTal : Str -> Str -> Str -> {
|
||||
s : DForm => Str
|
||||
}
|
||||
= \ två -> \ tolv -> \ tjugo -> {
|
||||
s = table {
|
||||
ental => två ;
|
||||
ton => tolv ;
|
||||
tiotal => tjugo
|
||||
}
|
||||
} ;
|
||||
oper regTal : Str -> {
|
||||
s : DForm => Str
|
||||
}
|
||||
= \ fem -> mkTal fem (fem + "ton")(fem + "tio");
|
||||
oper ss : Str -> {
|
||||
s : Str
|
||||
}
|
||||
= \ s -> {
|
||||
s = s
|
||||
} ;
|
||||
}
|
||||
@@ -83,6 +83,10 @@ oper
|
||||
-- bind together two tokens in the lexer, either obligatorily or optionally
|
||||
|
||||
oper
|
||||
bind : Str -> Str -> Str = \x,y -> x ++ "&+" ++ y ;
|
||||
bindOpt : Str -> Str -> Str = \x,y -> variants {bind x y ; x ++ y} ;
|
||||
glue : Str -> Str -> Str = \x,y -> x ++ BIND ++ y ;
|
||||
glueOpt : Str -> Str -> Str = \x,y -> variants {glue x y ; x ++ y} ;
|
||||
noglueOpt : Str -> Str -> Str = \x,y -> variants {x ++ y ; glue x y} ;
|
||||
|
||||
-- this should be hidden, and never changed since it's hardcoded in (un)lexers
|
||||
BIND : Str = "&+" ;
|
||||
} ;
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
concrete TestFin of TestAbs = ResFin ** open Prelude, SyntaxFin in {
|
||||
|
||||
flags startcat=Phr ; lexer=text ; parser=chart ; unlexer=text ;
|
||||
flags startcat=Phr ; lexer=unglue ; unlexer=glue ;
|
||||
|
||||
-- a random sample from the lexicon
|
||||
|
||||
|
||||
Reference in New Issue
Block a user