Skip to content

Commit 3ab59a2

Browse files
authored
Fix issue with syntax quoting reader var macro (#893)
Hi, could you please consider fix for the issue with using the reader var macro in syntax quotes. It fixes #889 I've also added a test. Thanks Co-authored-by: ikappaki <[email protected]>
1 parent c835374 commit 3ab59a2

File tree

3 files changed

+30
-1
lines changed

3 files changed

+30
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
3131
* Fix an issue where `concat` on maps was iterating over the keys instead of the key/value pairs (#871)
3232
* Fix a bug where the compiler would throw an exception partially macroexpanding forms with `recur` forms provided as arguments (#856)
3333
* Fix a bug where the original `(var ...)` form is not retained during analysis, causing it to be lost in calls to `macroexpand` (#888)
34+
* Fix issue with the reader var macro failing in syntax quote when unquoting a symbol, e.g. `(#'~symbol) (#889)
3435

3536
## [v0.1.0b1]
3637
### Added

src/basilisp/lang/reader.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1527,7 +1527,11 @@ def _read_reader_macro(ctx: ReaderContext) -> LispReaderForm: # noqa: MC0001
15271527
return _read_namespaced_map(ctx)
15281528
elif token == "'":
15291529
ctx.reader.advance()
1530-
s = _read_sym(ctx)
1530+
token_next = ctx.reader.peek()
1531+
if token_next == "~":
1532+
s = _read_unquote(ctx)
1533+
else:
1534+
s = _read_sym(ctx)
15311535
return llist.l(_VAR, s)
15321536
elif token == '"':
15331537
return _read_regex(ctx)

tests/basilisp/reader_test.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -970,6 +970,30 @@ def complex_resolver(s: sym.Symbol) -> sym.Symbol:
970970
),
971971
) == read_str_first("`(~'my-symbol)"), "Do not resolve unquoted quoted syms"
972972

973+
assert llist.l(
974+
reader._SEQ,
975+
llist.l(
976+
reader._CONCAT,
977+
llist.l(
978+
reader._LIST,
979+
llist.l(
980+
reader._SEQ,
981+
llist.l(
982+
reader._CONCAT,
983+
llist.l(
984+
reader._LIST,
985+
llist.l(sym.symbol("quote"), sym.symbol("var")),
986+
),
987+
llist.l(
988+
reader._LIST,
989+
llist.l(sym.symbol("quote"), sym.symbol("a-symbol")),
990+
),
991+
),
992+
),
993+
),
994+
),
995+
) == read_str_first("`(#'~'a-symbol)"), "Reader var macro works with unquote"
996+
973997
assert llist.l(sym.symbol("quote"), sym.symbol("&")) == read_str_first(
974998
"`&"
975999
), "do not resolve the not namespaced ampersand"

0 commit comments

Comments
 (0)