1
0
forked from GitHub/gf-core

Transfer: Changed BNFC's layout syntax resolver to add a semicolon at EOF if using top-level layout sytax. Changed transfer syntax to use this to force semicolon after imports when pretty printing transfer. transfer grammar printer now produces Transfer syntax, not core. It also imports prelude and includes Eq and Compos instances.

This commit is contained in:
bringert
2005-12-06 15:57:43 +00:00
parent cd9150855d
commit ed23b9d8d8
7 changed files with 311 additions and 312 deletions

View File

@@ -93,7 +93,6 @@ All other symbols are terminals.\\
\begin{tabular}{lll}
{\nonterminal{ListImport}} & {\arrow} &{\emptyP} \\
& {\delimit} &{\nonterminal{Import}} \\
& {\delimit} &{\nonterminal{Import}} {\terminal{;}} {\nonterminal{ListImport}} \\
\end{tabular}\\
@@ -106,7 +105,6 @@ All other symbols are terminals.\\
\begin{tabular}{lll}
{\nonterminal{ListDecl}} & {\arrow} &{\emptyP} \\
& {\delimit} &{\nonterminal{Decl}} \\
& {\delimit} &{\nonterminal{Decl}} {\terminal{;}} {\nonterminal{ListDecl}} \\
\end{tabular}\\

View File

@@ -105,10 +105,17 @@ resolveLayout tp = res Nothing [if tl then Implicit 1 else Explicit]
-- Nothing to see here, move along.
res _ st (t:ts) = moveAlong st [t] ts
-- We are at EOF, close all open implicit non-top-level layout blocks.
res (Just t) st [] =
addTokens (position t) [layoutClose | Implicit n <- st,
not (tl && n == 1)] []
-- At EOF: skip explicit blocks.
res (Just t) (Explicit:bs) [] | null bs = []
| otherwise = res (Just t) bs []
-- If we are using top-level layout, insert a semicolon after the last token
res (Just t) [Implicit n] [] = addToken (nextPos t) layoutSep []
-- At EOF in an implicit, non-top-level block: close the block
res (Just t) (Implicit n:bs) [] =
let c = addToken (nextPos t) layoutClose []
in moveAlong bs c []
-- This should only happen if the input is empty.
res Nothing st [] = []

File diff suppressed because one or more lines are too long

View File

@@ -78,7 +78,7 @@ Integer :: { Integer } : L_integ { (read $1) :: Integer }
Double :: { Double } : L_doubl { (read $1) :: Double }
Module :: { Module }
Module : ListImport ListDecl { Module $1 $2 }
Module : ListImport ListDecl { Module (reverse $1) (reverse $2) }
Import :: { Import }
@@ -87,8 +87,7 @@ Import : 'import' Ident { Import $2 }
ListImport :: { [Import] }
ListImport : {- empty -} { [] }
| Import { (:[]) $1 }
| Import ';' ListImport { (:) $1 $3 }
| ListImport Import ';' { flip (:) $1 $2 }
Decl :: { Decl }
@@ -100,8 +99,7 @@ Decl : 'data' Ident ':' Exp 'where' '{' ListConsDecl '}' { DataDecl $2 $4 $7 }
ListDecl :: { [Decl] }
ListDecl : {- empty -} { [] }
| Decl { (:[]) $1 }
| Decl ';' ListDecl { (:) $1 $3 }
| ListDecl Decl ';' { flip (:) $1 $2 }
ConsDecl :: { ConsDecl }

View File

@@ -154,12 +154,10 @@ instance Print (Tree c) where
instance Print [Import] 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 [Decl] 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 [ConsDecl] where
prt _ es = case es of

View File

@@ -10,13 +10,16 @@ comment "{-" "-}" ;
Module. Module ::= [Import] [Decl] ;
Import. Import ::= "import" Ident ;
separator Import ";" ;
-- FIXME: this is terminator to ensure that the pretty printer
-- produces a semicolon after the last import. This could cause
-- problems in a program which only does imports and uses layout syntax.
terminator Import ";" ;
DataDecl. Decl ::= "data" Ident ":" Exp "where" "{" [ConsDecl] "}" ;
TypeDecl. Decl ::= Ident ":" Exp ;
ValueDecl. Decl ::= Ident [Pattern] Guard "=" Exp ;
DeriveDecl. Decl ::= "derive" Ident Ident ;
separator Decl ";" ;
terminator Decl ";" ;
ConsDecl. ConsDecl ::= Ident ":" Exp ;
separator ConsDecl ";" ;