diff options
Diffstat (limited to 'parser')
-rw-r--r-- | parser/CC/Parser.hs | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/parser/CC/Parser.hs b/parser/CC/Parser.hs index 0088956..d6c2239 100644 --- a/parser/CC/Parser.hs +++ b/parser/CC/Parser.hs @@ -1,20 +1,22 @@ module CC.Parser(runPass, parseProgram) where import Control.Monad -import Text.Parsec hiding (State, SourcePos, getPosition, token) +import Text.Parsec hiding (SourcePos, getPosition, token) import qualified Text.Parsec +import CC.Pretty import CC.Source -type Parser a = Parsec String State a -type State = Int -- base indentation level; hanging lines should be > this +type Parser a = Parsec String () a -runPass :: Context -> RawString -> Either ParseError Program -runPass (Context path) (RawString src) = parseProgram path src +runPass :: Context -> RawString -> Either (PrettyShow ParseError) Program +runPass (Context path) (RawString src) = fmapLeft PrettyShow (parseProgram path src) + where fmapLeft f (Left x) = Left (f x) + fmapLeft _ (Right x) = Right x parseProgram :: FilePath -> String -> Either ParseError Program -parseProgram fname src = runParser pProgram 0 fname src +parseProgram fname src = parse pProgram fname src pProgram :: Parser Program pProgram = do @@ -30,7 +32,6 @@ pDef :: Parser Def pDef = do func <- try $ do emptyLines - putState 0 name <- pName0 <?> "declaration head name" return name mtyp <- optionMaybe $ do |