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<key>--[a-z-]+)\\s*:\\s*(?P<value>[^;]+)\\s*;\\s*$")
variable_use_rx = re.compile("^(?P<before>.+)var\\((?P<key>--[a-z-]+)\\)(?P<after>.+)$")
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š <mosra@centrum.cz>
+
+ 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:
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.
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)
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)