avoid list lookup by parseToken

Minor optimisation to parsing of a preferred content expression.
This commit is contained in:
Joey Hess 2019-05-14 13:08:51 -04:00
parent c1957b6aeb
commit aa7710982b
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38
5 changed files with 17 additions and 21 deletions

View file

@ -84,9 +84,9 @@ data ParseToken t
type ParseResult t = Either String (Token t)
parseToken :: [ParseToken t] -> String -> ParseResult t
parseToken l t
| t `elem` tokens = Right $ token t
| otherwise = go l
parseToken l t = case syntaxToken t of
Right st -> Right st
Left _ -> go l
where
go [] = Left $ "near " ++ show t
go (SimpleToken s r : _) | s == t = r