# The only thing allowed after a list, is this next marker, or a newline.
ifline=="###next-name-looks-similar":
# "###next-name-looks-similar"
# Indicates the common prefix of the last list has a very
# similar name to the next entry, but isn't part of the
# list. So do not emit a warning about them looking very
# similar.
iflength!=0:
errors.append(f"ERROR: list around {name} is shorted than indicated by ###length")
common_prefix=""
else:
errors.append(f"ERROR: expected a newline after a list, but didn't find any around {name}. Did you add an entry to the list without increasing the length?")
skip=SkipType.NONE
ifline[0]=="#":
ifline.startswith("###length "):
# "###length <count>"
# Indicates the next few entries are part of a list. Only
# the first entry is possibly referenced, and the rest are
# indirectly.
iflength!=0:
errors.append(f"ERROR: list around {name} is shorted than indicated by ###length")
length=line.split("")[1].strip()
iflength.isnumeric():
length=int(length)
else:
length=LENGTH_NAME_LOOKUP[length]
skip=SkipType.LENGTH
elifline.startswith("###external "):
# "###external <count>"
# Indicates the next few entries are used outside the
# source and will not be referenced.
iflength!=0:
errors.append(f"ERROR: list around {name} is shorted than indicated by ###length")
# Indicates the next entry is part of the "zero is special"
# flag of settings. These entries are not referenced
# directly in the code.
iflength!=0:
errors.append(f"ERROR: list around {name} is shorted than indicated by ###length")
skip=SkipType.ZERO_IS_SPECIAL
continue
name=line.split(":")[0].strip()
strings_defined.append(name)
ifskip==SkipType.EXTERNAL:
strings_found.add(name)
skip=SkipType.LENGTH
ifskip==SkipType.LENGTH:
skip=SkipType.NONE
length-=1
common_prefix=name
elifskip==SkipType.ZERO_IS_SPECIAL:
strings_found.add(name)
eliflength>0:
strings_found.add(name)
length-=1
# Find the common prefix of these strings
foriinrange(len(common_prefix)):
ifcommon_prefix[0:i+1]!=name[0:i+1]:
common_prefix=common_prefix[0:i]
break
iflength==0:
skip=SkipType.EXPECT_NEWLINE
iflen(common_prefix)<6:
errors.append(f"ERROR: common prefix of block including {name} was reduced to {common_prefix}. This means the names in the list are not consistent.")
elifcommon_prefix:
ifname.startswith(common_prefix):
errors.append(f"ERROR: {name} looks a lot like block above with prefix {common_prefix}. This mostly means that the list length was too short. Use '###next-name-looks-similar' if it is not.")