mirror of
https://github.com/GrammaticalFramework/gf-core.git
synced 2026-04-29 14:32:51 -06:00
Use rec and sig for records.
This commit is contained in:
@@ -72,7 +72,6 @@ data Tree :: * -> * where
|
||||
ENeg :: Exp -> Tree Exp_
|
||||
EApp :: Exp -> Exp -> Tree Exp_
|
||||
EProj :: Exp -> Ident -> Tree Exp_
|
||||
EEmptyRec :: Tree Exp_
|
||||
ERecType :: [FieldType] -> Tree Exp_
|
||||
ERec :: [FieldValue] -> Tree Exp_
|
||||
EVar :: Ident -> Tree Exp_
|
||||
@@ -232,7 +231,6 @@ instance Show (Tree c) where
|
||||
ENeg exp -> opar n . showString "ENeg" . showChar ' ' . showsPrec 1 exp . cpar n
|
||||
EApp exp0 exp1 -> opar n . showString "EApp" . showChar ' ' . showsPrec 1 exp0 . showChar ' ' . showsPrec 1 exp1 . cpar n
|
||||
EProj exp i -> opar n . showString "EProj" . showChar ' ' . showsPrec 1 exp . showChar ' ' . showsPrec 1 i . cpar n
|
||||
EEmptyRec -> showString "EEmptyRec"
|
||||
ERecType fieldtypes -> opar n . showString "ERecType" . showChar ' ' . showsPrec 1 fieldtypes . cpar n
|
||||
ERec fieldvalues -> opar n . showString "ERec" . showChar ' ' . showsPrec 1 fieldvalues . cpar n
|
||||
EVar i -> opar n . showString "EVar" . showChar ' ' . showsPrec 1 i . cpar n
|
||||
@@ -291,7 +289,6 @@ johnMajorEq (EMod exp0 exp1) (EMod exp0_ exp1_) = exp0 == exp0_ && exp1 == exp1_
|
||||
johnMajorEq (ENeg exp) (ENeg exp_) = exp == exp_
|
||||
johnMajorEq (EApp exp0 exp1) (EApp exp0_ exp1_) = exp0 == exp0_ && exp1 == exp1_
|
||||
johnMajorEq (EProj exp i) (EProj exp_ i_) = exp == exp_ && i == i_
|
||||
johnMajorEq EEmptyRec EEmptyRec = True
|
||||
johnMajorEq (ERecType fieldtypes) (ERecType fieldtypes_) = fieldtypes == fieldtypes_
|
||||
johnMajorEq (ERec fieldvalues) (ERec fieldvalues_) = fieldvalues == fieldvalues_
|
||||
johnMajorEq (EVar i) (EVar i_) = i == i_
|
||||
@@ -349,21 +346,20 @@ instance Ord (Tree c) where
|
||||
index (ENeg _) = 35
|
||||
index (EApp _ _) = 36
|
||||
index (EProj _ _) = 37
|
||||
index (EEmptyRec ) = 38
|
||||
index (ERecType _) = 39
|
||||
index (ERec _) = 40
|
||||
index (EVar _) = 41
|
||||
index (EType ) = 42
|
||||
index (EStr _) = 43
|
||||
index (EInt _) = 44
|
||||
index (EMeta ) = 45
|
||||
index (LetDef _ _ _) = 46
|
||||
index (Case _ _) = 47
|
||||
index (VVar _) = 48
|
||||
index (VWild ) = 49
|
||||
index (FieldType _ _) = 50
|
||||
index (FieldValue _ _) = 51
|
||||
index (Ident _) = 52
|
||||
index (ERecType _) = 38
|
||||
index (ERec _) = 39
|
||||
index (EVar _) = 40
|
||||
index (EType ) = 41
|
||||
index (EStr _) = 42
|
||||
index (EInt _) = 43
|
||||
index (EMeta ) = 44
|
||||
index (LetDef _ _ _) = 45
|
||||
index (Case _ _) = 46
|
||||
index (VVar _) = 47
|
||||
index (VWild ) = 48
|
||||
index (FieldType _ _) = 49
|
||||
index (FieldValue _ _) = 50
|
||||
index (Ident _) = 51
|
||||
compareSame (Module imports decls) (Module imports_ decls_) = mappend (compare imports imports_) (compare decls decls_)
|
||||
compareSame (Import i) (Import i_) = compare i i_
|
||||
compareSame (DataDecl i exp consdecls) (DataDecl i_ exp_ consdecls_) = mappend (compare i i_) (mappend (compare exp exp_) (compare consdecls consdecls_))
|
||||
@@ -402,7 +398,6 @@ instance Ord (Tree c) where
|
||||
compareSame (ENeg exp) (ENeg exp_) = compare exp exp_
|
||||
compareSame (EApp exp0 exp1) (EApp exp0_ exp1_) = mappend (compare exp0 exp0_) (compare exp1 exp1_)
|
||||
compareSame (EProj exp i) (EProj exp_ i_) = mappend (compare exp exp_) (compare i i_)
|
||||
compareSame EEmptyRec EEmptyRec = EQ
|
||||
compareSame (ERecType fieldtypes) (ERecType fieldtypes_) = compare fieldtypes fieldtypes_
|
||||
compareSame (ERec fieldvalues) (ERec fieldvalues_) = compare fieldvalues fieldvalues_
|
||||
compareSame (EVar i) (EVar i_) = compare i i_
|
||||
|
||||
@@ -48,7 +48,8 @@ The reserved words used in Syntax are the following: \\
|
||||
{\reserved{Type}} &{\reserved{case}} &{\reserved{data}} \\
|
||||
{\reserved{derive}} &{\reserved{else}} &{\reserved{if}} \\
|
||||
{\reserved{import}} &{\reserved{in}} &{\reserved{let}} \\
|
||||
{\reserved{of}} &{\reserved{then}} &{\reserved{where}} \\
|
||||
{\reserved{of}} &{\reserved{rec}} &{\reserved{sig}} \\
|
||||
{\reserved{then}} &{\reserved{where}} & \\
|
||||
\end{tabular}\\
|
||||
|
||||
The symbols used in Syntax are the following: \\
|
||||
@@ -118,7 +119,7 @@ All other symbols are terminals.\\
|
||||
|
||||
\begin{tabular}{lll}
|
||||
{\nonterminal{Pattern1}} & {\arrow} &{\terminal{(}} {\nonterminal{Ident}} {\nonterminal{ListPattern}} {\terminal{)}} \\
|
||||
& {\delimit} &{\terminal{\{}} {\nonterminal{ListFieldPattern}} {\terminal{\}}} \\
|
||||
& {\delimit} &{\terminal{rec}} {\terminal{\{}} {\nonterminal{ListFieldPattern}} {\terminal{\}}} \\
|
||||
& {\delimit} &{\terminal{Type}} \\
|
||||
& {\delimit} &{\nonterminal{String}} \\
|
||||
& {\delimit} &{\nonterminal{Integer}} \\
|
||||
@@ -229,9 +230,8 @@ All other symbols are terminals.\\
|
||||
\end{tabular}\\
|
||||
|
||||
\begin{tabular}{lll}
|
||||
{\nonterminal{Exp11}} & {\arrow} &{\terminal{\{}} {\terminal{\}}} \\
|
||||
& {\delimit} &{\terminal{\{}} {\nonterminal{ListFieldType}} {\terminal{\}}} \\
|
||||
& {\delimit} &{\terminal{\{}} {\nonterminal{ListFieldValue}} {\terminal{\}}} \\
|
||||
{\nonterminal{Exp11}} & {\arrow} &{\terminal{sig}} {\terminal{\{}} {\nonterminal{ListFieldType}} {\terminal{\}}} \\
|
||||
& {\delimit} &{\terminal{rec}} {\terminal{\{}} {\nonterminal{ListFieldValue}} {\terminal{\}}} \\
|
||||
& {\delimit} &{\nonterminal{Ident}} \\
|
||||
& {\delimit} &{\terminal{Type}} \\
|
||||
& {\delimit} &{\nonterminal{String}} \\
|
||||
@@ -245,7 +245,8 @@ All other symbols are terminals.\\
|
||||
\end{tabular}\\
|
||||
|
||||
\begin{tabular}{lll}
|
||||
{\nonterminal{ListFieldType}} & {\arrow} &{\nonterminal{FieldType}} \\
|
||||
{\nonterminal{ListFieldType}} & {\arrow} &{\emptyP} \\
|
||||
& {\delimit} &{\nonterminal{FieldType}} \\
|
||||
& {\delimit} &{\nonterminal{FieldType}} {\terminal{;}} {\nonterminal{ListFieldType}} \\
|
||||
\end{tabular}\\
|
||||
|
||||
@@ -254,7 +255,8 @@ All other symbols are terminals.\\
|
||||
\end{tabular}\\
|
||||
|
||||
\begin{tabular}{lll}
|
||||
{\nonterminal{ListFieldValue}} & {\arrow} &{\nonterminal{FieldValue}} \\
|
||||
{\nonterminal{ListFieldValue}} & {\arrow} &{\emptyP} \\
|
||||
& {\delimit} &{\nonterminal{FieldValue}} \\
|
||||
& {\delimit} &{\nonterminal{FieldValue}} {\terminal{;}} {\nonterminal{ListFieldValue}} \\
|
||||
\end{tabular}\\
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ import Data.Maybe (isNothing, fromJust)
|
||||
-- local parameters
|
||||
|
||||
topLayout = True
|
||||
layoutWords = ["let","where","of"]
|
||||
layoutWords = ["let","where","of","rec","sig"]
|
||||
layoutStopWords = ["in"]
|
||||
|
||||
-- layout separators
|
||||
|
||||
@@ -84,7 +84,7 @@ eitherResIdent tv s = treeFind resWords
|
||||
| s > a = treeFind right
|
||||
| s == a = t
|
||||
|
||||
resWords = b "import" (b "derive" (b "case" (b "Type" N N) (b "data" N N)) (b "if" (b "else" N N) N)) (b "of" (b "let" (b "in" N N) N) (b "where" (b "then" N N) N))
|
||||
resWords = b "in" (b "derive" (b "case" (b "Type" N N) (b "data" N N)) (b "if" (b "else" N N) (b "import" N N))) (b "sig" (b "of" (b "let" N N) (b "rec" N N)) (b "where" (b "then" N N) N))
|
||||
where b s = B s (TS s)
|
||||
|
||||
unescapeInitTail :: String -> String
|
||||
|
||||
@@ -79,7 +79,7 @@ eitherResIdent tv s = treeFind resWords
|
||||
| s > a = treeFind right
|
||||
| s == a = t
|
||||
|
||||
resWords = b "import" (b "derive" (b "case" (b "Type" N N) (b "data" N N)) (b "if" (b "else" N N) N)) (b "of" (b "let" (b "in" N N) N) (b "where" (b "then" N N) N))
|
||||
resWords = b "in" (b "derive" (b "case" (b "Type" N N) (b "data" N N)) (b "if" (b "else" N N) (b "import" N N))) (b "sig" (b "of" (b "let" N N) (b "rec" N N)) (b "where" (b "then" N N) N))
|
||||
where b s = B s (TS s)
|
||||
|
||||
unescapeInitTail :: String -> String
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -49,6 +49,8 @@ import Transfer.ErrM
|
||||
'in' { PT _ (TS "in") }
|
||||
'let' { PT _ (TS "let") }
|
||||
'of' { PT _ (TS "of") }
|
||||
'rec' { PT _ (TS "rec") }
|
||||
'sig' { PT _ (TS "sig") }
|
||||
'then' { PT _ (TS "then") }
|
||||
'where' { PT _ (TS "where") }
|
||||
|
||||
@@ -108,7 +110,7 @@ Pattern : Ident Pattern1 ListPattern { PConsTop $1 $2 (reverse $3) }
|
||||
|
||||
Pattern1 :: { Pattern }
|
||||
Pattern1 : '(' Ident ListPattern ')' { PCons $2 (reverse $3) }
|
||||
| '{' ListFieldPattern '}' { PRec $2 }
|
||||
| 'rec' '{' ListFieldPattern '}' { PRec $3 }
|
||||
| 'Type' { PType }
|
||||
| String { PStr $1 }
|
||||
| Integer { PInt $1 }
|
||||
@@ -219,9 +221,8 @@ Exp10 : Exp10 '.' Ident { EProj $1 $3 }
|
||||
|
||||
|
||||
Exp11 :: { Exp }
|
||||
Exp11 : '{' '}' { EEmptyRec }
|
||||
| '{' ListFieldType '}' { ERecType $2 }
|
||||
| '{' ListFieldValue '}' { ERec $2 }
|
||||
Exp11 : 'sig' '{' ListFieldType '}' { ERecType $3 }
|
||||
| 'rec' '{' ListFieldValue '}' { ERec $3 }
|
||||
| Ident { EVar $1 }
|
||||
| 'Type' { EType }
|
||||
| String { EStr $1 }
|
||||
@@ -235,7 +236,8 @@ FieldType : Ident ':' Exp { FieldType $1 $3 }
|
||||
|
||||
|
||||
ListFieldType :: { [FieldType] }
|
||||
ListFieldType : FieldType { (:[]) $1 }
|
||||
ListFieldType : {- empty -} { [] }
|
||||
| FieldType { (:[]) $1 }
|
||||
| FieldType ';' ListFieldType { (:) $1 $3 }
|
||||
|
||||
|
||||
@@ -244,7 +246,8 @@ FieldValue : Ident '=' Exp { FieldValue $1 $3 }
|
||||
|
||||
|
||||
ListFieldValue :: { [FieldValue] }
|
||||
ListFieldValue : FieldValue { (:[]) $1 }
|
||||
ListFieldValue : {- empty -} { [] }
|
||||
| FieldValue { (:[]) $1 }
|
||||
| FieldValue ';' ListFieldValue { (:) $1 $3 }
|
||||
|
||||
|
||||
|
||||
@@ -89,7 +89,7 @@ instance Print (Tree c) where
|
||||
ConsDecl i exp -> prPrec _i 0 (concatD [prt 0 i , doc (showString ":") , prt 0 exp])
|
||||
PConsTop i pattern patterns -> prPrec _i 0 (concatD [prt 0 i , prt 1 pattern , prt 0 patterns])
|
||||
PCons i patterns -> prPrec _i 1 (concatD [doc (showString "(") , prt 0 i , prt 0 patterns , doc (showString ")")])
|
||||
PRec fieldpatterns -> prPrec _i 1 (concatD [doc (showString "{") , prt 0 fieldpatterns , doc (showString "}")])
|
||||
PRec fieldpatterns -> prPrec _i 1 (concatD [doc (showString "rec") , doc (showString "{") , prt 0 fieldpatterns , doc (showString "}")])
|
||||
PType -> prPrec _i 1 (concatD [doc (showString "Type")])
|
||||
PStr str -> prPrec _i 1 (concatD [prt 0 str])
|
||||
PInt n -> prPrec _i 1 (concatD [prt 0 n])
|
||||
@@ -118,9 +118,8 @@ instance Print (Tree c) where
|
||||
ENeg exp -> prPrec _i 8 (concatD [doc (showString "-") , prt 8 exp])
|
||||
EApp exp0 exp1 -> prPrec _i 9 (concatD [prt 9 exp0 , prt 10 exp1])
|
||||
EProj exp i -> prPrec _i 10 (concatD [prt 10 exp , doc (showString ".") , prt 0 i])
|
||||
EEmptyRec -> prPrec _i 11 (concatD [doc (showString "{") , doc (showString "}")])
|
||||
ERecType fieldtypes -> prPrec _i 11 (concatD [doc (showString "{") , prt 0 fieldtypes , doc (showString "}")])
|
||||
ERec fieldvalues -> prPrec _i 11 (concatD [doc (showString "{") , prt 0 fieldvalues , doc (showString "}")])
|
||||
ERecType fieldtypes -> prPrec _i 11 (concatD [doc (showString "sig") , doc (showString "{") , prt 0 fieldtypes , doc (showString "}")])
|
||||
ERec fieldvalues -> prPrec _i 11 (concatD [doc (showString "rec") , doc (showString "{") , prt 0 fieldvalues , doc (showString "}")])
|
||||
EVar i -> prPrec _i 11 (concatD [prt 0 i])
|
||||
EType -> prPrec _i 11 (concatD [doc (showString "Type")])
|
||||
EStr str -> prPrec _i 11 (concatD [prt 0 str])
|
||||
@@ -170,9 +169,11 @@ instance Print [Case] where
|
||||
x:xs -> (concatD [prt 0 x , doc (showString ";") , prt 0 xs])
|
||||
instance Print [FieldType] where
|
||||
prt _ es = case es of
|
||||
[] -> (concatD [])
|
||||
[x] -> (concatD [prt 0 x])
|
||||
x:xs -> (concatD [prt 0 x , doc (showString ";") , prt 0 xs])
|
||||
instance Print [FieldValue] where
|
||||
prt _ es = case es of
|
||||
[] -> (concatD [])
|
||||
[x] -> (concatD [prt 0 x])
|
||||
x:xs -> (concatD [prt 0 x , doc (showString ";") , prt 0 xs])
|
||||
|
||||
@@ -49,7 +49,6 @@ transTree t = case t of
|
||||
ENeg exp -> failure t
|
||||
EApp exp0 exp1 -> failure t
|
||||
EProj exp i -> failure t
|
||||
EEmptyRec -> failure t
|
||||
ERecType fieldtypes -> failure t
|
||||
ERec fieldvalues -> failure t
|
||||
EVar i -> failure t
|
||||
@@ -123,7 +122,6 @@ transExp t = case t of
|
||||
ENeg exp -> failure t
|
||||
EApp exp0 exp1 -> failure t
|
||||
EProj exp i -> failure t
|
||||
EEmptyRec -> failure t
|
||||
ERecType fieldtypes -> failure t
|
||||
ERec fieldvalues -> failure t
|
||||
EVar i -> failure t
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
entrypoints Module, Exp ;
|
||||
|
||||
layout "let", "where", "of" ;
|
||||
layout "let", "where", "of","rec", "sig" ;
|
||||
layout stop "in" ;
|
||||
layout toplevel ;
|
||||
|
||||
@@ -28,7 +28,7 @@ _. Pattern ::= Pattern1 ;
|
||||
-- Constructor pattern with parantheses
|
||||
PCons. Pattern1 ::= "(" Ident [Pattern] ")" ;
|
||||
-- Record patterns
|
||||
PRec. Pattern1 ::= "{" [FieldPattern] "}";
|
||||
PRec. Pattern1 ::= "rec" "{" [FieldPattern] "}";
|
||||
-- The pattern matching the Type constant
|
||||
PType. Pattern1 ::= "Type" ;
|
||||
-- String literal patterns
|
||||
@@ -85,15 +85,13 @@ EApp. Exp9 ::= Exp9 Exp10 ;
|
||||
|
||||
EProj. Exp10 ::= Exp10 "." Ident ;
|
||||
|
||||
EEmptyRec. Exp11 ::= "{" "}" ;
|
||||
|
||||
ERecType. Exp11 ::= "{" [FieldType] "}" ;
|
||||
ERecType. Exp11 ::= "sig" "{" [FieldType] "}" ;
|
||||
FieldType. FieldType ::= Ident ":" Exp ;
|
||||
separator nonempty FieldType ";" ;
|
||||
separator FieldType ";" ;
|
||||
|
||||
ERec. Exp11 ::= "{" [FieldValue] "}" ;
|
||||
ERec. Exp11 ::= "rec" "{" [FieldValue] "}" ;
|
||||
FieldValue.FieldValue ::= Ident "=" Exp ;
|
||||
separator nonempty FieldValue ";" ;
|
||||
separator FieldValue ";" ;
|
||||
|
||||
EVar. Exp11 ::= Ident ;
|
||||
EType. Exp11 ::= "Type" ;
|
||||
|
||||
Reference in New Issue
Block a user