Copyright | (c) 2019-2021 Vaclav Svejcar |
---|---|
License | BSD-3-Clause |
Maintainer | vaclav.svejcar@gmail.com |
Stability | experimental |
Portability | POSIX |
Safe Haskell | None |
Language | Haskell2010 |
This module contains functions related to sanitizing license headers. Because license headers are just regular comments in given programming language, they need to have correct syntax in order to avoid causing compile/runtime errors. Because header manipulation done by Headroom can disrupt the comment syntax structure, sanitizing the header is the last step done in the flow, making sure that license header syntax is not broken.
Synopsis
- findPrefix :: HeaderSyntax -> Text -> HeaderSyntax
- sanitizeSyntax :: HeaderSyntax -> Text -> Text
- stripCommentSyntax :: HeaderSyntax -> Text -> Text
Documentation
:: HeaderSyntax | describes comment syntax of the header |
-> Text | text containint the comment |
-> HeaderSyntax | input |
Tries to find comment prefix in given comment. By prefix it's meant
either the line prefix used for block comment syntax (like *
at start of
each line between opening and closing pattern - * *
) or line comment
syntax (just the syntax for comment itself - like //
or --
). If such
prefix is found, it's then added to the input HeaderSyntax
.
>>>
:set -XQuasiQuotes
>>>
import Headroom.Data.Regex (re)
>>>
findPrefix (BlockComment [re|^\/\*|] [re|\*\/$|] Nothing) "/*\n * foo\n * bar\n */"
BlockComment "^\\/\\*" "\\*\\/$" (Just " *")
:: HeaderSyntax | header syntax definition that may contain prefix |
-> Text | header to sanitize |
-> Text | sanitized header |
Sanitizes given header text to make sure that each comment line starts with
appropriate prefix (if defined within given HeaderSyntax
). For block
comments, this is to make it visually unified, but for line comments it's
necessary in order not to break syntax of target source code file.
>>>
:set -XQuasiQuotes
>>>
import Headroom.Data.Regex (re)
>>>
sanitizeSyntax (LineComment [re|^--|] (Just "--")) "-- foo\nbar"
"-- foo\n-- bar"
:: HeaderSyntax | copyright header syntax |
-> Text | input text from which to strip the syntax |
-> Text | processed text |
Strips comment syntax from given text.
>>>
:set -XQuasiQuotes
>>>
import Headroom.Data.Regex (re)
>>>
stripCommentSyntax (LineComment [re|^--|] (Just "--")) "-- a\n-- b"
"a\n b"