mirror of
https://github.com/GrammaticalFramework/gf-core.git
synced 2026-04-11 05:49:31 -06:00
223 lines
6.1 KiB
HTML
223 lines
6.1 KiB
HTML
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
|
|
<HTML>
|
|
<HEAD>
|
|
<META NAME="generator" CONTENT="http://txt2tags.sf.net">
|
|
<TITLE> The GF Prelude</TITLE>
|
|
</HEAD><BODY BGCOLOR="white" TEXT="black">
|
|
<P ALIGN="center"><CENTER><H1> The GF Prelude</H1>
|
|
<FONT SIZE="4">
|
|
<I>Last update: 2006-02-27 09:41:31 CET</I><BR>
|
|
</FONT></CENTER>
|
|
|
|
<P></P>
|
|
<HR NOSHADE SIZE=1>
|
|
<P></P>
|
|
<UL>
|
|
<LI><A HREF="#toc1">Strings, records, and tables</A>
|
|
<LI><A HREF="#toc2">Optional elements</A>
|
|
<LI><A HREF="#toc3">Infixes. prefixes, and postfixes</A>
|
|
<LI><A HREF="#toc4">Booleans</A>
|
|
<LI><A HREF="#toc5">High-level acces to Predef operations</A>
|
|
<LI><A HREF="#toc6">Lexer-related operations</A>
|
|
<LI><A HREF="#toc7">Miscellaneous</A>
|
|
</UL>
|
|
|
|
<P></P>
|
|
<HR NOSHADE SIZE=1>
|
|
<P></P>
|
|
<P>
|
|
Produced by
|
|
gfdoc - a rudimentary GF document generator.
|
|
(c) Aarne Ranta (<A HREF="mailto:aarne@cs.chalmers.se">aarne@cs.chalmers.se</A>) 2002 under GNU GPL.
|
|
</P>
|
|
<P>
|
|
This file defines some prelude facilities usable in all grammars.
|
|
</P>
|
|
<PRE>
|
|
resource Prelude = open (Predef=Predef) in {
|
|
|
|
oper
|
|
</PRE>
|
|
<P></P>
|
|
<A NAME="toc1"></A>
|
|
<H2>Strings, records, and tables</H2>
|
|
<PRE>
|
|
SS : Type = {s : Str} ;
|
|
ss : Str -> SS = \s -> {s = s} ;
|
|
ss2 : (_,_ : Str) -> SS = \x,y -> ss (x ++ y) ;
|
|
ss3 : (_,_ ,_: Str) -> SS = \x,y,z -> ss (x ++ y ++ z) ;
|
|
|
|
cc2 : (_,_ : SS) -> SS = \x,y -> ss (x.s ++ y.s) ;
|
|
cc3 : (_,_,_ : SS) -> SS = \x,y,z -> ss (x.s ++ y.s ++ z.s) ;
|
|
|
|
SS1 : Type -> Type = \P -> {s : P => Str} ;
|
|
ss1 : (A : Type) -> Str -> SS1 A = \A,s -> {s = table {_ => s}} ;
|
|
|
|
SP1 : Type -> Type = \P -> {s : Str ; p : P} ;
|
|
sp1 : (A : Type) -> Str -> A -> SP1 A = \_,s,a -> {s = s ; p = a} ;
|
|
|
|
constTable : (A,B : Type) -> B -> A => B = \_,_,b -> \\_ => b ;
|
|
constStr : (A : Type) -> Str -> A => Str = \A -> constTable A Str ;
|
|
</PRE>
|
|
<P></P>
|
|
<P>
|
|
Discontinuous constituents.
|
|
</P>
|
|
<PRE>
|
|
SD2 = {s1,s2 : Str} ;
|
|
sd2 : (_,_ : Str) -> SD2 = \x,y -> {s1 = x ; s2 = y} ;
|
|
</PRE>
|
|
<P></P>
|
|
<A NAME="toc2"></A>
|
|
<H2>Optional elements</H2>
|
|
<P>
|
|
Missing form.
|
|
</P>
|
|
<PRE>
|
|
nonExist : Str = variants {} ;
|
|
</PRE>
|
|
<P></P>
|
|
<P>
|
|
Optional string with preference on the string vs. empty.
|
|
</P>
|
|
<PRE>
|
|
optStr : Str -> Str = \s -> variants {s ; []} ;
|
|
strOpt : Str -> Str = \s -> variants {[] ; s} ;
|
|
</PRE>
|
|
<P></P>
|
|
<P>
|
|
Free order between two strings.
|
|
</P>
|
|
<PRE>
|
|
bothWays : Str -> Str -> Str = \x,y -> variants {x ++ y ; y ++ x} ;
|
|
</PRE>
|
|
<P></P>
|
|
<P>
|
|
Parametric order between two strings.
|
|
</P>
|
|
<PRE>
|
|
preOrPost : Bool -> Str -> Str -> Str = \pr,x,y ->
|
|
if_then_Str pr (x ++ y) (y ++ x) ;
|
|
</PRE>
|
|
<P></P>
|
|
<A NAME="toc3"></A>
|
|
<H2>Infixes. prefixes, and postfixes</H2>
|
|
<P>
|
|
Fixes with precedences are defined in <A HREF="Precedence.html">Precedence</A>.
|
|
</P>
|
|
<PRE>
|
|
infixSS : Str -> SS -> SS -> SS = \f,x,y -> ss (x.s ++ f ++ y.s) ;
|
|
prefixSS : Str -> SS -> SS = \f,x -> ss (f ++ x.s) ;
|
|
postfixSS : Str -> SS -> SS = \f,x -> ss (x.s ++ f) ;
|
|
embedSS : Str -> Str -> SS -> SS = \f,g,x -> ss (f ++ x.s ++ g) ;
|
|
</PRE>
|
|
<P></P>
|
|
<A NAME="toc4"></A>
|
|
<H2>Booleans</H2>
|
|
<PRE>
|
|
param Bool = True | False ;
|
|
|
|
oper
|
|
if_then_else : (A : Type) -> Bool -> A -> A -> A = \_,c,d,e ->
|
|
case c of {
|
|
True => d ; ---- should not need to qualify
|
|
False => e
|
|
} ;
|
|
|
|
andB : (_,_ : Bool) -> Bool = \a,b -> if_then_else Bool a b False ;
|
|
orB : (_,_ : Bool) -> Bool = \a,b -> if_then_else Bool a True b ;
|
|
notB : Bool -> Bool = \a -> if_then_else Bool a False True ;
|
|
|
|
if_then_Str : Bool -> Str -> Str -> Str = if_then_else Str ;
|
|
|
|
onlyIf : Bool -> Str -> Str = \b,s -> case b of {
|
|
True => s ;
|
|
_ => nonExist
|
|
} ;
|
|
</PRE>
|
|
<P></P>
|
|
<P>
|
|
Interface to internal booleans
|
|
</P>
|
|
<PRE>
|
|
pbool2bool : Predef.PBool -> Bool = \b -> case b of {
|
|
Predef.PFalse => False ; Predef.PTrue => True
|
|
} ;
|
|
|
|
init : Tok -> Tok = Predef.tk 1 ;
|
|
last : Tok -> Tok = Predef.dp 1 ;
|
|
</PRE>
|
|
<P></P>
|
|
<A NAME="toc5"></A>
|
|
<H2>High-level acces to Predef operations</H2>
|
|
<PRE>
|
|
isNil : Tok -> Bool = \b -> pbool2bool (Predef.eqStr [] b) ;
|
|
|
|
ifTok : (A : Type) -> Tok -> Tok -> A -> A -> A = \A,t,u,a,b ->
|
|
case Predef.eqStr t u of {Predef.PTrue => a ; Predef.PFalse => b} ;
|
|
</PRE>
|
|
<P></P>
|
|
<A NAME="toc6"></A>
|
|
<H2>Lexer-related operations</H2>
|
|
<P>
|
|
Bind together two tokens in some lexers, either obligatorily or optionally
|
|
</P>
|
|
<PRE>
|
|
oper
|
|
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} ;
|
|
</PRE>
|
|
<P></P>
|
|
<P>
|
|
Force capitalization of next word in some unlexers
|
|
</P>
|
|
<PRE>
|
|
capitalize : Str -> Str = \s -> CAPIT ++ s ;
|
|
</PRE>
|
|
<P></P>
|
|
<P>
|
|
These should be hidden, and never changed since they are hardcoded in (un)lexers
|
|
</P>
|
|
<PRE>
|
|
BIND : Str = "&+" ;
|
|
PARA : Str = "&-" ;
|
|
CAPIT : Str = "&|" ;
|
|
</PRE>
|
|
<P></P>
|
|
<A NAME="toc7"></A>
|
|
<H2>Miscellaneous</H2>
|
|
<P>
|
|
Identity function
|
|
</P>
|
|
<PRE>
|
|
id : (A : Type) -> A -> A = \_,a -> a ;
|
|
</PRE>
|
|
<P></P>
|
|
<P>
|
|
Parentheses
|
|
</P>
|
|
<PRE>
|
|
paren : Str -> Str = \s -> "(" ++ s ++ ")" ;
|
|
parenss : SS -> SS = \s -> ss (paren s.s) ;
|
|
</PRE>
|
|
<P></P>
|
|
<P>
|
|
Zero, one, two, or more (elements in a list etc)
|
|
</P>
|
|
<PRE>
|
|
param
|
|
ENumber = E0 | E1 | E2 | Emore ;
|
|
|
|
oper
|
|
eNext : ENumber -> ENumber = \e -> case e of {
|
|
E0 => E1 ; E1 => E2 ; _ => Emore} ;
|
|
|
|
}
|
|
</PRE>
|
|
<P></P>
|
|
|
|
<!-- html code generated by txt2tags 2.3 (http://txt2tags.sf.net) -->
|
|
<!-- cmdline: txt2tags -thtml -\-toc ../prelude/Prelude.txt -->
|
|
</BODY></HTML>
|