Skip to content

Commit 02b33ff

Browse files
committed
Parser: nixUri: refactor
1 parent ac71d02 commit 02b33ff

File tree

1 file changed

+21
-16
lines changed

1 file changed

+21
-16
lines changed

src/Nix/Parser.hs

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -244,21 +244,26 @@ nixFloat =
244244
mkFloatF . realToFrac <$> float
245245

246246
nixUri :: Parser NExprLoc
247-
nixUri = lexeme $ annotateLocation $ try $ do
248-
start <- letterChar
249-
protocol <- many $
250-
satisfy $
251-
\ x ->
252-
isAlphanumeric x
253-
|| (`elem` ("+-." :: String)) x
254-
_ <- chunk ":"
255-
address <-
256-
some $
257-
satisfy $
258-
\ x ->
259-
isAlphanumeric x
260-
|| (`elem` ("%/?:@&=+$,-_.!~*'" :: String)) x
261-
pure $ NStr $ DoubleQuoted $ one $ Plain $ toText $ one start <> protocol <> ":" <> address
247+
nixUri =
248+
lexeme $
249+
annotateLocation $
250+
try $
251+
do
252+
start <- letterChar
253+
protocol <-
254+
many $
255+
satisfy $
256+
\ x ->
257+
isAlphanumeric x
258+
|| (`elem` ("+-." :: String)) x
259+
_ <- chunk ":"
260+
address <-
261+
some $
262+
satisfy $
263+
\ x ->
264+
isAlphanumeric x
265+
|| (`elem` ("%/?:@&=+$,-_.!~*'" :: String)) x
266+
pure $ NStr $ DoubleQuoted $ one $ Plain $ toText $ one start <> protocol <> ":" <> address
262267

263268

264269
-- ** Strings
@@ -377,7 +382,7 @@ nixBinders = (inherit <|> namedVar) `endBy` symbol ';' where
377382
do
378383
-- We can't use 'reserved' here because it would consume the whitespace
379384
-- after the keyword, which is not exactly the semantics of C++ Nix.
380-
try $ chunk "inherit" *> lookAhead (void (satisfy reservedEnd))
385+
try $ chunk "inherit" *> lookAhead (void $ satisfy reservedEnd)
381386
p <- getSourcePos
382387
x <- whiteSpace *> optional scope
383388
label "inherited binding" $

0 commit comments

Comments
 (0)