-- Evaluate an xparse-style conditional.
--
-- Note: In LaTeX3 this is defined via @\\ifx@.
xparseif :: HandleTeXIO m => Token -> LexerT m [Token]
xparseif t = do
  rs <- token <* skipOptSpace
  stripBraces <$> case stripBraces rs of
    [r] | r == t -> token <* skipOptSpace <* token
    _ -> token *> skipOptSpace *> token

---------- Builtin macros: catcodes

-- Parse the body of a @catcode@ command, execute it (by changing the
-- current catcode table) and remove catcode command from the token stream.
xparseif :: HandleTeXIO m => Token -> LexerT m [Token]
xparseif t = do
  rs <- token <* skipOptSpace
  stripBraces <$> case stripBraces rs of
    [r] | r == t -> token <* skipOptSpace <* token
    _ -> token *> skipOptSpace *> token

---------- Builtin macros: catcodes

-- Parse the body of a @catcode@ command, execute it (by changing the
-- current catcode table) and remove catcode command from the token stream.
xparseif t = do
  rs <- token <* skipOptSpace
  stripBraces <$> case stripBraces rs of
    [r] | r == t -> token <* skipOptSpace <* token
    _ -> token *> skipOptSpace *> token

---------- Builtin macros: catcodes

-- Parse the body of a @catcode@ command, execute it (by changing the
-- current catcode table) and remove catcode command from the token stream.