aboutsummaryrefslogtreecommitdiff
path: root/parser/CC
diff options
context:
space:
mode:
authorTom Smeding <tom.smeding@gmail.com>2020-07-23 20:15:15 +0200
committerTom Smeding <tom.smeding@gmail.com>2020-07-23 20:15:15 +0200
commit39ea4ac3a4b7663882a83f2ada43c8238f087d9b (patch)
tree70b28d7f0bd301f8eb912837b126956ecdaa1ca3 /parser/CC
parentbc52411ae2ed26cab1d5086ae6df68f23ebbd052 (diff)
Use Pretty for errors and expressions
Diffstat (limited to 'parser/CC')
-rw-r--r--parser/CC/Parser.hs15
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