Add iParse that takes a table

This commit is contained in:
Evan Czaplicki 2013-08-29 00:55:32 -07:00
parent 6d27c5eee7
commit f1a88975d2
3 changed files with 8 additions and 5 deletions

View file

@ -41,9 +41,12 @@ type OpTable = Map.Map String (Int, Assoc)
type IParser a = ParsecT String OpTable (State SourcePos) a
iParse :: IParser a -> SourceName -> String -> Either ParseError a
iParse aParser source_name input =
runIndent source_name $ runParserT aParser () source_name input
iParse :: IParser a -> String -> Either ParseError a
iParse = iParseWithTable "" Map.empty
iParseWithTable :: SourceName -> OpTable -> IParser a -> String -> Either ParseError a
iParseWithTable sourceName table aParser input =
runIndent sourceName $ runParserT aParser table sourceName input
backslashed :: IParser Char
backslashed = do { char '\\'; c <- anyChar

View file

@ -13,7 +13,7 @@ varList = parens $ commaSep1 (var <|> parens symOp)
getModuleName :: String -> Maybe String
getModuleName source =
case iParse getModuleName "" source of
case iParse getModuleName source of
Right name -> Just name
Left _ -> Nothing
where

View file

@ -42,6 +42,6 @@ dependencies =
setupParser :: IParser a -> String -> Either [P.Doc] a
setupParser p source =
case iParse p "" source of
case iParse p source of
Right result -> Right result
Left err -> Left [ P.text $ "Parse error at " ++ show err ]