Skip to content
Snippets Groups Projects
Commit f4cee313 authored by Nathan Daelman's avatar Nathan Daelman
Browse files

Add `stripWrapper`

parent a78aa265
No related branches found
No related tags found
No related merge requests found
......@@ -4,6 +4,7 @@ import Text.Parsec.String
import ToDB
import Database.Bolt (BoltActionT, Record)
import Control.Monad (liftM2)
import Data.Functor (($>))
data MForm = MForm {fName :: String, fParams :: [String]} deriving (Show)
......@@ -17,18 +18,26 @@ data Extracted = MCDef String
extendedLetter :: Parser Char
extendedLetter = try alphaNum <|> char '_'
stripWrapper :: Char -> Char -> Parser String
stripWrapper s e =
optional (char s) *>
many (noneOf [s, e]) >>= \cnt ->
optional (char e) $>
cnt
-- MapleC parsers
mcDefineParser :: Parser Extracted
mcDefineParser = MCDef <$> (string "$define" *> spaces *> many1 extendedLetter)
mcIncludeParser :: Parser Extracted
mcIncludeParser = MCInclude <$> (string "$include" *> spaces *> string "\"" *> many1 (extendedLetter <|> char '.') <* string "\"")
mcIncludeParser = MCInclude <$> (string "$include" *> spaces *> stripWrapper '"' '"')
mcConditionalParser :: Parser Extracted
mcConditionalParser = MCConditional <$>
(string "$ifdef" *> spaces *> many1 extendedLetter <* newline) <*>
manyTill ((\x -> (varName x, varValue x)) <$> mVarParser) (string "$endif") -- use mVarParser to parse the conditional body
manyTill ((\x -> (varName x, varValue x)) <$> mVarParser) (string "$endif")
-- use mVarParser to parse the conditional body
-- Maple parsers
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment