headroom-0.4.0.0: License Header Manager
Copyright(c) 2019-2021 Vaclav Svejcar
LicenseBSD-3-Clause
Maintainervaclav.svejcar@gmail.com
Stabilityexperimental
PortabilityPOSIX
Safe HaskellNone
LanguageHaskell2010

Headroom.Header.Sanitize

Description

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

Documentation

findPrefix Source #

Arguments

:: HeaderSyntax

describes comment syntax of the header

-> Text

text containint the comment

-> HeaderSyntax

input HeaderSyntax with added prefix (if found)

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 " *")

sanitizeSyntax Source #

Arguments

:: 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"

stripCommentSyntax Source #

Arguments

:: 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"