parsetja.py
: Condense parseLine
function
This commit is contained in:
parent
f77f31dcd0
commit
355d3a10f9
@ -10,68 +10,33 @@ COMMAND = ['START', 'END', 'GOGOSTART', 'GOGOEND', 'BRANCHSTART', 'BRANCHEND', '
|
|||||||
|
|
||||||
|
|
||||||
def parseLine(line):
|
def parseLine(line):
|
||||||
|
# Regex matches for various line types
|
||||||
match_comment = re.match(r"//.*", line)
|
match_comment = re.match(r"//.*", line)
|
||||||
match_header = re.match(r"^([A-Z]+):(.+)", line)
|
match_header = re.match(r"^([A-Z]+):(.+)", line)
|
||||||
match_command = re.match(r"^#([A-Z]+)(?:\s+(.+))?", line)
|
match_command = re.match(r"^#([A-Z]+)(?:\s+(.+))?", line)
|
||||||
match_data = re.match(r"^(([0-9]|A|B|C|F|G)*,?)$", line)
|
match_data = re.match(r"^(([0-9]|A|B|C|F|G)*,?)$", line)
|
||||||
|
|
||||||
# comment
|
|
||||||
if match_comment:
|
if match_comment:
|
||||||
return {
|
return {"type": 'comment', "value": line}
|
||||||
"type": 'comment',
|
|
||||||
"value": line
|
|
||||||
} # js: line = line.substr(0, match.index).strip()
|
|
||||||
|
|
||||||
# header
|
|
||||||
elif match_header:
|
elif match_header:
|
||||||
nameUpper = match_header.group(1).upper()
|
nameUpper = match_header.group(1).upper()
|
||||||
value = match_header.group(2)
|
value = match_header.group(2)
|
||||||
|
|
||||||
if nameUpper in HEADER_GLOBAL:
|
if nameUpper in HEADER_GLOBAL:
|
||||||
return {
|
return {"type": 'header', "scope": 'global', "name": nameUpper, "value": value.strip()}
|
||||||
"type": 'header',
|
|
||||||
"scope": 'global',
|
|
||||||
"name": nameUpper,
|
|
||||||
"value": value.strip(),
|
|
||||||
}
|
|
||||||
elif nameUpper in HEADER_COURSE:
|
elif nameUpper in HEADER_COURSE:
|
||||||
return {
|
return {"type": 'header', "scope": 'course', "name": nameUpper, "value": value.strip()}
|
||||||
"type": 'header',
|
|
||||||
"scope": 'course',
|
|
||||||
"name": nameUpper,
|
|
||||||
"value": value.strip(),
|
|
||||||
}
|
|
||||||
else:
|
|
||||||
breakpoint()
|
|
||||||
|
|
||||||
# command
|
|
||||||
elif match_command:
|
elif match_command:
|
||||||
nameUpper = match_command.group(1).upper()
|
nameUpper = match_command.group(1).upper()
|
||||||
value = match_command.group(2)
|
value = match_command.group(2) if match_command.group(2) else ''
|
||||||
if not value:
|
|
||||||
value = ''
|
|
||||||
|
|
||||||
if nameUpper in COMMAND:
|
if nameUpper in COMMAND:
|
||||||
return {
|
return {"type": 'command', "name": nameUpper, "value": value.strip()}
|
||||||
"type": 'command',
|
|
||||||
"name": nameUpper,
|
|
||||||
"value": value.strip(),
|
|
||||||
}
|
|
||||||
|
|
||||||
# data
|
|
||||||
elif match_data:
|
elif match_data:
|
||||||
data = match_data.group(1)
|
return {"type": 'data', "data": match_data.group(1)}
|
||||||
|
|
||||||
return {
|
return {"type": 'unknown', "value": line}
|
||||||
"type": 'data',
|
|
||||||
"data": data,
|
|
||||||
}
|
|
||||||
|
|
||||||
else:
|
|
||||||
return {
|
|
||||||
"type": 'unknown',
|
|
||||||
"value": line,
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
def getCourse(tjaHeaders, lines):
|
def getCourse(tjaHeaders, lines):
|
||||||
|
Loading…
Reference in New Issue
Block a user