Examples of ETuple2


Examples of erjang.ETuple2

       * @return
       */
      private Arg decode_value(EObject src) {

        if (src instanceof ETuple2) {
          ETuple2 tup = (ETuple2) src;
          if (tup.elem1 == ATOM_ATOM) {
            return new Arg(tup.elem2, EATOM_TYPE);
          } else if (tup.elem1 == LITERAL_ATOM) {
            return new Arg(tup.elem2);
          } else if (tup.elem1 == INTEGER_ATOM) {
View Full Code Here

Examples of erjang.ETuple2

  /** fake that the crypto_server launched */
 
  @BIF
  public static EObject init(EObject arg) {
    return new ETuple2(ERT.am_ok, ERT.NIL);
  }
View Full Code Here

Examples of erjang.ETuple2

      private Arg decode_out_arg(int insn_idx, EObject src) {
        TypeMap current = this.map[insn_idx];

        if (src instanceof ETuple2) {
          ETuple2 tup = (ETuple2) src;
          if (tup.elem1 == X_ATOM) {
            int xreg = tup.elem2.asInt();
            return new Arg(Arg.Kind.X, xreg);
          } else if (tup.elem1 == Y_ATOM) {
            int yreg = tup.elem2.asInt();
View Full Code Here

Examples of erjang.ETuple2

      @Deprecated
      private Type getType(TypeMap current, EObject src) {

        if (src instanceof ETuple2) {
          ETuple2 tup = (ETuple2) src;
          if (tup.elem1 == X_ATOM) {
            return current.getx(tup.elem2.asInt());
          } else if (tup.elem1 == Y_ATOM) {
            return current.gety(tup.elem2.asInt());
          } else if (tup.elem1 == FR_ATOM) {
View Full Code Here

Examples of erjang.ETuple2

            if (self != owner)
              throw new ErlangError(ERT.am_badfun, args);

            Object key = JavaObject.unbox(self, Object.class, args[0]);
            if (r.containsKey(key)) {
              return new ETuple2(args[0], JavaObject.box(self, r
                  .get(key)));
            } else {
              return am_none;
            }
          }
View Full Code Here

Examples of erjang.ETuple2

    if (re instanceof ECompiledRE) {
      regex = (ECompiledRE) re;

    } else {
      ETuple2 res = compile(re, opts);
      EObject val = res.elem2;
      if (res.elem1 == ERT.am_ok && ( val instanceof ECompiledRE)) {
        regex = (ECompiledRE) val;
      } 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.ETuple2

      if (INDEX_COMPATIBLE && opts.unicode) {
        try {
          int istart = subject.substring(0, start).getBytes("UTF8").length;
          int ilen = subject.substring(start, end).getBytes("UTF8").length;

          return new ETuple2(ERT.box(istart), ERT.box(ilen));
        } catch (UnsupportedEncodingException e) {
          throw new InternalError();
        }
      }
     
      return new ETuple2(ERT.box(start), ERT.box(end-start));
     
    } else if (opts.capture_type == am_list) {
      String sub = subject.substring(start, end);
      EBigString ebs = EBigString.fromString(sub);
      return erjang.m.unicode.Native.characters_to_list(ebs,
View Full Code Here

Examples of erjang.ETuple2

 
  @BIF
  static public ETuple2 compile(EObject obj1, EObject obj2) {

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

    Options o = new Options();

    String pattern;
    ETuple4 tup = ETuple4.cast(obj1);
    if (tup != null && tup.elem1 == ECompiledRE.am_re_pattern) {
      EBinary b = tup.elem4.testBinary();
      byte[] byteArray = b.getByteArray();
      if (b != null && b.byteAt(0) == '/') {
       
        byte[] raw = byteArray;
        int end = raw.length - 1;
        for (int i = b.byteSize()-1; i > 0; i--) {
          if (b.byteAt(i*8) == '/') {
            end = i;
            break;
          }
        } 
         
        pattern = new String(raw, 1, end-1, IO.UTF8);
 
        o.init( ECompiledRE.decode_options(raw, end+1) );
       
        if (!o.init(opts)) {
          throw ERT.badarg(obj1, obj2);
        }

      } else if ((pattern = is_special_pattern(byteArray, o)) != null) {
        // ok //
       
      } else {
        System.out.println("byte data[] = { ");
        for (int i = 0; i < byteArray.length; i++) {
          System.out.print(", "+byteArray[i]);
        }
        System.out.println(" } ");
        throw ERT.badarg(obj1, obj2);
      }
    } else {
      if (!o.init(opts)) {
        throw ERT.badarg(obj1, obj2);
      }
      pattern = o.decode(obj1);
    }
   
    if (pattern == null) {
      throw ERT.badarg(obj1, obj2);
    }
   
    String stripped_pattern = o.process_erl2java(pattern);

    try {
      Pattern c = Pattern.compile(stripped_pattern, o.flags);
      return new ETuple2(ERT.am_ok,
          new ECompiledRE(o, c, pattern)
      );

    } catch (PatternSyntaxException e) {
      return new ETuple2(ERT.am_error, new ETuple2(EString.fromString(e
          .getDescription()+" in /"+stripped_pattern+"/"), ERT.box(e.getIndex())));
    }
  }
View Full Code Here

Examples of erjang.ETuple2

     
     
      if (vals == ERT.NIL) {
        return Native.am_$end_of_table;
      } else if (!seq_has_more(map_seq) && !seq_has_more(coll_seq)) {
        return new ETuple2(vals, Native.am_$end_of_table);
      } else {
        return new ETuple2(vals, new EBagCont(matcher, map_seq, coll_seq, limit));
      }
    }
View Full Code Here

Examples of erjang.ETuple2

    //System.err.println("SETNODE("+node_arg+", "+cid_arg+", "+type_arg+")");
   
    EAtom node;
    int creation = 0;
   
    ETuple2 tup;
    if ((tup=ETuple2.cast(node_arg)) != null) {
      node = tup.elem1.testAtom();
      ESmall sm = tup.elem2.testSmall();
     
      if (node == null || sm==null || !is_node_name_atom(node))
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.