@@ -974,7 +974,6 @@ $hexit = [0-9a-fA-F]
974974-- Macro related
975975
976976@subst_nt = "$" @ident
977- @match_nt = @subst_nt ":" @ident
978977
979978tokens :-
980979
@@ -1076,13 +1075,6 @@ $white+ { \s -> pure (Space Whitespace s) }
10761075@line_comment { \c - > pure (Space Comment (drop 2 c)) }
10771076@inline_comment { \_ - > Space Comment < $> nestedComment }
10781077
1079- "#!" { token Shebang }
1080-
1081- @subst_nt { \(_: i) - > pure (SubstNt (mkIdent i)) }
1082- @match_nt { \(_: s) - > let (i,' :' : n) = Prelude . span (/= ' :' ) s
1083- in pure (MatchNt (mkIdent i) (mkIdent n))
1084- }
1085-
10861078{
10871079
10881080-- | Make a token.
@@ -1106,8 +1098,7 @@ literal lit = do
11061098 _ - > pure (LiteralTok lit Nothing )
11071099
11081100-- | Parses a raw string, the closing quotation, and the appropriate number of
1109- -- ' #' characters. Note that there can be more closing ' #' characters than
1110- -- opening ones (this is as per Rust ' s standard).
1101+ -- ' #' characters.
11111102rawString :: Int - > P String
11121103rawString n = do
11131104 c_m < - nextChar
@@ -1117,8 +1108,8 @@ rawString n = do
11171108
11181109 -- The string has a chance of being closed
11191110 Just ' "' - > do
1120- n' <- greedyChar '#'
1121- if n' > = n
1111+ n' <- greedyChar ' #' n
1112+ if n' = = n
11221113 then pure " "
11231114 else ((' "' : replicate n' ' #' ) ++) <$> rawString n
11241115
@@ -1174,12 +1165,13 @@ peekChar = do
11741165 in pure (Just c)
11751166
11761167-- | Greedily try to eat as many of a given character as possible (and return
1177- -- how many characters were eaten).
1178- greedyChar :: Char -> P Int
1179- greedyChar c = do
1168+ -- how many characters were eaten). The second argument is an upper limit.
1169+ greedyChar :: Char - > Int - > P Int
1170+ greedyChar _ 0 = pure 0
1171+ greedyChar c limit = do
11801172 c_m < - peekChar
11811173 case c_m of
1182- Just c' | c == c' -> do { _ <- nextChar; n <- greedyChar c; pure (n+1) }
1174+ Just c' | c == c' - > do { _ < - nextChar; n < - greedyChar c (limit - 1 ) ; pure (n+ 1 ) }
11831175 _ - > pure 0
11841176
11851177-- | Signal a lexical error.
@@ -1257,19 +1249,13 @@ lexTokens lexer = do
12571249 _ - > (tok : ) < $> lexTokens lexer
12581250
12591251-- | Lex the first line, if it immediately starts with @ #! @ (but not @ #! [@ - that should be an
1260- -- inner attribute). If this fails to find a shebang line, it consumes no input (in reality it does
1261- -- consume one token, but it pushed it back).
1252+ -- inner attribute). If this fails to find a shebang line, it consumes no input.
12621253lexShebangLine :: P (Maybe String )
12631254lexShebangLine = do
1264- tok <- lexNonSpace
1265- case unspan tok of
1266- Shebang -> do
1267- c <- peekChar
1268- case c of
1269- Just ' [' -> pushToken tok *> pure Nothing
1270- _ -> Just <$> toNewline
1271- _ -> pushToken tok *> pure Nothing
1272-
1255+ inp < - getInput
1256+ case takeChars 3 inp of
1257+ ' #' : ' !' : r | r /= " [" - > Just < $> toNewline
1258+ _ - > pure Nothing
12731259 where
12741260 -- Lexes a string until a newline
12751261 toNewline :: P String
0 commit comments