File tree Expand file tree Collapse file tree 2 files changed +17
-0
lines changed Expand file tree Collapse file tree 2 files changed +17
-0
lines changed Original file line number Diff line number Diff line change 46
46
47
47
_APPLY = symbol .symbol ('apply' , ns = 'basilisp.core' )
48
48
_CONCAT = symbol .symbol ('concat' , ns = 'basilisp.core' )
49
+ _DEREF = symbol .symbol ('deref' , ns = 'basilisp.core' )
49
50
_HASH_MAP = symbol .symbol ('hash-map' , ns = 'basilisp.core' )
50
51
_HASH_SET = symbol .symbol ('hash-set' , ns = 'basilisp.core' )
51
52
_LIST = symbol .symbol ('list' , ns = 'basilisp.core' )
@@ -710,6 +711,14 @@ def _read_unquote(ctx: ReaderContext) -> LispForm:
710
711
return llist .l (_UNQUOTE , next_form )
711
712
712
713
714
+ def _read_deref (ctx : ReaderContext ) -> LispForm :
715
+ """Read a derefed form from the input stream."""
716
+ start = ctx .reader .advance ()
717
+ assert start == "@"
718
+ next_form = _read_next (ctx )
719
+ return llist .l (_DEREF , next_form )
720
+
721
+
713
722
def _read_regex (ctx : ReaderContext ) -> Pattern :
714
723
"""Read a regex reader macro from the input stream."""
715
724
s = _read_str (ctx )
@@ -826,6 +835,8 @@ def _read_next(ctx: ReaderContext) -> LispForm: # noqa: C901
826
835
return _read_syntax_quoted (ctx )
827
836
elif token == '~' :
828
837
return _read_unquote (ctx )
838
+ elif token == '@' :
839
+ return _read_deref (ctx )
829
840
elif token == '' :
830
841
return __EOF
831
842
else :
Original file line number Diff line number Diff line change @@ -667,6 +667,12 @@ def test_function_reader_macro():
667
667
read_str_first ("#app/ermagrd [1 2 3]" )
668
668
669
669
670
+ def test_deref ():
671
+ assert read_str_first ("@s" ) == llist .l (reader ._DEREF , sym .symbol ('s' ))
672
+ assert read_str_first ("@ns/s" ) == llist .l (reader ._DEREF , sym .symbol ('s' , ns = 'ns' ))
673
+ assert read_str_first ("@(atom {})" ) == llist .l (reader ._DEREF , llist .l (sym .symbol ('atom' ), lmap .Map .empty ()))
674
+
675
+
670
676
def test_regex_reader_literal ():
671
677
assert read_str_first ('#"hi"' ) == langutil .regex_from_str ("hi" )
672
678
assert read_str_first ('#"\s"' ) == langutil .regex_from_str (r"\s" )
You can’t perform that action at this time.
0 commit comments