on master help sign in
Fix syntax macro bug
eec2b83Edwin Brady
src/Idris/AbsSyntax.hs+1
@@ -582,6 +582,7 @@ deriving instance Binary Syntax
582data SSymbol = Keyword Name
582data SSymbol = Keyword Name
583 | Symbol String
583 | Symbol String
584 | Expr Name
584 | Expr Name
585+ | SimpleExpr Name
585 deriving Show
586 deriving Show
586{-!
587{-!
587deriving instance Binary SSymbol
588deriving instance Binary SSymbol
src/Idris/IBC.hs+5−1
@@ -22,7 +22,7 @@ import System.Directory
22import Paths_idris
22import Paths_idris
23
23
24ibcVersion :: Word8
24ibcVersion :: Word8
25−ibcVersion = 8
25+ibcVersion = 9
26
26
27data IBCFile = IBCFile { ver :: Word8,
27data IBCFile = IBCFile { ver :: Word8,
28 sourcefile :: FilePath,
28 sourcefile :: FilePath,
@@ -1034,6 +1034,8 @@ instance Binary SSymbol where
1034 put x1
1034 put x1
1035 Expr x1 -> do putWord8 2
1035 Expr x1 -> do putWord8 2
1036 put x1
1036 put x1
1037+ SimpleExpr x1 -> do putWord8 3
1038+ put x1
1037 get
1039 get
1038 = do i <- getWord8
1040 = do i <- getWord8
1039 case i of
1041 case i of
@@ -1043,4 +1045,6 @@ instance Binary SSymbol where
1043 return (Symbol x1)
1045 return (Symbol x1)
1044 2 -> do x1 <- get
1046 2 -> do x1 <- get
1045 return (Expr x1)
1047 return (Expr x1)
1048+ 3 -> do x1 <- get
1049+ return (SimpleExpr x1)
1046 _ -> error "Corrupted binary data for SSymbol"
1050 _ -> error "Corrupted binary data for SSymbol"
src/Idris/Parser.hs+22−10
@@ -366,13 +366,23 @@ pSyntaxRule syn
366 lchar '='
366 lchar '='
367 tm <- pExpr syn
367 tm <- pExpr syn
368 pTerminator
368 pTerminator
369− return (Rule syms tm sty)
369+ return (Rule (mkSimple syms) tm sty)
370 where
370 where
371 expr (Expr _) = True
371 expr (Expr _) = True
372 expr _ = False
372 expr _ = False
373 name (Expr n) = Just n
373 name (Expr n) = Just n
374 name _ = Nothing
374 name _ = Nothing
375
375
376+ -- Can't parse two full expressions (i.e. expressions with application) in a row
377+ -- so change the first to a simple expression
378+
379+ mkSimple (Expr e : es) = SimpleExpr e : mkSimple' es
380+ mkSimple xs = mkSimple' xs
381+
382+ mkSimple' (Expr e : Expr e1 : es) = SimpleExpr e : mkSimple' (Expr e1 : es)
383+ mkSimple' (e : es) = e : mkSimple' es
384+ mkSimple' [] = []
385+
376pSynSym :: IParser SSymbol
386pSynSym :: IParser SSymbol
377pSynSym = try (do lchar '['; n <- pName; lchar ']'
387pSynSym = try (do lchar '['; n <- pName; lchar ']'
378 return (Expr n))
388 return (Expr n))
@@ -508,6 +518,7 @@ pSimpleExtExpr syn = do i <- getState
508 pExtensions syn (filter simple (syntax_rules i))
518 pExtensions syn (filter simple (syntax_rules i))
509 where
519 where
510 simple (Rule (Expr x:xs) _ _) = False
520 simple (Rule (Expr x:xs) _ _) = False
521+ simple (Rule (SimpleExpr x:xs) _ _) = False
511 simple (Rule [Keyword _] _ _) = True
522 simple (Rule [Keyword _] _ _) = True
512 simple (Rule [Symbol _] _ _) = True
523 simple (Rule [Symbol _] _ _) = True
513 simple (Rule (_:xs) _ _) = case (last xs) of
524 simple (Rule (_:xs) _ _) = case (last xs) of
@@ -534,17 +545,18 @@ pExtensions syn rules = choice (map (\x -> try (pExt syn x)) (filter valid rules
534
545
535
546
536pExt :: SyntaxInfo -> Syntax -> IParser PTerm
547pExt :: SyntaxInfo -> Syntax -> IParser PTerm
537−pExt syn (Rule (s:ssym) ptm _)
548+pExt syn (Rule ssym ptm _)
538− = do s1 <- pSymbol pSimpleExpr s
539− smap <- mapM (pSymbol pExpr) ssym
549+ = do smap <- mapM pSymbol ssym
540− let ns = mapMaybe id (s1:smap)
550+ let ns = mapMaybe id smap
541 return (update ns ptm) -- updated with smap
551 return (update ns ptm) -- updated with smap
542 where
552 where
543− pSymbol p (Keyword n) = do reserved (show n); return Nothing
553+ pSymbol (Keyword n) = do reserved (show n); return Nothing
544− pSymbol p (Expr n) = do tm <- p syn
554+ pSymbol (Expr n) = do tm <- pExpr syn
545− return $ Just (n, tm)
555+ return $ Just (n, tm)
556+ pSymbol (SimpleExpr n) = do tm <- pSimpleExpr syn
557+ return $ Just (n, tm)
546− pSymbol p (Symbol s) = do symbol s
558+ pSymbol (Symbol s) = do symbol s
547− return Nothing
559+ return Nothing
548 dropn n [] = []
560 dropn n [] = []
549 dropn n ((x,t) : xs) | n == x = xs
561 dropn n ((x,t) : xs) | n == x = xs
550 | otherwise = (x,t):dropn n xs
562 | otherwise = (x,t):dropn n xs