Skip to content

Commit

Permalink
Overload Token/Rule Types since they are currently not used simultano…
Browse files Browse the repository at this point in the history
…usly

Co-authored-by: Matus Tejiscak <ziman@functor.sk>
  • Loading branch information
fabianhjr and ziman committed May 24, 2020
1 parent a6b3565 commit dfd24ac
Show file tree
Hide file tree
Showing 13 changed files with 225 additions and 226 deletions.
12 changes: 6 additions & 6 deletions src/Idris/IDEMode/Parser.idr
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ import Utils.String
symbols : List String
symbols = ["(", ":", ")"]

ideTokens : TokenMap SourceToken
ideTokens : TokenMap Token
ideTokens =
map (\x => (exact x, Symbol)) symbols ++
[(digits, \x => IntegerLit (cast x)),
(stringLit, \x => StringLit (stripQuotes x)),
(identAllowDashes, \x => Ident x),
(space, Comment)]

idelex : String -> Either (Int, Int, String) (List (TokenData SourceToken))
idelex : String -> Either (Int, Int, String) (List (TokenData Token))
idelex str
= case lex ideTokens str of
-- Add the EndInput token so that we'll have a line and column
Expand All @@ -37,12 +37,12 @@ idelex str
[MkToken l c EndInput])
(_, fail) => Left fail
where
notComment : TokenData SourceToken -> Bool
notComment : TokenData Token -> Bool
notComment t = case tok t of
Comment _ => False
_ => True

sexp : SourceRule SExp
sexp : Rule SExp
sexp
= do symbol ":"; exactIdent "True"
pure (BoolAtom True)
Expand All @@ -59,14 +59,14 @@ sexp
symbol ")"
pure (SExpList xs)

ideParser : {e : _} -> String -> Grammar (TokenData SourceToken) e ty -> Either (ParseError SourceToken) ty
ideParser : {e : _} -> String -> Grammar (TokenData Token) e ty -> Either (ParseError Token) ty
ideParser str p
= do toks <- mapError LexFail $ idelex str
parsed <- mapError toGenericParsingError $ parse p toks
Right (fst parsed)


export
parseSExp : String -> Either (ParseError SourceToken) SExp
parseSExp : String -> Either (ParseError Token) SExp
parseSExp inp
= ideParser inp (do c <- sexp; eoi; pure c)
8 changes: 4 additions & 4 deletions src/Idris/Package.idr
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ data DescField : Type where
PPreclean : FC -> String -> DescField
PPostclean : FC -> String -> DescField

field : String -> PackageRule DescField
field : String -> Rule DescField
field fname
= strField PVersion "version"
<|> strField PAuthors "authors"
Expand Down Expand Up @@ -151,15 +151,15 @@ field fname
e <- getString
pure (PExec e)
where
strField : (FC -> String -> DescField) -> String -> PackageRule DescField
strField : (FC -> String -> DescField) -> String -> Rule DescField
strField p f
= do start <- location
exactProperty f
str <- getString
end <- location
pure $ p (MkFC fname start end) str

parsePkgDesc : String -> PackageRule (String, List DescField)
parsePkgDesc : String -> Rule (String, List DescField)
parsePkgDesc fname
= do name <- packageName
fields <- many (field fname)
Expand Down Expand Up @@ -416,7 +416,7 @@ clean pkg
delete $ ttFile ++ ".ttc"
delete $ ttFile ++ ".ttm"

getParseErrorLoc : String -> ParseError PackageToken -> FC
getParseErrorLoc : String -> ParseError Token -> FC
getParseErrorLoc fname (ParseFail _ (Just pos) _) = MkFC fname pos pos
getParseErrorLoc fname (LexFail (l, c, _)) = MkFC fname (l, c) (l, c)
getParseErrorLoc fname (LitFail _) = MkFC fname (0, 0) (0, 0) -- TODO: Remove this unused case
Expand Down
Loading

0 comments on commit dfd24ac

Please sign in to comment.