markdown-pap (empty) → 0.0.1.0
raw patch · 6 files changed
+230/−0 lines, 6 filesdep +basedep +monads-tfdep +papillonsetup-changed
Dependencies added: base, monads-tf, papillon
Files
- LICENSE +27/−0
- Setup.hs +4/−0
- markdown-pap.cabal +38/−0
- src/Text/Markdown/Pap.hs +10/−0
- src/Text/Markdown/Pap/Parser.hs +136/−0
- src/Text/Markdown/Pap/Text.hs +15/−0
+ LICENSE view
@@ -0,0 +1,27 @@+Copyright (c) 2011, Yoshikuni Jujo+All rights reserved.++Redistribution and use in source and binary forms, with or without+modification, are permitted provided that the following conditions are met:++ * Redistributions of source code must retain the above copyright notice,+ this list of conditions and the following disclaimer.++ * Redistributions in binary form must reproduce the above copyright+ notice, this list of conditions and the following disclaimer in the+ documentation and/or other materials provided with the distribution.++ * Neither the name of the Yoshikuni Jujo nor the names of its+ contributors may be used to endorse or promote products derived from+ this software without specific prior written permission.++THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,+THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE+ARE DISCLAIMED. IN NO EVEN SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE+FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL+DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR+SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER+CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,+OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ Setup.hs view
@@ -0,0 +1,4 @@+import Distribution.Simple++main :: IO ()+main = defaultMain
+ markdown-pap.cabal view
@@ -0,0 +1,38 @@+build-type: Simple+cabal-version: >= 1.8++name: markdown-pap+version: 0.0.1.0+stability: Experimental+author: Yoshikuni Jujo <PAF01143@nifty.ne.jp>+maintainer: Yoshikuni Jujo <PAF01143@nifty.ne.jp>++license: BSD3+license-file: LICENSE++category: Text+synopsis: markdown parser with papillon+description:+ Now. Implemented only following features.+ .+ Paragraph, header, code, list+ .+ Not yet implemented following features.+ .+ newline, bold, quote, link, horizontal line++source-repository head+ type: git+ location: git://github.com/YoshikuniJujo/markdown-pap.git++source-repository this+ type: git+ location: git://github.com/YoshikuniJujo/markdown-pap.git+ tag: 0.0.1.0++library+ hs-source-dirs: src+ exposed-modules: Text.Markdown.Pap+ other-modules: Text.Markdown.Pap.Parser, Text.Markdown.Pap.Text+ build-depends: base > 3 && < 5, papillon, monads-tf+ ghc-options: -Wall
+ src/Text/Markdown/Pap.hs view
@@ -0,0 +1,10 @@+module Text.Markdown.Pap (+ parse,+ Text(..), List, List1(..)+) where++import qualified Text.Markdown.Pap.Parser as P+import Text.Markdown.Pap.Text++parse :: String -> Maybe [Text]+parse = P.parseMrd
+ src/Text/Markdown/Pap/Parser.hs view
@@ -0,0 +1,136 @@+{-# LANGUAGE QuasiQuotes, TypeFamilies, PackageImports #-}++module Text.Markdown.Pap.Parser (+ parseMrd+) where++import Control.Arrow+import "monads-tf" Control.Monad.State+import "monads-tf" Control.Monad.Error+import Data.Maybe+import Data.Char+import Text.Papillon++import Text.Markdown.Pap.Text++parseMrd :: String -> Maybe [Text]+parseMrd src = case flip runState (0, [- 1]) $ runErrorT $ markdown $ parse src of+ (Right (r, _), _) -> Just r+ _ -> Nothing++clear :: State (Int, [Int]) Bool+clear = put (0, [- 1]) >> return True++reset :: State (Int, [Int]) Bool+reset = modify (first $ const 0) >> return True++count :: State (Int, [Int]) ()+count = modify $ first (+ 1)++deeper :: State (Int, [Int]) Bool+deeper = do+ (n, n0 : ns) <- get+ if n > n0 then put (n, n : n0 : ns) >> return True else return False++same :: State (Int, [Int]) Bool+same = do+ (n, n0 : _) <- get+ return $ n == n0++shallow :: State (Int, [Int]) Bool+shallow = do+ (n, n0 : ns) <- get+ if n < n0 then put (n, ns) >> return True else return False++[papillon|++monad: State (Int, [Int])++markdown :: [Text]+ = md:(m:markdown1 _:dmmy[clear] { return m })* { return md }++markdown1 :: Text+ = h:header { return h }+ / l:list { return $ List l }+ / c:code { return $ Code c }+ / p:paras { return $ Paras p }++header :: Text+ = n:sharps _:<isSpace>* l:line '\n'+ { return $ Header n l }+ / l:line '\n' _:equals '\n'+ { return $ Header 1 l }+ / l:line '\n' _:hyphens '\n'+ { return $ Header 2 l }++sharps :: Int+ = '#' n:sharps { return $ n + 1 }+ / '#' { return 1 }++equals :: ()+ = '=' _:equals+ / '='++hyphens :: ()+ = '-' _:hyphens+ / '-'++line :: String+ = l:<(`notElem` "#\n")>+ { return l }++code :: String+ = l:fourSpacesLine c:code { return $ l ++ c }+ / l:fourSpacesLine { return l }++fourSpacesLine :: String+ = _:fourSpaces l:line '\n'+ { return $ l ++ "\n" }++fourSpaces :: ()+ = ' ' ' ' ' ' ' '++list :: List = _:cnt _:dmmy[deeper] l:list1 ls:list1'* _:shllw { return $ l : ls }+-- = _:cnt _:dmmy[deeper] l:list1 -- ls:list1'* _:shllw+-- { return $ l : ls }+{-+ = ls:(_:listHead ' ' l:line '\n' s:subList { return $ BulItem l s })++ { return ls }+ / ls:(_:nListHead ' ' l:line '\n' s:subList { return $ OrdItem l s })++ { return ls }+ -}++cnt :: () = _:dmmy[reset] _:(' ' { count })*++list1' :: List1+ = _:cnt _:dmmy[same] l:list1 { return l }++list1 :: List1+ = _:listHead ' ' l:line '\n' ls:list?+ { return $ BulItem l $ fromMaybe [] ls }+ / _:nListHead ' ' l:line '\n' ls:list?+ { return $ OrdItem l $ fromMaybe [] ls }++subList :: List+ = ls:subList1* { return ls }++subList1 :: List1+ = _:fourSpaces _:listHead ' ' l:line '\n' { return $ BulItem l [] }+ / _:fourSpaces _:nListHead ' ' l:line '\n' { return $ OrdItem l [] }++listHead :: ()+ = '*' / '-' / '+'++nListHead :: ()+ = _:<isDigit>+ '.'++paras :: [String]+ = ps:para+ { return ps }++para :: String+ = ls:(!_:header !_:fourSpaces l:line '\n' { return l })+ _:('\n' / !_ / !_:para) !_:list+ { return $ concat ls }++shllw :: ()+ = _:dmmy[shallow]+ / !_+ / !_:list++dmmy :: () =++|]
+ src/Text/Markdown/Pap/Text.hs view
@@ -0,0 +1,15 @@+module Text.Markdown.Pap.Text (Text(..), List, List1(..)) where++import Control.Applicative ((<$>))+import Data.Maybe+import Data.List++data Text+ = Header Int String+ | Paras [String]+ | Code String+ | List List+ deriving Show++type List = [List1]+data List1 = OrdItem String List | BulItem String List deriving Show