From e7dfb662edf769cfc40b25947117ed1e9feee53f Mon Sep 17 00:00:00 2001 From: Pagwin Date: Sat, 31 Jan 2026 15:09:45 -0500 Subject: [PATCH] fix type errors in javascript tokenizer Fixed three type errors preventing compilation: - template_char: properly convert Tokens s to s for string literals and eol - regex_literal: correctly apply fromString to parser result, not parser itself - reg_first_char: use explicit list notation to resolve noneOf ambiguity Co-Authored-By: Claude Sonnet 4.5 --- src/Utilities/Javascript.hs | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/src/Utilities/Javascript.hs b/src/Utilities/Javascript.hs index 195a129..e61f5b6 100644 --- a/src/Utilities/Javascript.hs +++ b/src/Utilities/Javascript.hs @@ -384,17 +384,16 @@ literal = pure $ TemplateTail $ fromText $ mconcat $ map toText $ contents template_char :: Parser s m s template_char = - fromText . toText - <$> choice - [ try (string "$" <* (notFollowedBy $ char '{')), - try escape_seq, - try ((optional $ char '\\') *> (eol)), - -- I'm sure this is doable without do but do makes it much easier - do - notFollowedBy (choice [void linebreak, void $ char '`', void $ char '\\', void $ char '$']) - c <- source_char - pure $ fromString $ c : [] - ] + choice + [ try ((fromText . toText <$> string "$") <* (notFollowedBy $ char '{')), + try escape_seq, + try (fromText . toText <$> ((optional $ char '\\') *> (eol))), + -- I'm sure this is doable without do but do makes it much easier + do + notFollowedBy (choice [void linebreak, void $ char '`', void $ char '\\', void $ char '$']) + c <- source_char + pure $ fromString $ c : [] + ] source_char = anySingle escape_seq = do char '\\' @@ -446,13 +445,13 @@ fslash_handler = do rem_chars <- many reg_rem_char let body = fromString (first_char : rem_chars) char '/' - flags <- fromString $ tokensToChunk (Proxy :: Proxy s) <$> many letterChar + flags <- fromString <$> many letterChar pure $ Literal $ Regex {body, flags} reg_first_char :: Parser s m Char -- ecmascript specification name lied to me, it can be more than one char >:( -- to clarify this is technically wrong but I don't care because I don't want to rewrite -- other code due to ecmascript standard using bad names - reg_first_char = noneOf "*/" + reg_first_char = noneOf ['*', '/'] reg_rem_char :: Parser s m Char reg_rem_char = anySingleBut '/' division_assign :: Parser s m (Token s)