indentation 0.2.0.0 → 0.2.0.2
raw patch · 7 files changed
+158/−15 lines, 7 filesdep ~mtldep ~parsecdep ~parsersnew-uploader
Dependency ranges changed: mtl, parsec, parsers, trifecta
Files
- CHANGELOG.md +5/−0
- Text/Parsec/Indentation.hs +3/−1
- Text/Parsec/Indentation/Char.hs +5/−1
- Text/Parsec/Indentation/Examples/ISWIM.hs +61/−0
- Text/Parsec/Indentation/Examples/Parens.hs +58/−0
- Text/Trifecta/Indentation.hs +6/−6
- indentation.cabal +20/−7
+ CHANGELOG.md view
@@ -0,0 +1,5 @@+# 0.2.0.2 #++* Allow building with `parsec >= 3.1.7` and `trifecta >= 1.5`++
Text/Parsec/Indentation.hs view
@@ -17,7 +17,9 @@ import Control.Monad --import Text.Parsec.Prim-import Text.Parsec+import Text.Parsec.Prim (ParsecT, mkPT, runParsecT,+ Stream(..), Consumed(..), Reply(..),+ State(..), getInput, setInput) import Text.Parsec.Error (Message (Message), addErrorMessage) import Text.Parser.Indentation.Implementation as I
Text/Parsec/Indentation/Char.hs view
@@ -1,7 +1,11 @@ {-# LANGUAGE FlexibleInstances, MultiParamTypeClasses, FlexibleContexts #-} module Text.Parsec.Indentation.Char where -import Text.Parsec+import Text.Parsec.Prim (ParsecT, mkPT, runParsecT,+ Stream(..),+ Consumed(..), Reply(..),+ State(..))+import Text.Parsec.Pos (sourceColumn) import Text.Parser.Indentation.Implementation (Indentation) ----------------
+ Text/Parsec/Indentation/Examples/ISWIM.hs view
@@ -0,0 +1,61 @@+module Text.Parsec.Indentation.Examples.ISWIM where++-- Encodes example TODO from the paper TODO.+-- Note that because Parsec doesn't support full backtracking+-- this+--++import Control.Applicative ((<$>))+import Text.Parsec+import Text.Parsec.Indentation+import Text.Parsec.Indentation.Char++data ID = ID String deriving (Show, Eq)+data Expr+ = Where Expr ID Expr -- expr -> expr 'where' ID '=' |expr|>=+ | Plus Expr Expr -- expr -> expr '+' expr+ | Minus Expr -- expr -> '-' expr+ | Parens Expr -- expr -> '(' expr* ')'+ | Var ID -- expr -> ID+ deriving (Show, Eq)++runParse :: String -> Either ParseError Expr+runParse input+ = case runParser expr () "" (mkIndentStream 0 infIndentation True Ge (mkCharIndentStream input)) of+ Left err -> Left err+ Right a -> Right a++-- Note that this grammar DOES NOT WORK as written because it contains+-- a left recursion. (It diverges.) However, it provides a good+-- first example to see how to use the combinators in+-- Text.Parsec.Indentation.++tok s = string s >> localTokenMode (const Any) (ignoreAbsoluteIndentation (many (char ' ' <|> char '\n')))+ident = choice (map f ["v", "w", "x", "y", "z"])+ where f x = tok x >> return (ID x)++expr = choice $ map try+ [ do e1 <- expr_nonrec+ tok "where"+ i <- ident+ tok "="+ e2 <- localIndentation Ge (absoluteIndentation expr)+ return (Where e1 i e2)+ , do e1 <- expr_nonrec+ tok "+"+ e2 <- expr+ return (Plus e1 e2)+ , expr_nonrec+ ]++expr_nonrec = choice+ [ tok "-" >> (Minus <$> expr)+ , Parens <$> between (tok "(") (tok ")") (localIndentation Any expr)+ , Var <$> ident+ ]+++input1 = "x + v where\n\+ \ x = -(\n\+ \y + z) + w"+output1 = runParse input1
+ Text/Parsec/Indentation/Examples/Parens.hs view
@@ -0,0 +1,58 @@+{-# LANGUAGE NoMonomorphismRestriction, FlexibleContexts #-}+module Text.Parsec.Indentation.Examples.Parens where++-- Encodes example TODO from the paper TODO.+-- Note that because Parsec doesn't support full backtracking+-- this++import Control.Applicative+import Text.Parsec+import Text.Parsec.Indentation++data A+ = Par A -- '(' A ')'+ | Bra A -- '[' A ']'+ | Seq A A -- A A+ | Nil -- epsilon+ deriving (Show, Eq)++a :: (Monad m, Stream s m (Char, Indentation)) => ParsecT (IndentStream s) () m A+a = choice [ Seq <$> a' <*> a, a', return Nil ]++a' :: (Monad m, Stream s m (Char, Indentation)) => ParsecT (IndentStream s) () m A+a' = choice+ [ Par <$>+ between (localTokenMode (const Eq) $ char '(')+ (localTokenMode (const Eq) $ char ')')+ (localIndentation Gt a)+ , Bra <$>+ between (localTokenMode (const Ge) $ char '[')+ (localTokenMode (const Ge) $ char ']')+ (localIndentation Gt a)+ ]+++runParse input+ = case runParser a () "" (mkIndentStream 0 infIndentation True Gt input) of+ Left err -> Left (show err)+ Right a -> Right a++input1 = [('(', 1),+ ('[', 4),+ ('(', 5),+ (')', 5),+ (']', 7),+ (')', 1)]+output1 = runParse input1++input2 = [('(', 1),+ ('[', 8),+ ('(', 6),+ (')', 6),+ ('[', 8),+ (']', 9),+ (']', 4),+ ('(', 3),+ (')', 3),+ (')', 1)]+output2 = runParse input2
Text/Trifecta/Indentation.hs view
@@ -14,12 +14,12 @@ import Control.Monad.State.Lazy as LazyState import Control.Monad.State.Strict as StrictState -import Text.Parser.Combinators-import Text.Parser.Token-import Text.Parser.Char-import Text.Parser.LookAhead-import Text.Trifecta.Combinators-import Text.Trifecta.Delta+import Text.Parser.Combinators (Parsing(..))+import Text.Parser.Token (TokenParsing(..))+import Text.Parser.Char (CharParsing(..))+import Text.Parser.LookAhead (LookAheadParsing(..))+import Text.Trifecta.Combinators (DeltaParsing(..), MarkParsing(..))+import Text.Trifecta.Delta (Delta, column) import Text.Parser.Indentation.Implementation (IndentationState(..), IndentationRel(..), LocalState) import qualified Text.Parser.Indentation.Implementation as I
indentation.cabal view
@@ -1,14 +1,27 @@ name: indentation-version: 0.2.0.0-synopsis: Indentation sensitive parsing combinators for Parsec--- description:+version: 0.2.0.2+synopsis: Indentation sensitive parsing combinators for Parsec and Trifecta+description: Indentation sensitive parsing combinators for Parsec and Trifecta.+ . + See+ .+ __Michael D. Adams and Ömer S. Ağacan__.+ Indentation-sensitive parsing for Parsec.+ In /Proceedings of the 2014 ACM SIGPLAN Symposium on Haskell/,+ Haskell ’14, pages 121–132.+ ACM, New York, NY, USA, September 2014. ISBN 978-1-4503-3041-1.+ <http://dx.doi.org/10.1145/2633357.2633369 doi:10.1145/2633357.2633369>.+ license: BSD3 license-file: LICENSE author: Michael D. Adams <http://michaeldadams.org/> maintainer: Ömer Sinan Ağacan <omeragacan@gmail.com>+ Aleksey Kliger <aleksey@lambdageek.org> category: Parsing build-type: Simple cabal-version: >=1.10+extra-source-files: CHANGELOG.md+ Text/Parsec/Indentation/Examples/*.hs homepage: https://bitbucket.org/mdmkolbe/indentation bug-reports: https://bitbucket.org/mdmkolbe/indentation/issues@@ -20,17 +33,17 @@ library exposed-modules: Text.Parser.Indentation.Implementation build-depends: base >=4.6 && <4.8,- mtl >=2.1 && <2.2+ mtl >=2.1 if flag(Parsec)- build-depends: parsec ==3.1.*+ build-depends: parsec >=3.1.5 exposed-modules: Text.Parsec.Indentation , Text.Parsec.Indentation.Char , Text.Parsec.Indentation.Token if flag(Trifecta)- build-depends: trifecta ==1.4.*,- parsers ==0.11.0.*+ build-depends: trifecta >=1.4 && <1.6,+ parsers >=0.10 && <0.13 exposed-modules: Text.Trifecta.Indentation default-language: Haskell2010