her-lexer-parsec (empty) → 0.0.0
raw patch · 4 files changed
+269/−0 lines, 4 filesdep +basedep +her-lexerdep +parsecsetup-changed
Dependencies added: base, her-lexer, parsec, transformers
Files
- LICENCE +6/−0
- Language/Haskell/Her/Parsec.lhs +239/−0
- Setup.hs +2/−0
- her-lexer-parsec.cabal +22/−0
+ LICENCE view
@@ -0,0 +1,6 @@+SHE is written by Conor McBride.+Her lexer parsec was put together by Timothy Hobbs.++Permission is hereby granted, free of charge, to any person obtaining this work (the "Work"), to deal in the Work without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Work, and to permit persons to whom the Work is furnished to do so.++THE WORK IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE WORK OR THE USE OR OTHER DEALINGS IN THE WORK.
+ Language/Haskell/Her/Parsec.lhs view
@@ -0,0 +1,239 @@+>module Language.Haskell.Her.Parsec+> (haskellTokenStream+> ,litC+> ,opeC+> ,cloC+> ,uidC+> ,lidC+> ,kwC+> ,symC+> ,spcC+> ,comC+> ,urkC+> ,nlC+> ,lit+> ,ope+> ,clo+> ,uid+> ,lid+> ,kw+> ,sym+> ,semi+> ,spc+> ,com+> ,urk+> ,nl) where++>import Language.Haskell.Her.HaLay hiding+> (ope+> ,clo+> ,uid+> ,lid+> ,sym+> ,spc)+>import Text.ParserCombinators.Parsec+>import Text.Parsec.Prim+>import Data.Functor.Identity+>import Text.Parsec.Pos++>markLines+> :: String+> -> [(Int,Tok)]+> -> [(SourcePos,Tok)]+>markLines+> fileName+> toks+> = map+> (\((col,tok),line) ->+> (newPos fileName line col,tok))+> $ snd+> $ foldr+> markLines'+> (0,[])+> toks+> where+> markLines'+> tok+> (oldLine,markedToks)+> = case tok of+> (_,NL (_,newLine)) -> (newLine, (tok,newLine):markedToks)+> _ -> (oldLine,(tok,oldLine):markedToks)++>haskellTokenStream+> :: String+> -> String+> -> [(SourcePos,Tok)]+>haskellTokenStream+> haskellCode+> fileName+> = markLines+> fileName+> $ tokenize+> (((fileName,0),0),haskellCode)++>posTok (pos,_) = pos+>showT (_,t) = tokOut t+>justIf True v = Just v+>justIf False _ = Nothing++herToken+ :: Text.Parsec.Prim.Stream+ s+ Data.Functor.Identity.Identity+ (SourcePos, Tok)+ => ((SourcePos, Tok) -> Maybe a)+ -> Text.Parsec.Prim.Parsec s u a++>herToken matchT = token showT posTok matchT++----++>litC+> checker+> = herToken matchT+> where+> matchT (_,t@(Lit c)) = justIf (checker c) t+> matchT (_,_) = Nothing++>lit+> content+> = litC (\c -> c == content)++----++>opeC+> checker+> = herToken matchT+> where+> matchT (_,t@(Ope c)) = justIf (checker c) t+> matchT (_,_) = Nothing++>ope+> content+> = opeC (\c -> c == content)++----++>cloC+> checker+> = herToken matchT+> where+> matchT (_,t@(Clo c)) = justIf (checker c) t+> matchT (_,_) = Nothing++>clo+> content+> = cloC (\c -> c == content)++----++>uidC+> checker+> = herToken matchT+> where+> matchT (_,t@(Uid c)) = justIf (checker c) t+> matchT (_,_) = Nothing++>uid+> content+> = uidC (\c -> c == content)++----++>lidC+> checker+> = herToken matchT+> where+> matchT (_,t@(Lid c)) = justIf (checker c) t+> matchT (_,_) = Nothing++>lid+> content+> = lidC (\c -> c == content)++----++>kwC+> checker+> = herToken matchT+> where+> matchT (_,t@(KW c)) = justIf (checker c) t+> matchT (_,_) = Nothing++>kw+> content+> = kwC (\c -> c == content)++----++>symC+> checker+> = herToken matchT+> where+> matchT (_,t@(Sym c)) = justIf (checker c) t+> matchT (_,_) = Nothing++>sym+> content+> = symC (\c -> c == content)++----++>semi :: GenParser (SourcePos,Tok) st Tok+>semi+> = herToken matchT+> where+> matchT (_,t@Semi) = Just t+> matchT (_,_) = Nothing++----++>spcC+> checker+> = herToken matchT+> where+> matchT (_,t@(Spc c)) = justIf (checker c) t+> matchT (_,_) = Nothing++>spc+> content+> = spcC (\c -> c == content)++----++>comC+> checker+> = herToken matchT+> where+> matchT (_,t@(Com c)) = justIf (checker c) t+> matchT (_,_) = Nothing++>com+> content+> = comC (\c -> c == content)++----++>urkC+> checker+> = herToken matchT+> where+> matchT (_,t@(Urk c)) = justIf (checker c) t+> matchT (_,_) = Nothing++>urk+> content+> = urkC (\c -> c == content)++----++>nlC+> checker+> = herToken matchT+> where+> matchT (_,t@(NL c)) = justIf (checker c) t+> matchT (_,_) = Nothing++>nl+> content+> = nlC (\c -> c == content)
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ her-lexer-parsec.cabal view
@@ -0,0 +1,22 @@+name: her-lexer-parsec+version: 0.0.0+synopsis: Parsec frontend to "her-lexer" for Haskell source code.+description: Parsec frontend to "her-lexer" for Haskell source code.+category: Language+license: PublicDomain+license-file: LICENCE+author: Timothy Hobbs+maintainer: Timothy Hobbs<timothyhobbs@seznam.cz>+cabal-version: >= 1.6+build-type: Simple++library+ exposed-modules: Language.Haskell.Her.Parsec+ build-depends: base >=3 && < 5,+ parsec >= 3,+ transformers >= 0.3.0.0,+ her-lexer >= 0++source-repository head+ type: git+ location: https://github.com/timthelion/her-lexer-parsec.git