From 8c0dd46f9a288f4a2caed973fcb55f94c1c05a8f Mon Sep 17 00:00:00 2001 From: =?utf8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Mon, 23 Oct 2017 09:22:39 +0200 Subject: [PATCH] css: ignore license blobs when postprocessing. OTOH, put just a single one explicitly at the start. --- css/postprocess.py | 55 ++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 53 insertions(+), 2 deletions(-) diff --git a/css/postprocess.py b/css/postprocess.py index dafcd252..555076f9 100755 --- a/css/postprocess.py +++ b/css/postprocess.py @@ -32,6 +32,8 @@ import_rx = re.compile("^@import url\\('(?P[^']+)'\\);$") opening_brace_rx = re.compile("^\\s*:root\s*{\\s*$") closing_brace_rx = re.compile("^\\s*}\\s*$") comment_rx = re.compile("^\\s*(/\\*.*\\*/)?\\s*$") +comment_start_rx = re.compile("^\\s*(/\\*.*)\\s*$") +comment_end_rx = re.compile("^\\s*(.*\\*/)\\s*$") variable_declaration_rx = re.compile("^\\s*(?P--[a-z-]+)\\s*:\\s*(?P[^;]+)\\s*;\\s*$") variable_use_rx = re.compile("^(?P.+)var\\((?P--[a-z-]+)\\)(?P.+)$") @@ -46,13 +48,45 @@ def postprocess(files): not_just_variable_declarations = False - # Put a helper comment on top - out.write("/* Generated using `./postprocess.py {}`. Do not edit. */\n".format(' '.join(files))) + # Put a helper comment and a license blob on top + out.write("""/* Generated using `./postprocess.py {}`. Do not edit. */ + +/* + This file is part of m.css. + + Copyright © 2017 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. +*/ +""".format(' '.join(files))) # Parse the top-level file with open(files[0]) as f: in_variable_declarations = False + in_comment = False for line in f: + # In comment and the comment is not ending yet, ignore + if in_comment: + if comment_end_rx.match(line): + in_comment = False + continue + # Import statement: add the file at the beginning of th match = import_rx.match(line) if match: @@ -75,6 +109,11 @@ def postprocess(files): if comment_rx.match(line): continue + # Comment start line, ignore this and the next lines + if comment_start_rx.match(line): + in_comment = True + continue + # Closing brace of variable declaration block. If it was not # just variable declarations, put the closing brace to the # output as well. @@ -97,7 +136,14 @@ def postprocess(files): out.write('\n') with open(file) as f: + in_comment = False for line in f: + # In comment and the comment is not ending yet, ignore + if in_comment: + if comment_end_rx.match(line): + in_comment = False + continue + # Variable use, replace with actual value # TODO: more variables on the same line? match = variable_use_rx.match(line) @@ -112,6 +158,11 @@ def postprocess(files): if comment_rx.match(line): continue + # Comment start line, ignore this and the next lines + if comment_start_rx.match(line): + in_comment = True + continue + # Something else, copy verbatim to the output out.write(line) -- 2.30.2