summaryrefslogtreecommitdiff
path: root/src/GF/Grammar/Grammar.hs
diff options
context:
space:
mode:
Diffstat (limited to 'src/GF/Grammar/Grammar.hs')
-rw-r--r--src/GF/Grammar/Grammar.hs203
1 files changed, 124 insertions, 79 deletions
diff --git a/src/GF/Grammar/Grammar.hs b/src/GF/Grammar/Grammar.hs
index 8ab2356d2..f6ae9249f 100644
--- a/src/GF/Grammar/Grammar.hs
+++ b/src/GF/Grammar/Grammar.hs
@@ -1,18 +1,54 @@
----------------------------------------------------------------------
-- |
--- Module : (Module)
--- Maintainer : (Maintainer)
+-- Module : Grammar
+-- Maintainer : AR
-- Stability : (stable)
-- Portability : (portable)
--
--- > CVS $Date $
--- > CVS $Author $
--- > CVS $Revision $
+-- > CVS $Date: 2005/02/18 19:21:12 $
+-- > CVS $Author: peb $
+-- > CVS $Revision: 1.7 $
--
-- GF source abstract syntax used internally in compilation.
+--
+-- AR 23\/1\/2000 -- 30\/5\/2001 -- 4\/5\/2003
-----------------------------------------------------------------------------
-module Grammar where
+module Grammar (SourceGrammar,
+ SourceModInfo,
+ SourceModule,
+ SourceAbs,
+ SourceRes,
+ SourceCnc,
+ Info(..),
+ Perh,
+ MPr,
+ Type,
+ Cat,
+ Fun,
+ QIdent,
+ Term(..),
+ Patt(..),
+ TInfo(..),
+ Label(..),
+ MetaSymb(..),
+ Decl,
+ Context,
+ Equation,
+ Labelling,
+ Assign,
+ Case,
+ Cases,
+ LocalDef,
+ Param,
+ Altern,
+ Substitution,
+ Branch(..),
+ Con,
+ Trm,
+ wildPatt,
+ varLabel
+ ) where
import Str
import Ident
@@ -21,10 +57,7 @@ import Modules
import Operations
--- AR 23/1/2000 -- 30/5/2001 -- 4/5/2003
-
--- grammar as presented to the compiler
-
+-- | grammar as presented to the compiler
type SourceGrammar = MGrammar Ident Option Info
type SourceModInfo = ModInfo Ident Option Info
@@ -35,29 +68,39 @@ type SourceAbs = Module Ident Option Info
type SourceRes = Module Ident Option Info
type SourceCnc = Module Ident Option Info
--- judgements in abstract syntax
-
+-- | the constructors are judgements in
+--
+-- - abstract syntax (/ABS/)
+--
+-- - resource (/RES/)
+--
+-- - concrete syntax (/CNC/)
+--
+-- and indirection to module (/INDIR/)
data Info =
- AbsCat (Perh Context) (Perh [Term]) -- constructors; must be Id or QId
- | AbsFun (Perh Type) (Perh Term) -- Yes f = canonical
- | AbsTrans Term
+-- judgements in abstract syntax
+ AbsCat (Perh Context) (Perh [Term]) -- ^ (/ABS/) constructors; must be 'Id' or 'QId'
+ | AbsFun (Perh Type) (Perh Term) -- ^ (/ABS/) 'Yes f' = canonical
+ | AbsTrans Term -- ^ (/ABS/)
-- judgements in resource
- | ResParam (Perh [Param])
- | ResValue (Perh Type) -- to mark parameter constructors for lookup
- | ResOper (Perh Type) (Perh Term)
+ | ResParam (Perh [Param]) -- ^ (/RES/)
+ | ResValue (Perh Type) -- ^ (/RES/) to mark parameter constructors for lookup
+ | ResOper (Perh Type) (Perh Term) -- ^ (/RES/)
-- judgements in concrete syntax
- | CncCat (Perh Type) (Perh Term) MPr -- lindef ini'zed,
- | CncFun (Maybe (Ident,(Context,Type))) (Perh Term) MPr -- type info added at TC
+ | CncCat (Perh Type) (Perh Term) MPr -- ^ (/CNC/) lindef ini'zed,
+ | CncFun (Maybe (Ident,(Context,Type))) (Perh Term) MPr -- (/CNC/) type info added at 'TC'
--- indirection to module Ident; the Bool says if canonical
- | AnyInd Bool Ident
+-- indirection to module Ident
+ | AnyInd Bool Ident -- ^ (/INDIR/) the 'Bool' says if canonical
deriving (Read, Show)
-type Perh a = Perhaps a Ident -- to express indirection to other module
+-- | to express indirection to other module
+type Perh a = Perhaps a Ident
-type MPr = Perhaps Term Ident -- printname
+-- | printname
+type MPr = Perhaps Term Ident
type Type = Term
type Cat = QIdent
@@ -66,80 +109,81 @@ type Fun = QIdent
type QIdent = (Ident,Ident)
data Term =
- Vr Ident -- variable
- | Cn Ident -- constant
- | Con Ident -- constructor
- | EData -- to mark in definition that a fun is a constructor
- | Sort String -- basic type
- | EInt Int -- integer literal
- | K String -- string literal or token: "foo"
- | Empty -- the empty string []
-
- | App Term Term -- application: f a
- | Abs Ident Term -- abstraction: \x -> b
- | Meta MetaSymb -- metavariable: ?i (only parsable: ? = ?0)
- | Prod Ident Term Term -- function type: (x : A) -> B
- | Eqs [Equation] -- abstraction by cases: fn {x y -> b ; z u -> c}
+ Vr Ident -- ^ variable
+ | Cn Ident -- ^ constant
+ | Con Ident -- ^ constructor
+ | EData -- ^ to mark in definition that a fun is a constructor
+ | Sort String -- ^ basic type
+ | EInt Int -- ^ integer literal
+ | K String -- ^ string literal or token: @\"foo\"@
+ | Empty -- ^ the empty string @[]@
+
+ | App Term Term -- ^ application: @f a@
+ | Abs Ident Term -- ^ abstraction: @\x -> b@
+ | Meta MetaSymb -- ^ metavariable: @?i@ (only parsable: ? = ?0)
+ | Prod Ident Term Term -- ^ function type: @(x : A) -> B@
+ | Eqs [Equation] -- ^ abstraction by cases: @fn {x y -> b ; z u -> c}@
-- only used in internal representation
- | Typed Term Term -- type-annotated term
-
--- below this only for concrete syntax
- | RecType [Labelling] -- record type: { p : A ; ...}
- | R [Assign] -- record: { p = a ; ...}
- | P Term Label -- projection: r.p
- | ExtR Term Term -- extension: R ** {x : A} (both types and terms)
+ | Typed Term Term -- ^ type-annotated term
+--
+-- /below this, the constructors are only for concrete syntax/
+ | RecType [Labelling] -- ^ record type: @{ p : A ; ...}@
+ | R [Assign] -- ^ record: @{ p = a ; ...}@
+ | P Term Label -- ^ projection: @r.p@
+ | ExtR Term Term -- ^ extension: @R ** {x : A}@ (both types and terms)
- | Table Term Term -- table type: P => A
- | T TInfo [Case] -- table: table {p => c ; ...}
- | TSh TInfo [Cases] -- table with discjunctive patters (only back end opt)
- | V Type [Term] -- table given as course of values: table T [c1 ; ... ; cn]
- | S Term Term -- selection: t ! p
-
- | Let LocalDef Term -- local definition: let {t : T = a} in b
+ | Table Term Term -- ^ table type: @P => A@
+ | T TInfo [Case] -- ^ table: @table {p => c ; ...}@
+ | TSh TInfo [Cases] -- ^ table with discjunctive patters (only back end opt)
+ | V Type [Term] -- ^ table given as course of values: @table T [c1 ; ... ; cn]@
+ | S Term Term -- ^ selection: @t ! p@
- | Alias Ident Type Term -- constant and its definition, used in inlining
+ | Let LocalDef Term -- ^ local definition: @let {t : T = a} in b@
- | Q Ident Ident -- qualified constant from a package
- | QC Ident Ident -- qualified constructor from a package
+ | Alias Ident Type Term -- ^ constant and its definition, used in inlining
- | C Term Term -- concatenation: s ++ t
- | Glue Term Term -- agglutination: s + t
+ | Q Ident Ident -- ^ qualified constant from a package
+ | QC Ident Ident -- ^ qualified constructor from a package
- | FV [Term] -- alternatives in free variation: variants { s ; ... }
+ | C Term Term -- ^ concatenation: @s ++ t@
+ | Glue Term Term -- ^ agglutination: @s + t@
- | Alts (Term, [(Term, Term)]) -- alternatives by prefix: pre {t ; s/c ; ...}
- | Strs [Term] -- conditioning prefix strings: strs {s ; ...}
+ | FV [Term] -- ^ alternatives in free variation: @variants { s ; ... }@
- --- these three are obsolete
- | LiT Ident -- linearization type
- | Ready Str -- result of compiling; not to be parsed ...
- | Computed Term -- result of computing: not to be reopened nor parsed
+ | Alts (Term, [(Term, Term)]) -- ^ alternatives by prefix: @pre {t ; s\/c ; ...}@
+ | Strs [Term] -- ^ conditioning prefix strings: @strs {s ; ...}@
+--
+-- /below this, the last three constructors are obsolete/
+ | LiT Ident -- ^ linearization type
+ | Ready Str -- ^ result of compiling; not to be parsed ...
+ | Computed Term -- ^ result of computing: not to be reopened nor parsed
deriving (Read, Show, Eq, Ord)
data Patt =
- PC Ident [Patt] -- constructor pattern: C p1 ... pn C
- | PP Ident Ident [Patt] -- package constructor pattern: P.C p1 ... pn P.C
- | PV Ident -- variable pattern: x
- | PW -- wild card pattern: _
- | PR [(Label,Patt)] -- record pattern: {r = p ; ...} -- only concrete
- | PString String -- string literal pattern: "foo" -- only abstract
- | PInt Int -- integer literal pattern: 12 -- only abstract
- | PT Type Patt -- type-annotated pattern
+ PC Ident [Patt] -- ^ constructor pattern: @C p1 ... pn@ @C@
+ | PP Ident Ident [Patt] -- ^ package constructor pattern: @P.C p1 ... pn@ @P.C@
+ | PV Ident -- ^ variable pattern: @x@
+ | PW -- ^ wild card pattern: @_@
+ | PR [(Label,Patt)] -- ^ record pattern: @{r = p ; ...}@ -- only concrete
+ | PString String -- ^ string literal pattern: @\"foo\"@ -- only abstract
+ | PInt Int -- ^ integer literal pattern: @12@ -- only abstract
+ | PT Type Patt -- ^ type-annotated pattern
deriving (Read, Show, Eq, Ord)
--- to guide computation and type checking of tables
+-- | to guide computation and type checking of tables
data TInfo =
- TRaw -- received from parser; can be anything
- | TTyped Type -- type annontated, but can be anything
- | TComp Type -- expanded
- | TWild Type -- just one wild card pattern, no need to expand
+ TRaw -- ^ received from parser; can be anything
+ | TTyped Type -- ^ type annontated, but can be anything
+ | TComp Type -- ^ expanded
+ | TWild Type -- ^ just one wild card pattern, no need to expand
deriving (Read, Show, Eq, Ord)
+-- | record label
data Label =
LIdent String
| LVar Int
- deriving (Read, Show, Eq, Ord) -- record label
+ deriving (Read, Show, Eq, Ord)
newtype MetaSymb = MetaSymb Int deriving (Read, Show, Eq, Ord)
@@ -158,10 +202,11 @@ type Altern = (Term, [(Term, Term)])
type Substitution = [(Ident, Term)]
--- branches à la Alfa
+-- | branches à la Alfa
newtype Branch = Branch (Con,([Ident],Term)) deriving (Eq, Ord,Show,Read)
type Con = Ident ---
+varLabel :: Int -> Label
varLabel = LVar
wildPatt :: Patt