Examples of ESeq


Examples of erjang.ESeq

    return testSeq();
  }

  @Override
  public ECons testNonEmptyList() {
    ESeq seq = testSeq();
    if (seq == null || seq.isNil())
      return null;
    return seq;
  }
View Full Code Here

Examples of erjang.ESeq

  public EString testString() {
    if (real_object instanceof String) {
      return EString.fromString((String) real_object);
    }

    ESeq seq;
    if ((seq = testSeq()) != null) {
      return seq.testString();
    }

    return null;
  }
View Full Code Here

Examples of erjang.ESeq

  public static Object[] convert_args(EProc self, Class<?>[] arg_types,
      ESeq arg_seq) throws IllegalArgumentException {
    Object[] out = new Object[arg_types.length];

    ESeq as_iter = arg_seq;
    for (int i = 0; i < arg_types.length; i++) {
      out[i] = JavaObject.unbox(self, arg_types[i], as_iter.head());
      as_iter = as_iter.tail();
    }

    return out;
  }
View Full Code Here

Examples of erjang.ESeq

      return null;
    }
   
    /** unbox to array type */
    if (type.isArray()) {
      ESeq seq;
      if ((seq = val.testSeq()) != null) {
        int length = seq.length();
        Class<?> componentType = type.getComponentType();
        Object arr = Array.newInstance(componentType, length);

        int index = 0;
        while (!seq.isNil()) {
          Object value = JavaObject.unbox(self, componentType, seq
              .head());
          Array.set(arr, index++, value);
          seq = seq.tail();
        }

        return arr;
      }

View Full Code Here

Examples of erjang.ESeq

  /** return a list of elements at given key */
  @Override
  protected ESeq lookup(EObject key) {
    IPersistentMap ipm = deref();
    IPersistentCollection set = (IPersistentCollection) ipm.valAt(key);
    ESeq res = ERT.NIL;
    if (set == null) return res;
    for(ISeq s = set.seq(); s != null; s = s.next())
    {
      res = res.cons((EObject) s.first());
    }   
    return res.reverse();
  }
View Full Code Here

Examples of erjang.ESeq

   
    EObject key = matcher.getKey(keypos1);
    if (key == null) {
     
      // oops, .. tablescan
      ESeq res = ERT.NIL;
     
      IPersistentMap map = deref();
      for (ISeq entseq = map.seq(); entseq != null; entseq = entseq.next()) {
        IMapEntry ent = (IMapEntry) entseq.first();

        if (ent == null) continue;
       
        Seqable coll = (Seqable)ent.getValue();
        res = matcher.match_vars(res, coll.seq());
      }
     
      return res.reverse();
    }
   
    IPersistentMap map = deref();
    IPersistentCollection coll = (IPersistentCollection) map.valAt(key);
    if (coll == null) return ERT.NIL;
View Full Code Here

Examples of erjang.ESeq

   
    EObject key = matcher.getKey(keypos1);
    if (key == null) {
     
      // oops, .. tablescan
      ESeq res = ERT.NIL;
     
      IPersistentMap map = deref();
      for (ISeq entseq = map.seq(); entseq != null; entseq = entseq.next()) {
        IMapEntry ent = (IMapEntry) entseq.first();

        if (ent == null) break;
       
        Seqable coll = (Seqable)ent.getValue();
        res = matcher.match_members(res, coll.seq());
      }
     
      return res.reverse();
    }
   
    IPersistentMap map = deref();
    IPersistentCollection coll = (IPersistentCollection) map.valAt(key);
    if (coll == null) return ERT.NIL;
View Full Code Here

Examples of erjang.ESeq

      } else {
        return val;
      }
    }

    ESeq o = opts.testSeq();
    Options o2;
   
    if (o.isNil()) {
      o2 = regex.options;
    } else {
      o2 = regex.options.re_init(o);
     
      if (o2 == null) {
        throw ERT.badarg(subj, re, opts);
      }
    }
   
    String subject = regex.options.decode(subj);
    if (subject == null) {
      throw ERT.badarg(subj, re, opts);
    }
   
    if (o2.offset > subject.length() || o2.offset < 0) {
      throw ERT.badarg(subj, re, opts);
    }
   
    Matcher matcher = regex.patt.matcher(subject.substring(o2.offset ));
       
    if (o2.global) {
     
      ESeq result = ERT.NIL;
     
      while (matcher.find()) {
        MatchResult mr = matcher.toMatchResult();
     
        ESeq list;
        if (o2.capture_spec == am_all) {
          ESeq l = ERT.NIL;
          for (int i = mr.groupCount(); i >= 0; i--) {
            l = l.cons( capture (subject, mr, i, o2) );
          }
         
          result = result.cons(l);
        } else if ((list = o2.capture_spec.testSeq()) != null) {
          ESeq l = ERT.NIL;
          while (!list.isNil()) {
            EObject group = list.head();
            ESmall num;
            EAtom nam;
            EString nam2;
            if ((num=group.testSmall()) != null)
            {
              l = l.cons( capture (subject, mr, num.value, o2 ));
            } else if ((nam=group.testAtom()) != null) {
              Integer groupNo = o2.named_groups.get(nam.getName());
              if (groupNo != null) {
                l = l.cons( capture (subject, mr, groupNo.intValue(), o2 ));
              }
            } else if ((nam2=group.testString()) != null) {
              Integer groupNo = o2.named_groups.get(nam2.stringValue());
              if (groupNo != null) {
                l = l.cons( capture (subject, mr, groupNo.intValue(), o2 ));
              }
            } else {
              throw new NotImplemented("named capture groups");
            }
            list = list.tail();
          }
          result = result.cons(l);

        } else {
          throw new NotImplemented("global and not all");
        }
      }
     
      if (result == ERT.NIL) {
        return am_nomatch;
      } else {
         return new ETuple2(am_match, result.reverse());
      }
     
    } else {
     
      if (matcher.find()) {
       
        if (o2.capture_spec  == am_none) {
          return am_match;
        }
       
        MatchResult mr = matcher.toMatchResult();
     
        int max = mr.groupCount();
        while( mr.start(max) == -1)
          max -= 1;
       
        ESeq il;
        if (o2.capture_spec == am_all) {
          ESeq l = ERT.NIL;
          for (int i = max; i >= 0; i--) {
            l = l.cons( capture (subject, mr, i, o2) );
          }
          return new ETuple2(am_match, l);
         
        } else if (o2.capture_spec == am_all_but_first) {
          ESeq l = ERT.NIL;
          for (int i = max; i > 0; i--) {
            l = l.cons( capture (subject, mr, i, o2) );
          }
          return new ETuple2(am_match, l);
         
        } else if (o2.capture_spec == am_first) {
          EObject l = capture (subject, mr, 0, o2);
          return new ETuple2(am_match, l);
         
        } else if ((il = o2.capture_spec.testSeq()) != null) {
         
          ESeq out = ERT.NIL;
         
           for (; !il.isNil(); il = il.tail()) {
             EObject what = il.head();
            ESmall idx = what.testSmall();
             EAtom nam;
            if (idx != null && mr.start(idx.value) != -1) {
               EObject val = capture (subject, mr, idx.value, o2);
               out = out.cons(val);
             } else if ((nam=what.testAtom())!=null) {
               Integer idx2 = o2.named_groups.get(nam.getName());
               if (idx2 != null) {
                   EObject val = capture (subject, mr, idx2, o2);
                   out = out.cons(val);
               } else {
                 // badarg?
               }
             } else {
               out = out.cons(nocapture(o2));
             }
           }
          
           return new ETuple2(am_match, out.reverse());
         
        } else {
          throw ERT.badarg(subj, re, opts);
        }
       
View Full Code Here

Examples of erjang.ESeq

    int delete_count = in_tx(new WithMap<Integer>() {

      @Override
      protected Integer run(IPersistentMap map) {
        ESeq vals = ERT.NIL;
        int initial_count = sizeRef.get();
       
        EObject key = matcher.getTupleKey(keypos1);
       
        if (key == null) {
          vals = matcher.matching_values_bag(vals, (Map<EObject, IPersistentCollection>) map);
        } else {
          IPersistentCollection coll = (IPersistentCollection) map.valAt(key);
          if (coll != null) {
            vals = matcher.matching_values_coll(vals, coll.seq());
          }
        }
       
        int count = 0;
        for (; !vals.isNil(); vals = vals.tail()) {
          try {
            ETuple val = (ETuple) vals.head();
            key = val.elm(keypos1);
            IPersistentCollection coll = (IPersistentCollection) map.valAt(key);

            if (coll instanceof IPersistentSet) {
              IPersistentSet set = (IPersistentSet) coll;
View Full Code Here

Examples of erjang.ESeq

      return new ETuple2(ERT.am_ok,
          obj1
      );
    }
   
    ESeq opts = obj2.testSeq();

    Options o = new Options();

    String pattern;
    ETuple4 tup = ETuple4.cast(obj1);
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.