parsetja.py
: Move parseLine
function down
My main focus will be rewriting the `getCourse` function, so I want it to be at the top.
This commit is contained in:
parent
355d3a10f9
commit
35ba7bfeba
@ -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()
|
||||
|
Loading…
Reference in New Issue
Block a user