on master help sign in
Fix syntax macro bug
commiteec2b836fcc23f57d73e797c27db1863e0b93a10 authorEdwin Brady <eb@cs.st-andrews.ac.uk> dateWed 18 Jan 2012, 15:39 (15 years ago) parent401e9a0
3 files changed+28−11
src/Idris/AbsSyntax.hs+1 src/Idris/IBC.hs+5−1 src/Idris/Parser.hs+22−10
src/Idris/AbsSyntax.hs+1
@@ -582,6 +582,7 @@ deriving instance Binary Syntax
582582data SSymbol = Keyword Name
583583 | Symbol String
584584 | Expr Name
585+ | SimpleExpr Name
585586 deriving Show
586587{-!
587588deriving instance Binary SSymbol
src/Idris/IBC.hs+5−1
@@ -22,7 +22,7 @@ import System.Directory
2222import Paths_idris
2323
2424ibcVersion :: Word8
25−ibcVersion = 8
25+ibcVersion = 9
2626
2727data IBCFile = IBCFile { ver :: Word8,
2828 sourcefile :: FilePath,
@@ -1034,6 +1034,8 @@ instance Binary SSymbol where
10341034 put x1
10351035 Expr x1 -> do putWord8 2
10361036 put x1
1037+ SimpleExpr x1 -> do putWord8 3
1038+ put x1
10371039 get
10381040 = do i <- getWord8
10391041 case i of
@@ -1043,4 +1045,6 @@ instance Binary SSymbol where
10431045 return (Symbol x1)
10441046 2 -> do x1 <- get
10451047 return (Expr x1)
1048+ 3 -> do x1 <- get
1049+ return (SimpleExpr x1)
10461050 _ -> error "Corrupted binary data for SSymbol"
src/Idris/Parser.hs+22−10
@@ -366,13 +366,23 @@ pSyntaxRule syn
366366 lchar '='
367367 tm <- pExpr syn
368368 pTerminator
369− return (Rule syms tm sty)
369+ return (Rule (mkSimple syms) tm sty)
370370 where
371371 expr (Expr _) = True
372372 expr _ = False
373373 name (Expr n) = Just n
374374 name _ = Nothing
375375
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+
376386pSynSym :: IParser SSymbol
377387pSynSym = try (do lchar '['; n <- pName; lchar ']'
378388 return (Expr n))
@@ -508,6 +518,7 @@ pSimpleExtExpr syn = do i <- getState
508518 pExtensions syn (filter simple (syntax_rules i))
509519 where
510520 simple (Rule (Expr x:xs) _ _) = False
521+ simple (Rule (SimpleExpr x:xs) _ _) = False
511522 simple (Rule [Keyword _] _ _) = True
512523 simple (Rule [Symbol _] _ _) = True
513524 simple (Rule (_:xs) _ _) = case (last xs) of
@@ -534,17 +545,18 @@ pExtensions syn rules = choice (map (\x -> try (pExt syn x)) (filter valid rules
534545
535546
536547pExt :: SyntaxInfo -> Syntax -> IParser PTerm
537−pExt syn (Rule (s:ssym) ptm _)
538− = do s1 <- pSymbol pSimpleExpr s
539− smap <- mapM (pSymbol pExpr) ssym
540− let ns = mapMaybe id (s1:smap)
548+pExt syn (Rule ssym ptm _)
549+ = do smap <- mapM pSymbol ssym
550+ let ns = mapMaybe id smap
541551 return (update ns ptm) -- updated with smap
542552 where
543− pSymbol p (Keyword n) = do reserved (show n); return Nothing
544− pSymbol p (Expr n) = do tm <- p syn
545− return $ Just (n, tm)
546− pSymbol p (Symbol s) = do symbol s
547− return Nothing
553+ pSymbol (Keyword n) = do reserved (show n); return Nothing
554+ pSymbol (Expr n) = do tm <- pExpr syn
555+ return $ Just (n, tm)
556+ pSymbol (SimpleExpr n) = do tm <- pSimpleExpr syn
557+ return $ Just (n, tm)
558+ pSymbol (Symbol s) = do symbol s
559+ return Nothing
548560 dropn n [] = []
549561 dropn n ((x,t) : xs) | n == x = xs
550562 | otherwise = (x,t):dropn n xs