Add ability to source from external macro files

This commit is contained in:
Akbar Rahman 2019-01-18 22:37:48 +00:00
parent 3f8326cd33
commit 75587f7b3a
Signed by: alvierahman90
GPG Key ID: 20609519444A1269
3 changed files with 11 additions and 6 deletions

View File

@ -3,3 +3,6 @@
.ca carbon
.ox oxygen
:wink: 😉
source tests/test_macros_biology
source tests/test_macros_custom_plurals
source tests/test_macros_plural

View File

@ -129,18 +129,20 @@ def get_macros(input):
"""
Turn a string into a list of tuples of macros
"""
response = []
# turn input into unvalidated list of macros
macros = [re.split('[ \t]', x) for x in input.split('\n')]
# validate macros
for index, macro in enumerate(macros):
if macro[0] == "source":
with open(macro[1]) as file:
response += get_macros(file.read())
if len(macro) == 2 or len(macro) == 3:
macros[index] = tuple(macros[index])
else:
macros.pop(index)
response.append(tuple(macros[index]))
return macros
return response
def main(args):

View File

@ -1,4 +1,4 @@
#/usr/bin/env sh
./pymacro -sm tests/test_macros_plural -m tests/test_macros_biology tests/test_input tests/test_actual_output
diff tests/test_actual_output tests/test_expected_output
./pymacro -s tests/test_input tests/test_actual_output
git diff tests/test_actual_output tests/test_expected_output