MCPcopy Index your code
hub / github.com/clojure/clojure / parse

Method parse

src/jvm/clojure/lang/Compiler.java:3608–3659  ·  view source on GitHub ↗
(C context, IPersistentMap form)

Source from the content-addressed store, hash-verified

3606
3607
3608 static public Expr parse(C context, IPersistentMap form) {
3609 IPersistentVector keyvals = PersistentVector.EMPTY;
3610 boolean keysConstant = true;
3611 boolean valsConstant = true;
3612 boolean allConstantKeysUnique = true;
3613 IPersistentSet constantKeys = PersistentHashSet.EMPTY;
3614 for(ISeq s = RT.seq(form); s != null; s = s.next())
3615 {
3616 IMapEntry e = (IMapEntry) s.first();
3617 Expr k = analyze(context == C.EVAL ? context : C.EXPRESSION, e.key());
3618 Expr v = analyze(context == C.EVAL ? context : C.EXPRESSION, e.val());
3619 keyvals = (IPersistentVector) keyvals.cons(k);
3620 keyvals = (IPersistentVector) keyvals.cons(v);
3621 if(k instanceof LiteralExpr)
3622 {
3623 Object kval = k.eval();
3624 if (constantKeys.contains(kval))
3625 allConstantKeysUnique = false;
3626 else
3627 constantKeys = (IPersistentSet)constantKeys.cons(kval);
3628 }
3629 else
3630 keysConstant = false;
3631 if(!(v instanceof LiteralExpr))
3632 valsConstant = false;
3633 }
3634
3635 Expr ret = new MapExpr(keyvals);
3636 if(form instanceof IObj && ((IObj) form).meta() != null)
3637 return new MetaExpr(ret, MapExpr
3638 .parse(context == C.EVAL ? context : C.EXPRESSION, ((IObj) form).meta()));
3639 else if(keysConstant)
3640 {
3641 // TBD: Add more detail to exception thrown below.
3642 if(!allConstantKeysUnique)
3643 throw new IllegalArgumentException("Duplicate constant keys in map");
3644 if(valsConstant)
3645 {
3646 IPersistentMap m = PersistentArrayMap.EMPTY;
3647 for(int i=0;i<keyvals.length();i+= 2)
3648 {
3649 m = m.assoc(((LiteralExpr)keyvals.nth(i)).val(), ((LiteralExpr)keyvals.nth(i+1)).val());
3650 }
3651// System.err.println("Constant: " + m);
3652 return new ConstantExpr(m);
3653 }
3654 else
3655 return ret;
3656 }
3657 else
3658 return ret;
3659 }
3660}
3661
3662public static class SetExpr implements Expr{

Callers 5

parseMethod · 0.95
parseMethod · 0.95
parseMethod · 0.95
analyzeMethod · 0.95
parseMethod · 0.95

Calls 14

seqMethod · 0.95
nextMethod · 0.95
firstMethod · 0.95
keyMethod · 0.95
valMethod · 0.95
consMethod · 0.95
evalMethod · 0.95
containsMethod · 0.95
lengthMethod · 0.95
assocMethod · 0.95
analyzeMethod · 0.80
consMethod · 0.65

Tested by

no test coverage detected