hy/lex/parser.py: Add support for sub-object mangling

With this patch, every identifier is split up along dots, each part gets
separately mangled, and then it is all joined back together. This allows
for fun stuff like (.foo? (Foo)), and even more contrived examples.

Signed-off-by: Gergely Nagy <algernon@madhouse-project.org>
This commit is contained in:
Gergely Nagy 2014-01-13 22:36:53 +01:00 committed by Gergely Nagy
parent e49ad3b3d5
commit 8ef02a54b5
2 changed files with 9 additions and 1 deletions

View File

@ -254,7 +254,7 @@ def t_identifier(p):
return p
obj = mangle(obj)
obj = ".".join([mangle(part) for part in obj.split(".")])
return HySymbol(obj)

View File

@ -294,3 +294,11 @@ def test_lex_mangling_qmark():
assert entry == [HySymbol("?")]
entry = tokenize("im?foo")
assert entry == [HySymbol("im?foo")]
entry = tokenize(".foo?")
assert entry == [HySymbol(".is_foo")]
entry = tokenize("foo.bar?")
assert entry == [HySymbol("foo.is_bar")]
entry = tokenize("foo?.bar")
assert entry == [HySymbol("is_foo.bar")]
entry = tokenize(".foo?.bar.baz?")
assert entry == [HySymbol(".is_foo.bar.is_baz")]