@@ -148,6 +148,7 @@ collect (c@(PClauses _ o _ _) : ds)
148 getfc (PClauses fc _ _ _) = fc
148 getfc (PClauses fc _ _ _) = fc
150collect (PParams f ns ps : ds) = PParams f ns (collect ps) : collect ds
150collect (PParams f ns ps : ds) = PParams f ns (collect ps) : collect ds
151+collect (PNamespace ns ps : ds) = PNamespace ns (collect ps) : collect ds
151collect (PClass f s cs n ps ds : ds') = PClass f s cs n ps (collect ds) : collect ds'
152collect (PClass f s cs n ps ds : ds') = PClass f s cs n ps (collect ds) : collect ds'
152collect (PInstance f s cs n ps t ds : ds')
153collect (PInstance f s cs n ps t ds : ds')
153 = PInstance f s cs n ps t (collect ds) : collect ds'
154 = PInstance f s cs n ps t (collect ds) : collect ds'
@@ -168,6 +169,7 @@ pDecl syn
168 return [d']
169 return [d']
169 <|> pUsing syn
170 <|> pUsing syn
170 <|> pParams syn
171 <|> pParams syn
171 <|> pClass syn
173 <|> pClass syn
172 <|> pInstance syn
174 <|> pInstance syn
173 <|> pDirective
175 <|> pDirective
@@ -237,7 +239,8 @@ pSynSym = try (do lchar '['; n <- pName; lchar ']'
237 return (Symbol sym)
239 return (Symbol sym)
239pFunDecl' :: SyntaxInfo -> IParser PDecl
241pFunDecl' :: SyntaxInfo -> IParser PDecl
240−pFunDecl' syn = try (do n <- pfName;
242+pFunDecl' syn = try (do n_in <- pfName
243+ let n = expandNS syn n_in
241 ty <- pTSig syn
244 ty <- pTSig syn
242 fc <- pfc
245 fc <- pfc
243 lchar ';'
246 lchar ';'
@@ -270,6 +273,20 @@ pParams syn =
270 fc <- pfc
273 fc <- pfc
271 return [PParams fc ns (concat ds)]
274 return [PParams fc ns (concat ds)]
276+pNamespace :: SyntaxInfo -> IParser [PDecl]
278+ do reserved "namespace";
281+ ds <- many1 (pDecl syn { syn_namespace = n : syn_namespace syn })
283+ return [PNamespace n (concat ds)]
285+expandNS :: SyntaxInfo -> Name -> Name
286+expandNS syn n = case syn_namespace syn of
273--------- Fixity ---------
290--------- Fixity ---------
275pFixity :: IParser PDecl
292pFixity :: IParser PDecl
@@ -295,7 +312,7 @@ pClass :: SyntaxInfo -> IParser [PDecl]
295pClass syn = do reserved "class"
312pClass syn = do reserved "class"
296 fc <- pfc
313 fc <- pfc
297 cons <- pConstList syn
314 cons <- pConstList syn
298− n <- pName
315+ n_in <- pName; let n = expandNS syn n_in
299 cs <- many1 carg
316 cs <- many1 carg
300 reserved "where"; lchar '{'
317 reserved "where"; lchar '{'
301 ds <- many1 $ pFunDecl syn;
318 ds <- many1 $ pFunDecl syn;
@@ -607,14 +624,16 @@ prefix name f = Prefix (do { reservedOp name; fc <- pfc;
608pData :: SyntaxInfo -> IParser PDecl
625pData :: SyntaxInfo -> IParser PDecl
609pData syn = try (do reserved "data"; fc <- pfc
626pData syn = try (do reserved "data"; fc <- pfc
610− tyn <- pfName; ty <- pTSig syn
627+ tyn_in <- pfName; ty <- pTSig syn
628+ let tyn = expandNS syn tyn_in
611 reserved "where"
629 reserved "where"
612-- ty' <- implicit syn tyn ty
630-- ty' <- implicit syn tyn ty
613 cons <- sepBy (pConstructor syn) (lchar '|')
631 cons <- sepBy (pConstructor syn) (lchar '|')
614 lchar ';'
632 lchar ';'
615 return $ PData syn fc (PDatadecl tyn ty cons))
633 return $ PData syn fc (PDatadecl tyn ty cons))
616 <|> do reserved "data"; fc <- pfc
634 <|> do reserved "data"; fc <- pfc
617− tyn <- pfName; args <- many pName
635+ tyn_in <- pfName; args <- many pName
636+ let tyn = expandNS syn tyn_in
618 lchar '='
637 lchar '='
619 cons <- sepBy1 (pSimpleCon syn) (lchar '|')
638 cons <- sepBy1 (pSimpleCon syn) (lchar '|')
620 lchar ';'
639 lchar ';'
@@ -636,14 +655,16 @@ bindArgs (x:xs) t = PPi expl (MN 0 "t") x (bindArgs xs t)
637pConstructor :: SyntaxInfo -> IParser (Name, PTerm, FC)
656pConstructor :: SyntaxInfo -> IParser (Name, PTerm, FC)
638pConstructor syn
657pConstructor syn
639− = do cn <- pfName; fc <- pfc
658+ = do cn_in <- pfName; fc <- pfc
659+ let cn = expandNS syn cn_in
640 ty <- pTSig syn
660 ty <- pTSig syn
641-- ty' <- implicit syn cn ty
661-- ty' <- implicit syn cn ty
642 return (cn, ty, fc)
662 return (cn, ty, fc)
644pSimpleCon :: SyntaxInfo -> IParser (Name, [PTerm], FC)
664pSimpleCon :: SyntaxInfo -> IParser (Name, [PTerm], FC)
645pSimpleCon syn
665pSimpleCon syn
646− = do cn <- pfName
666+ = do cn_in <- pfName
667+ let cn = expandNS syn cn_in
647 fc <- pfc
668 fc <- pfc
648 args <- many (pSimpleExpr syn)
669 args <- many (pSimpleExpr syn)
649 return (cn, args, fc)
670 return (cn, args, fc)
@@ -668,7 +689,7 @@ pRHS syn n = do lchar '='; pExpr syn
669pClause :: SyntaxInfo -> IParser PClause
690pClause :: SyntaxInfo -> IParser PClause
670pClause syn
691pClause syn
671− = try (do n <- pfName
692+ = try (do n_in <- pfName; let n = expandNS syn n_in
672 cargs <- many (pConstraintArg syn)
693 cargs <- many (pConstraintArg syn)
673 iargs <- many (pImplicitArg syn)
694 iargs <- many (pImplicitArg syn)
674 fc <- pfc
695 fc <- pfc
@@ -677,11 +698,13 @@ pClause syn
677 rhs <- pRHS syn n
698 rhs <- pRHS syn n
678 ist <- getState
699 ist <- getState
679 let ctxt = tt_ctxt ist
700 let ctxt = tt_ctxt ist
701+ let wsyn = syn { syn_namespace = [] }
680− (wheres, nmap) <- choice [pWhereblock n syn, do lchar ';'
702+ (wheres, nmap) <- choice [pWhereblock n wsyn,
681− return ([], [])]
704+ return ([], [])]
682 return $ PClause n (PApp fc (PRef fc n)
705 return $ PClause n (PApp fc (PRef fc n)
683 (iargs ++ cargs ++ map pexp args)) wargs rhs wheres)
706 (iargs ++ cargs ++ map pexp args)) wargs rhs wheres)
684− <|> try (do n <- pfName
707+ <|> try (do n_in <- pfName; let n = expandNS syn n_in
685 cargs <- many (pConstraintArg syn)
708 cargs <- many (pConstraintArg syn)
686 iargs <- many (pImplicitArg syn)
709 iargs <- many (pImplicitArg syn)
687 fc <- pfc
710 fc <- pfc
@@ -698,19 +721,21 @@ pClause syn
699 <|> do l <- pArgExpr syn
722 <|> do l <- pArgExpr syn
700 op <- operator
723 op <- operator
701− let n = UN op
724+ let n = expandNS syn (UN op)
702 r <- pArgExpr syn
725 r <- pArgExpr syn
703 fc <- pfc
726 fc <- pfc
704 wargs <- many (pWExpr syn)
727 wargs <- many (pWExpr syn)
705 rhs <- pRHS syn n
728 rhs <- pRHS syn n
729+ let wsyn = syn { syn_namespace = [] }
706− (wheres, nmap) <- choice [pWhereblock n syn, do lchar ';'
730+ (wheres, nmap) <- choice [pWhereblock n wsyn,
707− return ([], [])]
732+ return ([], [])]
708 return $ PClause n (PApp fc (PRef fc n) [pexp l,pexp r])
733 return $ PClause n (PApp fc (PRef fc n) [pexp l,pexp r])
709 wargs rhs wheres
734 wargs rhs wheres
711 <|> do l <- pArgExpr syn
736 <|> do l <- pArgExpr syn
712 op <- operator
737 op <- operator
713− let n = UN op
738+ let n = expandNS syn (UN op)
714 r <- pArgExpr syn
739 r <- pArgExpr syn
715 fc <- pfc
740 fc <- pfc
716 wargs <- many (pWExpr syn)
741 wargs <- many (pWExpr syn)