@@ -974,7 +974,6 @@ $hexit = [0-9a-fA-F]
974
974
-- Macro related
975
975
976
976
@subst_nt = "$" @ident
977
- @match_nt = @subst_nt ":" @ident
978
977
979
978
tokens :-
980
979
@@ -1076,13 +1075,6 @@ $white+ { \s -> pure (Space Whitespace s) }
1076
1075
@line_comment { \c - > pure (Space Comment (drop 2 c)) }
1077
1076
@inline_comment { \_ - > Space Comment < $> nestedComment }
1078
1077
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
-
1086
1078
{
1087
1079
1088
1080
-- | Make a token.
@@ -1106,8 +1098,7 @@ literal lit = do
1106
1098
_ - > pure (LiteralTok lit Nothing )
1107
1099
1108
1100
-- | 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.
1111
1102
rawString :: Int - > P String
1112
1103
rawString n = do
1113
1104
c_m < - nextChar
@@ -1117,8 +1108,8 @@ rawString n = do
1117
1108
1118
1109
-- The string has a chance of being closed
1119
1110
Just ' "' - > do
1120
- n' <- greedyChar '#'
1121
- if n' > = n
1111
+ n' <- greedyChar ' #' n
1112
+ if n' = = n
1122
1113
then pure " "
1123
1114
else ((' "' : replicate n' ' #' ) ++) <$> rawString n
1124
1115
@@ -1174,12 +1165,13 @@ peekChar = do
1174
1165
in pure (Just c)
1175
1166
1176
1167
-- | 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
1180
1172
c_m < - peekChar
1181
1173
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 ) }
1183
1175
_ - > pure 0
1184
1176
1185
1177
-- | Signal a lexical error.
@@ -1257,19 +1249,13 @@ lexTokens lexer = do
1257
1249
_ - > (tok : ) < $> lexTokens lexer
1258
1250
1259
1251
-- | 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.
1262
1253
lexShebangLine :: P (Maybe String )
1263
1254
lexShebangLine = 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
1273
1259
where
1274
1260
-- Lexes a string until a newline
1275
1261
toNewline :: P String
0 commit comments