Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issue with syntax quoting reader var macro #893

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading