diff --git a/grammars/numerals/NumSwedish.gf b/grammars/numerals/NumSwedish.gf new file mode 100644 index 000000000..c216ff596 --- /dev/null +++ b/grammars/numerals/NumSwedish.gf @@ -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); + } diff --git a/grammars/numerals/Numerals.gf b/grammars/numerals/Numerals.gf index c0e293059..b725070dc 100644 --- a/grammars/numerals/Numerals.gf +++ b/grammars/numerals/Numerals.gf @@ -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 ; } diff --git a/grammars/numerals/ResNumSwedish.gf b/grammars/numerals/ResNumSwedish.gf new file mode 100644 index 000000000..2f4c80c9a --- /dev/null +++ b/grammars/numerals/ResNumSwedish.gf @@ -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 + } ; + } diff --git a/grammars/prelude/Prelude.gf b/grammars/prelude/Prelude.gf index bda2f5f6d..5d8734d04 100644 --- a/grammars/prelude/Prelude.gf +++ b/grammars/prelude/Prelude.gf @@ -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 = "&+" ; } ; diff --git a/grammars/resource/finnish/TestFin.gf b/grammars/resource/finnish/TestFin.gf index 9408e98f3..5de29ffa8 100644 --- a/grammars/resource/finnish/TestFin.gf +++ b/grammars/resource/finnish/TestFin.gf @@ -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