fix importing with dots, prep work for porting
This commit is contained in:
@@ -12,7 +12,6 @@ import Data.List
|
||||
import Lib.Types -- Name / Tm
|
||||
import Lib.TopContext
|
||||
import Lib.Prettier
|
||||
import Lib.Eval -- lookupMeta
|
||||
import Lib.Util
|
||||
|
||||
public export
|
||||
|
||||
@@ -389,7 +389,13 @@ parseSig : Parser Decl
|
||||
parseSig = TypeSig <$> getPos <*> try (some (ident <|> uident) <* keyword ":") <*> typeExpr
|
||||
|
||||
parseImport : Parser Import
|
||||
parseImport = MkImport <$> getPos <* keyword "import" <*> uident
|
||||
parseImport = do
|
||||
fc <- getPos
|
||||
keyword "import"
|
||||
ident <- uident
|
||||
rest <- many $ token Projection
|
||||
let name = joinBy "" (ident :: rest)
|
||||
pure $ MkImport fc name
|
||||
|
||||
-- Do we do pattern stuff now? or just name = lambda?
|
||||
-- TODO multiple names
|
||||
@@ -523,7 +529,14 @@ parseDecl = parseMixfix <|> parsePType <|> parsePFunc
|
||||
|
||||
export
|
||||
parseModHeader : Parser (FC, String)
|
||||
parseModHeader = sameLevel (keyword "module") >> withPos uident
|
||||
parseModHeader = do
|
||||
sameLevel (keyword "module")
|
||||
fc <- getPos
|
||||
name <- uident
|
||||
rest <- many $ token Projection
|
||||
-- FIXME use QName
|
||||
let name = joinBy "" (name :: rest)
|
||||
pure (fc, name)
|
||||
|
||||
export
|
||||
parseImports : Parser (List Import)
|
||||
@@ -535,6 +548,9 @@ parseMod = do
|
||||
startBlock $ do
|
||||
keyword "module"
|
||||
name <- uident
|
||||
rest <- many $ token Projection
|
||||
-- FIXME use QName
|
||||
let name = joinBy "" (name :: rest)
|
||||
imports <- manySame $ parseImport
|
||||
decls <- manySame $ parseDecl
|
||||
pure $ MkModule name imports decls
|
||||
|
||||
@@ -18,6 +18,7 @@ data Kind
|
||||
| Space
|
||||
| Comment
|
||||
| Pragma
|
||||
| Projection
|
||||
-- not doing Layout.idr
|
||||
| LBrace
|
||||
| Semi
|
||||
@@ -42,6 +43,7 @@ Show Kind where
|
||||
show Pragma = "Pragma"
|
||||
show StringKind = "String"
|
||||
show JSLit = "JSLit"
|
||||
show Projection = "Projection"
|
||||
|
||||
export
|
||||
Eq Kind where
|
||||
@@ -58,6 +60,7 @@ Eq Kind where
|
||||
RBrace == RBrace = True
|
||||
StringKind == StringKind = True
|
||||
JSLit == JSLit = True
|
||||
Projection == Projection = True
|
||||
_ == _ = False
|
||||
|
||||
export
|
||||
|
||||
@@ -15,7 +15,9 @@ keywords = ["let", "in", "where", "case", "of", "data", "U", "do",
|
||||
"∀", "forall", "import", "uses",
|
||||
"class", "instance", "record", "constructor",
|
||||
"if", "then", "else",
|
||||
"$", "λ", "?", "@",
|
||||
-- it would be nice to find a way to unkeyword "." so it could be
|
||||
-- used as an operator too
|
||||
"$", "λ", "?", "@", ".",
|
||||
"->", "→", ":", "=>", ":=", "=", "<-", "\\", "_", "|"]
|
||||
|
||||
-- This makes a big case tree...
|
||||
@@ -38,6 +40,7 @@ tokenise' sl sc toks chars = case chars of
|
||||
'/' :: '-' :: cs => blockComment sl (sc + 2) toks cs
|
||||
'`' :: cs => doBacktick sl (sc + 1) toks cs [<]
|
||||
'"' :: cs => doQuote sl (sc + 1) toks cs [<]
|
||||
'.' :: cs => doRest sl (sc + 1) toks cs Projection isIdent (Lin :< '.')
|
||||
'-' :: c :: cs => if isDigit c
|
||||
then doRest sl (sc + 2) toks cs Number isDigit (Lin :< '-' :< c)
|
||||
else doRest sl (sc + 1) toks (c :: cs) Ident isIdent (Lin :< '-')
|
||||
@@ -48,6 +51,9 @@ tokenise' sl sc toks chars = case chars of
|
||||
isIdent : Char -> Bool
|
||||
isIdent c = not (isSpace c || elem c standalone)
|
||||
|
||||
isUIdent : Char -> Bool
|
||||
isUIdent c = isIdent c || c == '.'
|
||||
|
||||
doBacktick : Int -> Int -> SnocList BTok -> List Char -> SnocList Char -> Either Error (List BTok)
|
||||
doBacktick l c toks Nil acc = Left $ E (MkFC "" (l,c)) "EOF in backtick string"
|
||||
doBacktick el ec toks ('`' :: cs) acc =
|
||||
|
||||
Reference in New Issue
Block a user