endComent :: Action
endComent cfg p txt s =
  case s of
    InComment d f [] cs     -> (Just (mkToken d f cs), Normal)
    InComment d _ (q:qs) cs -> (Nothing, InComment d q qs (txt : cs))
    _                     -> panic "[Lexer] endComment" ["outside comment"]
  where
  mkToken isDoc f cs =
    let r   = Range { from = f, to = moves p txt, source = cfgSource cfg }
        str = T.concat $ reverse $ txt : cs

        tok = if isDoc then DocStr else BlockComment
    in Located { srcRange = r, thing = Token (White tok) str }
endComent :: Action
endComent cfg p txt s =
  case s of
    InComment d f [] cs     -> (Just (mkToken d f cs), Normal)
    InComment d _ (q:qs) cs -> (Nothing, InComment d q qs (txt : cs))
    _                     -> panic "[Lexer] endComment" ["outside comment"]
  where
  mkToken isDoc f cs =
    let r   = Range { from = f, to = moves p txt, source = cfgSource cfg }
        str = T.concat $ reverse $ txt : cs

        tok = if isDoc then DocStr else BlockComment
    in Located { srcRange = r, thing = Token (White tok) str }
endComent cfg p txt s =
  case s of
    InComment d f [] cs     -> (Just (mkToken d f cs), Normal)
    InComment d _ (q:qs) cs -> (Nothing, InComment d q qs (txt : cs))
    _                     -> panic "[Lexer] endComment" ["outside comment"]
  where
  mkToken isDoc f cs =
    let r   = Range { from = f, to = moves p txt, source = cfgSource cfg }
        str = T.concat $ reverse $ txt : cs

        tok = if isDoc then DocStr else BlockComment
    in Located { srcRange = r, thing = Token (White tok) str }