on master help sign in
Add iParse that takes a table
f1a8897Evan Czaplicki
compiler/Parse/Helpers.hs+6−3
@@ -41,9 +41,12 @@ type OpTable = Map.Map String (Int, Assoc)
41
41
42type IParser a = ParsecT String OpTable (State SourcePos) a
42type IParser a = ParsecT String OpTable (State SourcePos) a
43
43
44+iParse :: IParser a -> String -> Either ParseError a
45+iParse = iParseWithTable "" Map.empty
46+
44−iParse :: IParser a -> SourceName -> String -> Either ParseError a
47+iParseWithTable :: SourceName -> OpTable -> IParser a -> String -> Either ParseError a
45−iParse aParser source_name input =
48+iParseWithTable sourceName table aParser input =
46− runIndent source_name $ runParserT aParser () source_name input
49+ runIndent sourceName $ runParserT aParser table sourceName input
47
50
48backslashed :: IParser Char
51backslashed :: IParser Char
49backslashed = do { char '\\'; c <- anyChar
52backslashed = do { char '\\'; c <- anyChar
compiler/Parse/Module.hs+1−1
@@ -13,7 +13,7 @@ varList = parens $ commaSep1 (var <|> parens symOp)
13
13
14getModuleName :: String -> Maybe String
14getModuleName :: String -> Maybe String
15getModuleName source =
15getModuleName source =
16− case iParse getModuleName "" source of
16+ case iParse getModuleName source of
17 Right name -> Just name
17 Right name -> Just name
18 Left _ -> Nothing
18 Left _ -> Nothing
19 where
19 where
compiler/Parse/Parse.hs+1−1
@@ -42,6 +42,6 @@ dependencies =
42
42
43setupParser :: IParser a -> String -> Either [P.Doc] a
43setupParser :: IParser a -> String -> Either [P.Doc] a
44setupParser p source =
44setupParser p source =
45− case iParse p "" source of
45+ case iParse p source of
46 Right result -> Right result
46 Right result -> Right result
47 Left err -> Left [ P.text $ "Parse error at " ++ show err ]
47 Left err -> Left [ P.text $ "Parse error at " ++ show err ]