File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -433,6 +433,16 @@ pub fn try_read_pattern(input: &str) -> IResult<&str, Value> {
433433 let regex = regex:: Regex :: new ( regex_string. as_str ( ) ) . to_value ( ) ;
434434 Ok ( ( rest_input, regex) )
435435}
436+ // Reads the #
437+ pub fn try_read_var ( input : & str ) -> IResult < & str , Value > {
438+ named ! ( var_parser<& str , & str >, preceded!( consume_clojure_whitespaces_parser, tag!( "#'" ) ) ) ;
439+
440+ let ( rest_input, _) = var_parser ( input) ?;
441+ let ( rest_input, val) = try_read ( rest_input) ?;
442+ // #'x just expands to (var x), just like 'x is just a shorthand for (quote x)
443+ // So here we return (var val)
444+ Ok ( ( rest_input, list_val ! ( sym!( "var" ) val) ) )
445+ }
436446
437447// @TODO Perhaps generalize this, or even generalize it as a reader macro
438448/// Tries to parse &str into Value::PersistentListMap, or some other Value::..Map
@@ -586,6 +596,7 @@ pub fn try_read(input: &str) -> IResult<&str, Value> {
586596 try_read_list,
587597 try_read_vector,
588598 try_read_pattern,
599+ try_read_var,
589600 ) ) ,
590601 ) ( input)
591602}
You can’t perform that action at this time.
0 commit comments