From 35ba7bfeba21313cedb514f70af4503131f0d15e Mon Sep 17 00:00:00 2001 From: Viv Date: Fri, 2 Jun 2023 16:33:43 -0400 Subject: [PATCH] `parsetja.py`: Move `parseLine` function down My main focus will be rewriting the `getCourse` function, so I want it to be at the top. --- tja2fumen/parsetja.py | 60 +++++++++++++++++++++---------------------- 1 file changed, 30 insertions(+), 30 deletions(-) diff --git a/tja2fumen/parsetja.py b/tja2fumen/parsetja.py index 89a8d24..90a4347 100644 --- a/tja2fumen/parsetja.py +++ b/tja2fumen/parsetja.py @@ -9,36 +9,6 @@ COMMAND = ['START', 'END', 'GOGOSTART', 'GOGOEND', 'BRANCHSTART', 'BRANCHEND', ' 'BPMCHANGE', 'DELAY', 'SECTION', 'N', 'E', 'M', 'LEVELHOLD', 'SCROLL', 'BMSCROLL', 'HBSCROLL', 'TTBREAK'] -def parseLine(line): - # Regex matches for various line types - match_comment = re.match(r"//.*", line) - match_header = re.match(r"^([A-Z]+):(.+)", line) - match_command = re.match(r"^#([A-Z]+)(?:\s+(.+))?", line) - match_data = re.match(r"^(([0-9]|A|B|C|F|G)*,?)$", line) - - if match_comment: - return {"type": 'comment', "value": line} - - elif match_header: - nameUpper = match_header.group(1).upper() - value = match_header.group(2) - if nameUpper in HEADER_GLOBAL: - return {"type": 'header', "scope": 'global', "name": nameUpper, "value": value.strip()} - elif nameUpper in HEADER_COURSE: - return {"type": 'header', "scope": 'course', "name": nameUpper, "value": value.strip()} - - elif match_command: - nameUpper = match_command.group(1).upper() - value = match_command.group(2) if match_command.group(2) else '' - if nameUpper in COMMAND: - return {"type": 'command', "name": nameUpper, "value": value.strip()} - - elif match_data: - return {"type": 'data', "data": match_data.group(1)} - - return {"type": 'unknown', "value": line} - - def getCourse(tjaHeaders, lines): headers = { "course": 'Oni', @@ -238,6 +208,36 @@ def getCourse(tjaHeaders, lines): return course, headers, measures +def parseLine(line): + # Regex matches for various line types + match_comment = re.match(r"//.*", line) + match_header = re.match(r"^([A-Z]+):(.+)", line) + match_command = re.match(r"^#([A-Z]+)(?:\s+(.+))?", line) + match_data = re.match(r"^(([0-9]|A|B|C|F|G)*,?)$", line) + + if match_comment: + return {"type": 'comment', "value": line} + + elif match_header: + nameUpper = match_header.group(1).upper() + value = match_header.group(2) + if nameUpper in HEADER_GLOBAL: + return {"type": 'header', "scope": 'global', "name": nameUpper, "value": value.strip()} + elif nameUpper in HEADER_COURSE: + return {"type": 'header', "scope": 'course', "name": nameUpper, "value": value.strip()} + + elif match_command: + nameUpper = match_command.group(1).upper() + value = match_command.group(2) if match_command.group(2) else '' + if nameUpper in COMMAND: + return {"type": 'command', "name": nameUpper, "value": value.strip()} + + elif match_data: + return {"type": 'data', "data": match_data.group(1)} + + return {"type": 'unknown', "value": line} + + def parseTJA(tja): # Split into lines lines = tja.read().splitlines()