Fix of batchcode to correctly handle code inserted at the beginning of the file, outside a block

This commit is contained in:
Griatch 2017-09-03 00:09:24 +02:00
parent ac65c9f7ec
commit 2bb0b23688

View file

@ -183,7 +183,7 @@ _ENCODINGS = settings.ENCODINGS
_RE_INSERT = re.compile(r"^\#INSERT (.*)", re.MULTILINE) _RE_INSERT = re.compile(r"^\#INSERT (.*)", re.MULTILINE)
_RE_CLEANBLOCK = re.compile(r"^\#.*?$|^\s*$", re.MULTILINE) _RE_CLEANBLOCK = re.compile(r"^\#.*?$|^\s*$", re.MULTILINE)
_RE_CMD_SPLIT = re.compile(r"^\#.*?$", re.MULTILINE) _RE_CMD_SPLIT = re.compile(r"^\#.*?$", re.MULTILINE)
_RE_CODE_OR_HEADER = re.compile(r"(\A|^\#CODE|^\#HEADER).*?$(.*?)(?=^#CODE.*?$|^#HEADER.*?$|\Z)", _RE_CODE_OR_HEADER = re.compile(r"((?:\A|^)#CODE|(?:/A|^)#HEADER|\A)(.*?)$(.*?)(?=^#CODE.*?$|^#HEADER.*?$|\Z)",
re.MULTILINE + re.DOTALL) re.MULTILINE + re.DOTALL)
@ -352,8 +352,10 @@ class BatchCodeProcessor(object):
headers = [] headers = []
codes = [] codes = []
for imatch, match in enumerate(list(_RE_CODE_OR_HEADER.finditer(text))): for imatch, match in enumerate(list(_RE_CODE_OR_HEADER.finditer(text))):
mtype = match.group(1) mtype = match.group(1).strip()
istart, iend = match.span(2) # we need to handle things differently at the start of the file
mgroup = 3 if mtype else 2
istart, iend = match.span(mgroup)
code = text[istart:iend] code = text[istart:iend]
if mtype == "#HEADER": if mtype == "#HEADER":
headers.append(code) headers.append(code)