Skip to content

Commit

Permalink
refactored reader meta data parser
Browse files Browse the repository at this point in the history
  • Loading branch information
jlangch committed Sep 10, 2023
1 parent 3c3adba commit b93fad0
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
13 changes: 11 additions & 2 deletions src/main/java/com/github/jlangch/venice/impl/reader/Reader.java
Original file line number Diff line number Diff line change
Expand Up @@ -418,10 +418,19 @@ private static VncVal parseMetaData(final Reader rdr) {
rdr.next();
final Token metaToken = rdr.peek();
VncVal meta = read_form(rdr);

if (Types.isVncKeyword(meta)) {
// allow ^:private is equivalent to ^{:private true}
meta = VncHashMap.of(meta, VncBoolean.True);
final String qName = ((VncKeyword)meta).getQualifiedName();
if (qName.equals("private") || qName.equals("dynamic")) {
// allow ^:private is equivalent to ^{:private true}
// allow ^:dynamic is equivalent to ^{:dynamic true}
meta = VncHashMap.of(meta, VncBoolean.True);
}
else {
meta = VncHashMap.of(MetaUtil.TYPE, meta);
}
}

if (Types.isVncMap(meta)) {
final Token symToken = rdr.peek();
return read_form(rdr).withMeta(MetaUtil.mergeMeta(meta, MetaUtil.toMeta(symToken)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,13 @@ public void testMeta() {
assertEquals(100L, new Venice().eval("(do (def ^{:a 200} x 100) x)"));
assertEquals(200L, new Venice().eval("(do (def ^{:a 200} x 100) (:a (meta x)))"));
assertEquals("(xx yy)", new Venice().eval("(do (def ^{:a '(\"xx\" \"yy\")} x 100) (str (:a (meta x))))"));

assertEquals(true, new Venice().eval("(do (def ^:private x 100) (:private (meta x))))"));
}
assertEquals(true, new Venice().eval("(do (ns test) (def ^:private x 100) (:private (meta x))))"));

assertEquals(true, new Venice().eval("(do (def ^:dynamic x 100) (:dynamic (meta x))))"));
assertEquals(true, new Venice().eval("(do (ns test) (def ^:dynamic x 100) (:dynamic (meta x))))"));
}

@Test
public void testAtomInteger() {
Expand Down

0 comments on commit b93fad0

Please sign in to comment.