packages feed

maxsharing 1.0.3 → 1.1

raw patch · 4 files changed

+79/−67 lines, 4 filesdep +fgldep +indentparserdep −IndentParserdep ~HaLeXdep ~basedep ~base-unicode-symbols

Dependencies added: fgl, indentparser

Dependencies removed: IndentParser

Dependency ranges changed: HaLeX, base, base-unicode-symbols, boxes, containers, containers-unicode-symbols, mtl, parsec, process, uuagc, uuagc-cabal

Files

MaxSharing.hs view
@@ -7,7 +7,7 @@ 	synthesise, scoped_Syn_R, dfa_Syn_R, readback_Syn_R, proof_Syn_R, unscoped_Syn_R) import System.Environment import Language.HaLex.Minimize-import System.Cmd+import System.Process import Language.HaLex.FaAsDiGraph (tographviz) import Language.HaLex.Dfa (Dfa, beautifyDfa) import Language.HaLex.FaOperations (dfa2ndfa)
Parser.hs view
@@ -3,70 +3,86 @@  import Lambda import Prelude.Unicode-import Text.ParserCombinators.Parsec as Parsec-import Text.ParserCombinators.Parsec.IndentParser as Indent-import Text.ParserCombinators.Parsec.Language-import Text.ParserCombinators.Parsec.IndentParser.Token-import Control.Monad (liftM)+import Control.Monad.Identity+import Text.ParserCombinators.Parsec+import Text.Parsec.Prim as P+import Text.Parsec.Language as L+import Text.Parsec.Token as T+import qualified Text.Parsec.IndentParsec as I  +langDef ∷ Monad m ⇒ GenLanguageDef String u m+langDef = T.LanguageDef+       {commentStart   = "{-",+        commentEnd     = "-}",+        commentLine    = "--",+        nestedComments = True,+        identStart     = identLetter langDef,+        identLetter    = alphaNum <|> oneOf "_':!#$%&*+/<?@^|-~",+        opStart        = oneOf "",+        opLetter       = oneOf "",+        reservedOpNames= [],+        reservedNames  = ["let","in","λ"],+        caseSensitive  = True}++lexer ∷ Monad m ⇒ I.IndentTokenParser String u m+lexer = T.makeTokenParser langDef++type IndentParser a = I.IndentParsecT String () Identity a+ parse ∷ String → Λ-parse str = either (error ∘ show) id (Indent.parse parser "(null)" str)+parse input = either (error ∘ show) id $ runIdentity $ I.runGIPT parser () "" "input"  parseFile ∷ FilePath → IO Λ-parseFile = liftM (either (error ∘ show) id) ∘ Indent.parseFromFile parser+parseFile path = do+	input ← readFile path+	return $ either (error ∘ show) id $ runIdentity $ I.runGIPT parser () path input -parser ∷ IndentCharParser st Λ-parser = expression where+parser ∷ IndentParser Λ+parser = expression <* eof where -	expression = flip label "expression" $ application <|> letBinding+	expression = application <|> letBinding <?> "expression" -	application = liftM (foldl1 A) $ many1 $ choice [parenthetic, abstraction, variable]+	application = foldl1 A <$> many1 (parenthetic <|> abstraction <|> variable) -	parenthetic = parens haskell expression+	parenthetic = I.parens lexer expression  	abstraction = flip label "abstraction" $ do-		_ ← sym "λ" <|> sym "\\"-		vars ← many1 ident-		_ ← sym "." <|> sym "→" <|> sym "->"-		body ← expression+		vars ← (sym "λ" <|> sym "\\") *> many1 ident+		body ← (sym "." <|> sym "→" <|> sym "->") *> expression 		return $ foldr Λ body vars -	variable = liftM V $ ident <|> liftM (either show show) (naturalOrFloat haskell)+	variable = fmap V $ ident <|> show <$> I.natural lexer -	-- Ugly, but works. Keyword "in" terminates binding blocks and bindings. Allows empty lets 	letBinding = flip label "let binding" $ do-		keyword "let"-		let parseBindings = do-			e ← optionMaybe $ keyword "in" >> expression-			case e of-				Just je → return ([], Just je)-				Nothing → do-					(b,e) ← lineFold $ do-						b ← binding-						e ← optionMaybe $ keyword "in" >> expression-						return (b,e)-					case e of-						Nothing → do-							rec ← optionMaybe parseBindings-							case rec of-								Nothing → return ([b], Nothing)-								Just (bs, me) → return (b:bs, me)-						Just je → return ([b], Just je)-		(binds, e) ← block parseBindings+		(bs, maybe_e) ← sym "let" *> I.blockOf bindings+		e ← case maybe_e of+			Nothing → sym "in" *> expression+			Just e → return e+		return $ L bs e++	bindings = do+		(b,e) ← I.foldedLinesOf $ do+			b ← binding+			e ← optionMaybe $ sym "in" *> expression+			return (b,e) 		case e of-			Nothing → liftM (L binds) (keyword "in" >> expression)-			Just je → return $ L binds je+			Just _ → return ([b], e)+			Nothing → do+				m ← optionMaybe bindings+				case m of+					Nothing → return ([b], e)+					Just (bs, e) → return (b:bs, e) -	binding ∷ IndentCharParser st (String,Λ)+	binding ∷ IndentParser (String,Λ) 	binding = flip label "binding" $ do 		funct  ← ident 		params ← many ident-		body   ← sym "=" >> expression+		body   ← sym "=" *> expression 		return (funct, foldr Λ body params) -	keyword = reserved haskell-	ident = do-		i ← identifier haskell-		if head i ≡ 'λ' then fail "'λ' is reserved for abstractions" else return i-	sym = symbol haskell+	ident ∷ IndentParser String+	ident = I.identifier lexer++	sym ∷ String → IndentParser String+	sym = P.try . I.symbol lexer
− examples/sum.l
@@ -1,5 +0,0 @@-let-	sum list = case list of-		Nil -> 0-		Cons z zs -> (\x.λy -> + x y) z (sum zs)-in sum (Cons 1 (Cons 2 Nil))
maxsharing.cabal view
@@ -1,9 +1,9 @@ Name:           maxsharing-Version:        1.0.3+Version:        1.1 Copyright:      (c) 2013, Jan Rochel Author:         Jan Rochel Maintainer:     jan@rochel.info-Homepage:       http://rochel.info/maxsharing/+Homepage:       http://arxiv.org/abs/1401.1460 License:        BSD3 License-file:   LICENSE Stability:      beta@@ -15,8 +15,8 @@                 unfolding as the original term but is more (maximally) compact.                 If executable "dot" from graphviz is available, the graphs are                 displayed (tested for Linux). The approach is described in an-                ICFP-paper (http://dx.doi.org/10.1145/2628136.2628148) and an-                extended version thereof (http://arxiv.org/abs/1401.1460).+                ICFP-paper <http://dx.doi.org/10.1145/2628136.2628148> and an+                extended version thereof <http://arxiv.org/abs/1401.1460>. Category:       Graphs, Compiler Cabal-Version:  >= 1.6 Extra-Source-Files: uuagc_options@@ -24,18 +24,19 @@  Executable maxsharing   Build-Depends:-    base < 4.8,-    base-unicode-symbols < 0.3,-    parsec < 2.2,-    IndentParser < 0.3,-    containers < 0.6,-    containers-unicode-symbols < 0.4,-    mtl < 2.3,-    uuagc-cabal < 1.1,-    uuagc >= 0.9.50.2 && < 0.10,-    HaLeX >= 1.2.1 && < 1.3,-    boxes < 0.2,-    process < 1.5+    base < 4.9,+    base-unicode-symbols,+    parsec >= 3.0,+    indentparser,+    containers,+    containers-unicode-symbols,+    mtl,+    uuagc-cabal,+    uuagc,+    HaLeX,+    process,+    boxes,+    fgl   Extensions: UnicodeSyntax   Other-Modules:  Lambda Parser Spanning   Main-Is: MaxSharing.hs