pToken :: Lexer (Span, Token)
pToken = withPosition (try pToken' <|> pUnknown) <* pSkip
  where
    posToLoc :: SourcePos -> Loc
    posToLoc (SourcePos _ sourceLine sourceColumn) = uncurry loc
        ( fromIntegral . unPos $ sourceLine
        , fromIntegral . unPos $ sourceColumn)
    withPosition p = do
        pos1 <- posToLoc <$> getSourcePos
        t <- p
        pos2 <- posToLoc <$> getSourcePos
        return (spanFromTo pos1 pos2, t)
pToken :: Lexer (Span, Token)
pToken = withPosition (try pToken' <|> pUnknown) <* pSkip
  where
    posToLoc :: SourcePos -> Loc
    posToLoc (SourcePos _ sourceLine sourceColumn) = uncurry loc
        ( fromIntegral . unPos $ sourceLine
        , fromIntegral . unPos $ sourceColumn)
    withPosition p = do
        pos1 <- posToLoc <$> getSourcePos
        t <- p
        pos2 <- posToLoc <$> getSourcePos
        return (spanFromTo pos1 pos2, t)
pToken = withPosition (try pToken' <|> pUnknown) <* pSkip
  where
    posToLoc :: SourcePos -> Loc
    posToLoc (SourcePos _ sourceLine sourceColumn) = uncurry loc
        ( fromIntegral . unPos $ sourceLine
        , fromIntegral . unPos $ sourceColumn)
    withPosition p = do
        pos1 <- posToLoc <$> getSourcePos
        t <- p
        pos2 <- posToLoc <$> getSourcePos
        return (spanFromTo pos1 pos2, t)