lentil-0.1.2.0: src/Lentil/Parse/Syntaxes.hs
-----------------------------------------------------------------------------
-- |
-- Module : Lentil.Parse.Syntaxes
-- Copyright : © 2015 Francesco Ariis
-- License : GPLv3 (see the LICENSE file)
--
-- Languages descriptors
-----------------------------------------------------------------------------
module Lentil.Parse.Syntaxes where
import Lentil.Parse.Source
import Text.Parsec
import qualified System.FilePath as SF
-- TODO: add langparsers che sia estensibile e leggibile
-- a compilazione [u:2] [feature:intermediate]
langParser :: String -> Maybe (ParSource [CommentString])
langParser fp | ext `elem` [".hs", ".lhs"] = Just haskell
| ext `elem` [".c", ".h"] = Just c
| ext `elem` [".cpp", ".hpp"] = Just c -- C++
| ext `elem` [".java"] = Just c -- Java
| ext `elem` [".js"] = Just javascript
| ext `elem` [".py"] = Just python
| ext `elem` [".rb"] = Just ruby
| ext `elem` [".pas", ".pp", ".inc"] = Just pascal
| ext `elem` [".txt"] = Just text
| otherwise = Nothing
where ext = SF.takeExtension fp
-- todo multiline signature? [lint]
-- todo tag at the beginning too? [design]
haskell, c, javascript, pascal, python, ruby, text :: ParSource [CommentString]
haskell = source $ ParSyntax ["--"] [("{-", "-}")] ['"'] ['\'']
c = source $ ParSyntax ["//"] [("/*", "*/")] ['"'] ['\'']
javascript = source $ ParSyntax ["//"] [("/*", "*/")] ['"', '\''] []
pascal = source $ ParSyntax ["//"] [("{", "}" ),
("(*", "*)")] ['\''] []
python = source $ ParSyntax ["#"] [("\"\"\"",
"\"\"\"")] ['"', '\''] []
ruby = source $ ParSyntax ["#"] [("=begin",
"=end")] ['"', '\''] []
text = (:[]) . MultiLine 1 <$> many anyChar