Skip to content

Cannot parse nested tagged elements #8

@bhavyakukkar

Description

@bhavyakukkar

As far as I understand, EDNs can be nested tags i.e.

#pow2 #pow3 2

which is expected to be parsed as:

Tagged("pow2", Tagged("pow3", Int(2)))

From the spec:

Upon encountering a tag, the reader will first read the next element (which may itself be or comprise other tagged elements)

I also verified this with the python implementation where the following assertion succeeds:

expand python code
import edn_format
edn_format.add_tag("pow2", lambda x: x*x)
edn_format.add_tag("pow3", lambda x: x*x*x)
assert(edn_format.loads("#pow2 #pow3 2") == 64)

However, at present this library fails to parse the same example with code UnexpectedEOF:

expand rust code
use clojure_reader::edn::{self, Edn};

fn main() {
  assert_eq!(
    edn::read_string("#pow2 #pow3 2").unwrap(),
    Edn::Tagged("pow2", Box::new(Edn::Tagged("pow3", Box::new(Edn::Int(2)))))
  );
}
thread 'main' panicked at examples/foo.rs:5:39:
called `Result::unwrap()` on an `Err` value: EdnError { code: UnexpectedEOF, line: Some(1), column: Some(14), ptr: Some(13) }
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions