Skip to content

Commit 3022b7d

Browse files
authored
Allow non-symbols in interop member position (#230)
1 parent f7e03ca commit 3022b7d

File tree

2 files changed

+19
-12
lines changed

2 files changed

+19
-12
lines changed

src/basilisp/reader.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -373,14 +373,17 @@ def _read_interop(ctx: ReaderContext, end_token: str) -> llist.List:
373373
if whitespace_chars.match(token):
374374
instance = _read_next_consuming_comment(ctx)
375375
member = _read_next_consuming_comment(ctx)
376-
if not isinstance(member, symbol.Symbol):
377-
raise SyntaxError(f"Expected Symbol; found {type(member)}")
378-
is_property = member.name.startswith('-')
379-
if is_property:
376+
377+
# There are cases (particularly with macros) where we may
378+
# not have a symbol in this spot. In those cases, we need
379+
# to expect the author used the correct form in the first
380+
# place.
381+
if isinstance(member, symbol.Symbol) and member.name.startswith('-'):
380382
seq.append(_INTEROP_PROP)
381383
member = symbol.symbol(member.name[1:])
382384
else:
383385
seq.append(_INTEROP_CALL)
386+
384387
seq.append(instance)
385388
seq.append(member)
386389
elif token == '-':

tests/basilisp/reader_test.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -560,14 +560,18 @@ def test_var():
560560

561561

562562
def test_interop_call():
563-
assert read_str_first('(. "STRING" lower)') == llist.l(
564-
sym.symbol('.'), "STRING", sym.symbol('lower'))
565-
assert read_str_first('(.lower "STRING")') == llist.l(
566-
sym.symbol('.'), "STRING", sym.symbol('lower'))
567-
assert read_str_first('(.split "www.google.com" ".")') == llist.l(
568-
sym.symbol('.'), "www.google.com", sym.symbol('split'), ".")
569-
assert read_str_first('(. "www.google.com" split ".")') == llist.l(
570-
sym.symbol('.'), "www.google.com", sym.symbol('split'), ".")
563+
assert llist.l(sym.symbol('.'), "STRING", sym.symbol('lower')) == read_str_first(
564+
'(. "STRING" lower)')
565+
assert llist.l(sym.symbol('.'), "STRING", sym.symbol('lower')) == read_str_first(
566+
'(.lower "STRING")')
567+
assert llist.l(sym.symbol('.'), "www.google.com", sym.symbol('split'), ".") == read_str_first(
568+
'(.split "www.google.com" ".")')
569+
assert llist.l(sym.symbol('.'), "www.google.com", sym.symbol('split'), ".") == read_str_first(
570+
'(. "www.google.com" split ".")')
571+
572+
assert llist.l(sym.symbol('.'), sym.symbol('obj'), llist.l(
573+
sym.symbol('unquote'), llist.l(sym.symbol('quote'), sym.symbol('method')))) == read_str_first(
574+
'(. obj (unquote (quote method)))')
571575

572576
with pytest.raises(reader.SyntaxError):
573577
read_str_first('(."non-symbol" symbol)')

0 commit comments

Comments
 (0)