Package org.eclipse.imp.pdb.facts

Examples of org.eclipse.imp.pdb.facts.INode


          IConstructor attributeConstructor = (IConstructor)attributeValue;

          if (attributeConstructor.getName().equals("tag")) {
       
            for (IValue childValue : attributeConstructor.getChildren()) {
              INode childNode = (INode)childValue;

              // non-empty breakable tag?
              if (childNode.getName().equals("breakable")
                  && childNode.getChildren().iterator().hasNext()) {

                String c = ((IString)childNode.get(0)).getValue();
                String s = c.substring(1,c.length()-1);
                result = s.split(",");
              }
            }
          }
View Full Code Here


    return null;
  }

  @SuppressWarnings("unused")
  private IValue buildTerm(IMap t, Type type) {
    INode result;
    IValue key = t.get(nameKey);
    if (debug && key != null)
      System.err.println("builterm key=" + key);
    if (key == null) {
      if (type.isMap() || t.getType().isMap())
        return _buildTerm(t, type);
      else
        return t;
    }
    /* Abstract Data Type */
    final String funname = ((IString) key).getValue();
    if (debug && key != null)
      System.err.println("builterm funname=" + funname);
    IList rs = vf.list(tf.valueType());
    final Iterator<IValue> args = ((IList) t.get(argKey)).iterator();
    while (args.hasNext()) {
      IValue arg = (IValue) args.next();
      arg = buildTerm(arg, type);
      rs = rs.append(arg);
    }
    IValue[] a = new IValue[rs.length()];
    Type[] b = new Type[rs.length()];
    {
      int i = 0;
      for (IValue c : rs) {
        a[i] = c;
        b[i] = c.getType();
        i++;
      }
    }
    HashMap<String, IValue> map = new HashMap<String, IValue>();
    IMap annoMap = (IMap) t.get(annoKey);
    if (annoMap != null) {
      Iterator<IValue> iterator = annoMap.iterator();
      while (iterator.hasNext()) {
        IValue k = iterator.next();
        String ky = ((IString) k).getValue();
        IValue v = annoMap.get(k);
        map.put(ky, v);
      }
    }
   
    // keyword parameters
   
    HashMap<String, IValue> kwmap = new HashMap<String, IValue>();
   
    Iterator<IValue> iterator = t.iterator();
    while (iterator.hasNext()) {
      IValue k = iterator.next();
      String ky = ((IString) k).getValue();

      if(!(k.equals(nameKey) || k.equals(argKey) || k.equals(annoKey))){
        IValue v = t.get(k);
        kwmap.put(ky, v);
      }
    }
   
    if (funname.equals("#rat")) {
      int dn = ((IInteger) a[0]).intValue(), nm = ((IInteger) a[1])
          .intValue();
      return vf.rational(dn, nm);
    }
    if (funname.equals("#tuple")) {
      return vf.tuple(a);
    }
    if (funname.equals("#loc")) {
      try {
        final URI uri = URIUtil.createFromEncoded(((IString) a[0]).getValue());
        return vf.sourceLocation(uri);
      } catch (URISyntaxException e) {
        e.printStackTrace();
      }
    }
    if (funname.equals("#set")) {
      return a.length == 0 ? vf.set(tf.valueType()) : vf.set(a);
    }
    if (funname.equals("#map")) {
      IMapWriter w = vf.mapWriter();
      for (int i = 0; i < a.length; i++) {
        w.put(((ITuple) a[i]).get(0), ((ITuple) a[i]).get(1));
      }
      return w.done();
    }
    if (funname.equals("#datetime"))
      return dateTime(((IString) a[0]).getValue());

    Type computed = tf.tupleType(b);
    if (debug)
      System.err.println("lookupFirstConstructor:" + funname + " "
          + computed + " " + type);
    Type found = null;
    if (type.isAbstractData())
      found = ts.lookupConstructor(type, funname, computed);
    if (found == null)
      found = ts.lookupFirstConstructor(funname, computed);
    ArrayList<IValue[]> r = new ArrayList<IValue[]>();
    ArrayList<Type> f = new ArrayList<Type>();
    if (found == null) {
      Set<Type> nodes = ts.lookupConstructors(funname);
      if (debug)
        System.err.println("Number of nodes found:" + nodes.size());
      Iterator<Type> it = nodes.iterator();
      while (it.hasNext()) {
        found = it.next();
        IValue[] v = matched(found, a);
        if (v == null)
          break;
        r.add(v);
        f.add(found);
      }
      if (r.size() != 1)
        found = null;
      else {
        found = f.get(0);
        a = r.get(0);
      }
    }
    if (debug)
      System.err.println("JSonReader found:" + r.size());
    if (debug)
      System.err.println("node2=" + found);
    if (found == null) {
      result = vf.node(funname, a);
    } else {
      if (found.isAliased())
        found = found.getAliased();
      result = vf.constructor(found, a);
      if (debug)
        System.err.println("JSonReader result:" + result);
    }
    if (annoMap != null)
      result = result.asAnnotatable().setAnnotations(map);
    if(kwmap.size() > 0){
      result = result.asWithKeywordParameters().setParameters(kwmap);
    }
    return result;
  }
View Full Code Here

              .__getEval().getStackTrace());
        }
      } else if (rec.getType().isNode()) {

        try {
          INode node = (INode) rec.getValue();

          IValue repl = __eval.__getValue().getValue();
          if(!repl.getType().isList()){
            throw new UnexpectedType(rec.getType(), repl.getType(), __eval.__getEval().getCurrentAST());
          }

          __eval.__setValue(__eval.newResult(node, __eval.__getValue()));
          node = node.replace(firstIndex, secondIndex, endIndex, (IList) repl);

          result = org.rascalmpl.interpreter.result.ResultFactory
              .makeResult(rec.hasInferredType() ? rec.getType()
                  .lub(node.getType()) : rec.getType(), node,
                  __eval.__getEval());
        } catch (IndexOutOfBoundsException e) { // include last in message
          throw org.rascalmpl.interpreter.utils.RuntimeExceptionFactory
          .indexOutOfBounds((IInteger) first.getValue(),
              __eval.__getEval().getCurrentAST(), __eval
View Full Code Here

  public Void visitNode(INode value) throws IOException {
    // ["node", ["name", arity, [...]] ]
    out.beginArray();
    out.value("node");
    out.beginArray();
    INode n = (INode) value;
    out.value(n.getName());
    out.value(n.arity());
    out.beginArray();
    for (IValue v : n.getChildren()) {
      write(out, v);
    }
    out.endArray();
   
//    if (!value.asAnnotatable().hasAnnotations()) {
View Full Code Here

    @Override
    public void handleEndTag(Tag t, int pos) {
      java.util.List<IValue> kids = stack.pop();
      IValue[] a = new IValue[kids.size()];
      kids.toArray(a);
      INode node = factory.node(t.toString(), factory.list(a));
      node = node.asAnnotatable().setAnnotations(attributes.pop());
      stack.peek().add(node);
    }
View Full Code Here

      stack.peek().add(node);
    }
   
    @Override
    public void handleSimpleTag(Tag t, MutableAttributeSet a, int pos) {
      INode node = factory.node(t.toString());
      stack.peek().add(node);
    }
View Full Code Here

        }
       
      } else if (rec.getType().isNode()) {

        try {
          INode node = (INode) rec.getValue();

          IValue repl = __eval.__getValue().getValue();
          if(!repl.getType().isList()){
            throw new UnexpectedType(rec.getType(), repl.getType(), __eval.__getEval().getCurrentAST());
          }

          __eval.__setValue(__eval.newResult(node, __eval.__getValue()));
          node = node.replace(firstIndex, secondIndex, endIndex, (IList) repl);

          result = org.rascalmpl.interpreter.result.ResultFactory
              .makeResult(rec.hasInferredType() ? rec.getType()
                  .lub(node.getType()) : rec.getType(), node,
                  __eval.__getEval());
        } catch (IndexOutOfBoundsException e) { // include last in message
          throw org.rascalmpl.interpreter.utils.RuntimeExceptionFactory
          .indexOutOfBounds((IInteger) first.getValue(),
              __eval.__getEval().getCurrentAST(), __eval
View Full Code Here

    if (subjectType.isAbstractData()) {
      subjectType = ((IConstructor) this.subject).getConstructorType();
    }

    INode node = ((INode) this.subject);
    if (node.arity() != patternChildren.size()) {
      return; // that can never match
    }

    if (patternType.comparable(subjectType)) {
      hasNext = true;
View Full Code Here

    return ResultFactory.bool(getValue().getName().equals(Names.name(name)), ctx);
  }
 
  @Override
  public Result<IBool> has(Name name) {
    INode node = getValue();
    if(node instanceof IConstructor)
      return ResultFactory.bool(((IConstructor) node).has(Names.name(name)), ctx);
    else
      return ResultFactory.bool(false, ctx);
  }
View Full Code Here

 
  //////
 
  @Override
  protected LessThanOrEqualResult lessThanOrEqualNode(NodeResult that) {
    INode left = that.getValue();
    INode right = getValue();
   
    int compare = left.getName().compareTo(right.getName());
   
    if (compare <= -1) {
      return new LessThanOrEqualResult(true, false, ctx);
    }
   
    if (compare >= 1){
      return new LessThanOrEqualResult(false, false, ctx);
    }
   
    // if the names are not ordered, then we order lexicographically on the arguments:
   
    int leftArity = left.arity();
    int rightArity = right.arity();
   
    if (leftArity < rightArity) {
      return new LessThanOrEqualResult(true, false, ctx);
    }
   
    if (leftArity > rightArity) {
      return new LessThanOrEqualResult(false, false, ctx);
    }
   
    for (int i = 0; i < Math.min(leftArity, rightArity); i++) {
      IValue leftArg = left.get(i);
      IValue rightArg = right.get(i);
      LessThanOrEqualResult loe = makeResult(leftArg.getType(), leftArg, ctx).lessThanOrEqual(makeResult(rightArg.getType(), rightArg,ctx));

      if (loe.getLess() && !loe.getEqual()) {
        return new LessThanOrEqualResult(true, false, ctx);
      }

      if (!loe.getEqual()) {
        return new LessThanOrEqualResult(false, false, ctx);
      }
    }
   
    if (!left.mayHaveKeywordParameters() && !right.mayHaveKeywordParameters()) {
      if (left.asAnnotatable().hasAnnotations() || right.asAnnotatable().hasAnnotations()) {
        // bail out
        return new LessThanOrEqualResult(false, true, ctx);
      }
    }
   
    if (!left.asWithKeywordParameters().hasParameters() && right.asWithKeywordParameters().hasParameters()) {
      return new LessThanOrEqualResult(true, false, ctx);
    }

    if (left.asWithKeywordParameters().hasParameters() && !right.asWithKeywordParameters().hasParameters()) {
      return new LessThanOrEqualResult(false, false, ctx);
    }
   
    if (left.asWithKeywordParameters().hasParameters() && right.asWithKeywordParameters().hasParameters()) {
      Map<String, IValue> paramsLeft = left.asWithKeywordParameters().getParameters();
      Map<String, IValue> paramsRight = right.asWithKeywordParameters().getParameters();
      if (paramsLeft.size() < paramsRight.size()) {
        return new LessThanOrEqualResult(true, false, ctx);
      }
      if (paramsLeft.size() > paramsRight.size()) {
        return new LessThanOrEqualResult(false, false, ctx);
View Full Code Here

TOP

Related Classes of org.eclipse.imp.pdb.facts.INode

Copyright © 2018 www.massapicom. 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.