Skip to content

Commit

Permalink
Fix issue with syntax quoting reader var macro (#893)
Browse files Browse the repository at this point in the history
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 <ikappaki@users.noreply.github.com>
  • Loading branch information
ikappaki and ikappaki authored Mar 7, 2024
1 parent c835374 commit 3ab59a2
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* Fix an issue where `concat` on maps was iterating over the keys instead of the key/value pairs (#871)
* Fix a bug where the compiler would throw an exception partially macroexpanding forms with `recur` forms provided as arguments (#856)
* Fix a bug where the original `(var ...)` form is not retained during analysis, causing it to be lost in calls to `macroexpand` (#888)
* Fix issue with the reader var macro failing in syntax quote when unquoting a symbol, e.g. `(#'~symbol) (#889)

## [v0.1.0b1]
### Added
Expand Down
6 changes: 5 additions & 1 deletion src/basilisp/lang/reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -1527,7 +1527,11 @@ def _read_reader_macro(ctx: ReaderContext) -> LispReaderForm: # noqa: MC0001
return _read_namespaced_map(ctx)
elif token == "'":
ctx.reader.advance()
s = _read_sym(ctx)
token_next = ctx.reader.peek()
if token_next == "~":
s = _read_unquote(ctx)
else:
s = _read_sym(ctx)
return llist.l(_VAR, s)
elif token == '"':
return _read_regex(ctx)
Expand Down
24 changes: 24 additions & 0 deletions tests/basilisp/reader_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -970,6 +970,30 @@ def complex_resolver(s: sym.Symbol) -> sym.Symbol:
),
) == read_str_first("`(~'my-symbol)"), "Do not resolve unquoted quoted syms"

assert llist.l(
reader._SEQ,
llist.l(
reader._CONCAT,
llist.l(
reader._LIST,
llist.l(
reader._SEQ,
llist.l(
reader._CONCAT,
llist.l(
reader._LIST,
llist.l(sym.symbol("quote"), sym.symbol("var")),
),
llist.l(
reader._LIST,
llist.l(sym.symbol("quote"), sym.symbol("a-symbol")),
),
),
),
),
),
) == read_str_first("`(#'~'a-symbol)"), "Reader var macro works with unquote"

assert llist.l(sym.symbol("quote"), sym.symbol("&")) == read_str_first(
"`&"
), "do not resolve the not namespaced ampersand"
Expand Down

0 comments on commit 3ab59a2

Please sign in to comment.