hy/lex/parser.py: Move most of the identifier mangling into a def

As a refactoring step, move the identifier mangling done in t_identifier
into a separate def.

Signed-off-by: Gergely Nagy <algernon@madhouse-project.org>
This commit is contained in:
Gergely Nagy 2014-01-13 22:19:25 +01:00 committed by Gergely Nagy
parent d34c22eeac
commit ceb615d010

View File

@ -242,14 +242,19 @@ def t_identifier(p):
if obj.startswith("&"):
return HyLambdaListKeyword(obj)
if obj.startswith("*") and obj.endswith("*") and obj not in ("*", "**"):
obj = obj[1:-1].upper()
def mangle(p):
if p.startswith("*") and p.endswith("*") and p not in ("*", "**"):
p = p[1:-1].upper()
if "-" in obj and obj != "-":
obj = obj.replace("-", "_")
if "-" in p and p != "-":
p = p.replace("-", "_")
if obj.endswith("?") and obj != "?":
obj = "is_%s" % (obj[:-1])
if p.endswith("?") and p != "?":
p = "is_%s" % (p[:-1])
return p
obj = mangle(obj)
return HySymbol(obj)