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:
parent
e49ad3b3d5
commit
8ef02a54b5
@ -254,7 +254,7 @@ def t_identifier(p):
|
|||||||
|
|
||||||
return p
|
return p
|
||||||
|
|
||||||
obj = mangle(obj)
|
obj = ".".join([mangle(part) for part in obj.split(".")])
|
||||||
|
|
||||||
return HySymbol(obj)
|
return HySymbol(obj)
|
||||||
|
|
||||||
|
@ -294,3 +294,11 @@ def test_lex_mangling_qmark():
|
|||||||
assert entry == [HySymbol("?")]
|
assert entry == [HySymbol("?")]
|
||||||
entry = tokenize("im?foo")
|
entry = tokenize("im?foo")
|
||||||
assert entry == [HySymbol("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")]
|
||||||
|
Loading…
Reference in New Issue
Block a user