From f1a88975d2d14df302eb141a11400886e199afe1 Mon Sep 17 00:00:00 2001 From: Evan Czaplicki Date: Thu, 29 Aug 2013 00:55:32 -0700 Subject: [PATCH] Add iParse that takes a table --- compiler/Parse/Helpers.hs | 9 ++++++--- compiler/Parse/Module.hs | 2 +- compiler/Parse/Parse.hs | 2 +- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/compiler/Parse/Helpers.hs b/compiler/Parse/Helpers.hs index 978a490..4b02191 100644 --- a/compiler/Parse/Helpers.hs +++ b/compiler/Parse/Helpers.hs @@ -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 diff --git a/compiler/Parse/Module.hs b/compiler/Parse/Module.hs index 0c559ef..3d342d4 100644 --- a/compiler/Parse/Module.hs +++ b/compiler/Parse/Module.hs @@ -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 diff --git a/compiler/Parse/Parse.hs b/compiler/Parse/Parse.hs index e7afe05..2bcf033 100644 --- a/compiler/Parse/Parse.hs +++ b/compiler/Parse/Parse.hs @@ -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 ]