Examples of IList


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

    }
    if (isSort(symbol) || isLex(symbol) || isKeyword(symbol)) {
      return getName(symbol);
    }
    if (isCharClass(symbol)) {
      IList ranges = getRanges(symbol);
      StringBuilder b = new StringBuilder();
      b.append("[");
      for (IValue range : ranges) {
        IInteger from = getRangeBegin(range);
        IInteger to = getRangeEnd(range);
        if  (from.equals(to)) {
          b.append(escapeChar(from.intValue()));
        }
        else {
          b.append(escapeChar(from.intValue()));
          b.append("-");
          b.append(escapeChar(to.intValue()));
        }
      }
      b.append("]");
      return b.toString();
    }
   
   
    if (isIterPlusSeps(symbol)) {
      IList seps = getSeparators(symbol);
      StringBuilder b = new StringBuilder();
     
      if (!withLayout && seps.length() == 1 && isLayouts((IConstructor) seps.get(0))) {
        b.append(toString(getSymbol(symbol), withLayout));
        b.append('+');
      }
      else {
        b.append('{');
        b.append(toString(getSymbol(symbol), withLayout));
        for (IValue sep : seps) {
          b.append(" ");
          b.append(toString((IConstructor) sep, withLayout));
        }
        b.append('}');
        b.append('+');
      }
     
      return b.toString();
     
    }
   
    if (isIterStarSeps(symbol)) {
      StringBuilder b = new StringBuilder();
       IList seps = getSeparators(symbol);
      
      if (!withLayout && seps.length() == 1 && isLayouts((IConstructor) seps.get(0))) {
        b.append(toString(getSymbol(symbol), withLayout));
        b.append('*');
      }
      else {
        b.append('{');
        b.append(toString(getSymbol(symbol), withLayout));
        for (IValue sep : seps) {
          if (!isLayouts((IConstructor) sep)) {
            b.append(" ");
            b.append(toString((IConstructor) sep, withLayout));
          }
        }
        b.append('}');
        b.append('*');
      }
      return b.toString();
    }
    if (isIterPlus(symbol)) {
      return toString(getSymbol(symbol), withLayout) + '+';
    }
    if (isIterStar(symbol)) {
      return toString(getSymbol(symbol), withLayout) + '*';
    }
    if (isOpt(symbol)) {
      return toString(getSymbol(symbol), withLayout) + '?';
    }
    if (isSeq(symbol)) {
      return "(" + toString(getSymbols(symbol), ' ', withLayout) + ")";
    }
    if (isAlt(symbol)) {
      ISet alts = getAlternatives(symbol);
      StringBuilder b = new StringBuilder();
      b.append("(");
      boolean first = true;
      for (IValue elem : alts) {
        if (!first) {
          first = false;
          b.append(" | ");
        }
        b.append(toString((IConstructor) elem, withLayout));
      }
      b.append(")");
      return b.toString();
    }
    if (isLayouts(symbol)) {
      return withLayout ? "layout[" + symbol.get("name") + "]" : "";
    }
    if (isLiteral(symbol)) {
      return '"' + ((IString) symbol.get("string")).getValue() + '"';
    }
    if (isCILiteral(symbol)) {
      return '\'' + ((IString) symbol.get("string")).getValue() + '\'';
    }
    if (isParameterizedSort(symbol) || isParameterizedLex(symbol)) {
      StringBuilder b = new StringBuilder();
      b.append(getName(symbol));
      IList params = (IList) symbol.get("parameters");
      b.append('[');
      b.append(toString(params, ',', withLayout));
      b.append(']');
      return b.toString();
    }
    if (isStartSort(symbol)) {
      return "start[" + toString(getStart(symbol), withLayout) + "]";
    }
    if (isParameter(symbol)) {
      return "&" + getName(symbol);
    }
   
    if (isInt(symbol) || isStr(symbol) || isReal(symbol) || isBool(symbol) || isRat(symbol)
        || isNode(symbol) || isValue(symbol) || isVoid(symbol) || isNum(symbol) || isDatetime(symbol) || isLoc(symbol)) {
      return symbol.getName();
    }
   
    if (isSet(symbol) || isList(symbol) || isBag(symbol) || isReifiedType(symbol)) {
      return symbol.getName() + "[" + toString((IConstructor) symbol.get("symbol"), withLayout) + "]";
    }
   
    if (isRel(symbol) || isListRel(symbol) || isTuple(symbol)) {
      StringBuilder b = new StringBuilder();
      b.append(symbol.getName());
      IList symbols = (IList) symbol.get("symbols");
      b.append('[');
      b.append(toString(symbols, ',', withLayout));
      b.append(']');
      return b.toString();
    }
   
    if (isMap(symbol)) {
      return symbol.getName() + "[" + toString((IConstructor) symbol.get("from"), withLayout) + "," + toString((IConstructor) symbol.get("to"), withLayout) + "]";
    }
   
    if (isConditional(symbol)) {
      ISet conditions = getConditions(symbol);
      StringBuilder b = new StringBuilder();
      // first prefix conditions
      for (IValue elem : conditions) {
        IConstructor cond = (IConstructor) elem;
        switch (cond.getConstructorType().getName()) {
        case "precede":
          b.append(toString((IConstructor) cond.get("symbol"), withLayout));
          b.append(" << ");
          break;
        case "not-precede":
          b.append(toString((IConstructor) cond.get("symbol"), withLayout));
          b.append(" !<< ");
          break;
        case "begin-of-line":
          b.append("^ ");
          break;
        }
      }
      // then the symbol
      b.append(toString(getSymbol(symbol), withLayout));
     
      // then the postfix conditions
      for (IValue elem : conditions) {
        IConstructor cond = (IConstructor) elem;
        switch (cond.getConstructorType().getName()) {
        case "follow":
          b.append(" >> ");
          b.append(toString((IConstructor) cond.get("symbol"), withLayout));
          break;
        case "not-follow":
          b.append(" !>> ");
          b.append(toString((IConstructor) cond.get("symbol"), withLayout));
          break;
        case "delete":
          b.append(" \\ ");
          b.append(toString((IConstructor) cond.get("symbol"), withLayout));
          break;
        case "except":
          b.append("!");
          b.append(((IString) cond.get("label")).getValue());
        case "end-of-line":
          b.append(" $");
          break;
        }
      }
       
      return b.toString();
    }
   
    if (isADT(symbol) || isAlias(symbol)) {
      StringBuilder b = new StringBuilder();
      b.append(getName(symbol));
      IList params = (IList) symbol.get("parameters");
     
      if (!params.isEmpty()) {
        b.append('[');
        b.append(toString(params, ',', withLayout));
        b.append(']');
      }
      return b.toString();
View Full Code Here

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

    if (debug) {
      System.err.println("length=" + length);
      System.err.println("reducedLength=" + reducedLength);
    }  

    IList sublist = makeSubList(start, reducedLength);

    if(debug)System.err.println("matchBindingListVar: init child #" + patternCursor + " (" + child + ") with " + sublist);
    // TODO : check if we can use a static type here!?
    child.initMatch(ResultFactory.makeResult(sublist.getType(), sublist, ctx));

    if(child.next()){
      subjectCursor = start + length;
      if(debug)System.err.println("child matches, subjectCursor=" + subjectCursor);
      patternCursor += delta;
View Full Code Here

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

 
  public IValue upTill(IInteger ni) {
    //@doc{Returns the list 0..n, this is slightly faster than [0,1..n], since the returned values are shared}
    int n = ni.intValue();
    if(indexes == null || indexes.get() == null) {
      IList l = makeUpTill(0, n);
      indexes = new WeakReference<IList>(l);
      return indexes.get();
    } else {
      IList l = indexes.get(); // strong ref
      if(l == null || n >= l.length()){
        l = makeUpTill(0,n);
        indexes =  new WeakReference<IList>(l);
        return l;
      }
      return l.sublist(0, n);
    }
  }
View Full Code Here

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

  }

  public IValue makeNode(IString N, IList V, IMap kwParams)
  //@doc{makeNode -- create a node given its function name and arguments}
  {
      IList argList = V;
    IValue args[] = new IValue[argList.length()];
    int i = 0;
    for(IValue v : argList){
      args[i++] = v;
    }
   
View Full Code Here

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

    if (type.isString() && !splicing) {
      return values.string(TreeAdapter.yield(tree));
    }

    if (SymbolAdapter.isStartSort(TreeAdapter.getType(tree))) {
      IList args = TreeAdapter.getArgs(tree);
      IConstructor before = (IConstructor) args.get(0);
      IConstructor ast = (IConstructor) args.get(1);
      IConstructor after = (IConstructor) args.get(2);
      IValue result = implode(store, type, ast, splicing, ctx);
      if (result.getType().isNode()) {
        IMapWriter comments = values.mapWriter();
        comments.putAll((IMap)((INode)result).asAnnotatable().getAnnotation("comments"));
        IList beforeComments = extractComments(before);
        if (!beforeComments.isEmpty()) {
          comments.put(values.integer(-1), beforeComments);
        }
        IList afterComments = extractComments(after);
        if (!afterComments.isEmpty()) {
          comments.put(values.integer(((INode)result).arity()), afterComments);
        }
        result = ((INode)result).asAnnotatable().setAnnotation("comments", comments.done());
      }
      return result;
    }
   
    if (TreeAdapter.isLexical(tree)) {
      java.lang.String constructorName = unescapedConsName(tree);
      java.lang.String yield = TreeAdapter.yield(tree);
      if (constructorName != null) {
        // make a single argument constructor  with yield as argument
        // if there is a singleton constructor with a str argument
        if (!type.isAbstractData() && !isUntypedNodeType(type)) {
          throw RuntimeExceptionFactory.illegalArgument(tree, null, null, "Constructor (" + constructorName + ") should match with abstract data type and not with " + type);
        }
       
        if (isUntypedNodeType(type)) {
          return values.node(constructorName, values.string(yield));
        }
       
        Set<Type> conses = findConstructors(type, constructorName, 1, store);
        Iterator<Type> iter = conses.iterator();
        while (iter.hasNext()) {
          try {
            @SuppressWarnings("unused")
            Type cons = iter.next();
            ISourceLocation loc = TreeAdapter.getLocation(tree);
            IConstructor ast = makeConstructor(type, constructorName, ctx, values.string(yield));
            return ast.asAnnotatable().setAnnotation("location", loc);
          }
          catch (Backtrack b) {
            continue;
          }
        }
        throw new Backtrack(RuntimeExceptionFactory.illegalArgument(tree, null, null, "Cannot find a constructor " + type));
      }
      if (type.isInteger()) {
        return values.integer(yield);
      }
      if (type.isReal()) {
        return values.real(yield);
      }
      if (type.isBool()) {
        if (yield.equals("true")) {
          return values.bool(true);
        }
        if (yield.equals("false")) {
          return values.bool(false);
        }
        throw new Backtrack(RuntimeExceptionFactory.illegalArgument(tree, null, null, "Bool type does not match with " + yield));
      }
      if (type.isString() || isUntypedNodeType(type)) {
        // NB: in "node space" all lexicals become strings
        return values.string(yield);
      }
     
      throw RuntimeExceptionFactory.illegalArgument(tree, null, null, "Missing lexical constructor");
    }
   
    //Set implementation added here by Jurgen at 19/07/12 16:45
    if (TreeAdapter.isList(tree)) {
      if (type.isList() || splicing || isUntypedNodeType(type)) {
        // if in node space, we also make a list;
        // NB: this breaks type safety if the top-level tree
        // is itself a list.
       
        Type elementType = type;
        if (!splicing && !isUntypedNodeType(type)) {
          elementType = type.getElementType();
        }
        IListWriter w = values.listWriter();
        for (IValue arg: TreeAdapter.getListASTArgs(tree)) {
          w.append(implode(store, elementType, (IConstructor) arg, false, ctx));
        }
        return w.done();
      }
      else if (type.isSet()) {
        Type elementType = splicing ? type : type.getElementType();
        ISetWriter w = values.setWriter();
        for (IValue arg: TreeAdapter.getListASTArgs(tree)) {
          w.insert(implode(store, elementType, (IConstructor) arg, false, ctx));
        }
        return w.done();
      }
      else {
        throw new Backtrack(RuntimeExceptionFactory.illegalArgument(tree, null, null, "Cannot match list with " + type));
      }
    }
    //Changes end here
   
    if (TreeAdapter.isOpt(tree) && type.isBool()) {
      IList args = TreeAdapter.getArgs(tree);
      if (args.isEmpty()) {
        return values.bool(false);
      }
      return values.bool(true);
    }
   
    if (TreeAdapter.isOpt(tree)) {
      if (!type.isList() && !isUntypedNodeType(type)) {
        throw new Backtrack(RuntimeExceptionFactory.illegalArgument(tree, null, null, "Optional should match with a list and not " + type));
      }
      Type elementType = isUntypedNodeType(type) ? type : type.getElementType();
      IListWriter w = values.listWriter();
      for (IValue arg: TreeAdapter.getASTArgs(tree)) {
        IValue implodedArg = implode(store, elementType, (IConstructor) arg, true, ctx);
        if (implodedArg instanceof IList) {
          // splicing
          for (IValue nextArg: (IList)implodedArg) {
            w.append(nextArg);
          }
        }
        else {
          w.append(implodedArg);
        }
        // opts should have one argument (if any at all)
        break;
      }
      return w.done();
    }
   
    if (TreeAdapter.isAmb(tree)) {
      if (!type.isSet()) {
        throw new Backtrack(RuntimeExceptionFactory.illegalArgument(tree, null, null, "Ambiguous node should match with set and not " + type));
      }
      Type elementType = type.getElementType();
      ISetWriter w = values.setWriter();
      for (IValue arg: TreeAdapter.getAlternatives(tree)) {
        w.insert(implode(store, elementType, (IConstructor) arg, false, ctx));
      }
      return w.done();
    }
   
    if (ProductionAdapter.hasAttribute(TreeAdapter.getProduction(tree), Factory.Attribute_Bracket)) {
      return implode(store, type, (IConstructor) TreeAdapter.getASTArgs(tree).get(0), false, ctx);
    }
   
    if (TreeAdapter.isAppl(tree)) {
      IList args = TreeAdapter.getASTArgs(tree);
     
      int j = 0;
      IMapWriter cw = values.mapWriter();
      IListWriter aw = values.listWriter();
      for (IValue kid : TreeAdapter.getArgs(tree)) {
        if (TreeAdapter.isLayout((IConstructor) kid)) {
          IList cts = extractComments((IConstructor) kid);
          if (!cts.isEmpty()) {
            cw.put(values.integer(j), cts);
          }
          j++;
        }
        else if (!TreeAdapter.isLiteral((IConstructor) kid) &&
View Full Code Here

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

     
      // Otherwise:
      // - Copy prod node verbatim to result
      // - Only visit non-layout nodes in argument list
      args[0] = cons.get(0);
      IList list = (IList) cons.get(1);
      int len = list.length();

      if (len > 0) {
        IListWriter w = eval.getValueFactory().listWriter(list.getType().getElementType());
        boolean hasChanged = false;
        boolean hasMatched = false;

        for (int i = 0; i < len; i++){
          IValue elem = list.get(i);
          if (i % 2 == 0) { // Recursion to all non-layout elements
            tr.changed = false;
            tr.matched = false;
            w.append(traverseOnce(elem, casesOrRules, direction, progress, fixedpoint, tr));
            hasChanged |= tr.changed;
            hasMatched |= tr.matched;
          } else { // Just copy layout elements
            w.append(list.get(i));
          }
        }
        tr.changed = hasChanged;
        tr.matched = hasMatched;
        args[1] = w.done();
View Full Code Here

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

    }
  }

  private IValue traverseListOnce(IValue subject, CaseBlockList casesOrRules,
      DIRECTION direction, PROGRESS progress, FIXEDPOINT fixedpoint, TraverseResult tr) {
    IList list = (IList) subject;
    int len = list.length();
    if (len > 0){
      IListWriter w = eval.getValueFactory().listWriter(list.getType().getElementType());
      boolean hasChanged = false;
      boolean hasMatched = false;
     
      for (int i = 0; i < len; i++){
        IValue elem = list.get(i);
        tr.changed = false;
        tr.matched = false;
        w.append(traverseOnce(elem, casesOrRules, direction, progress, fixedpoint, tr));
        hasChanged |= tr.changed;
        hasMatched |= tr.matched;
View Full Code Here

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

          IValue newKid = oldKid.accept(new PushDownTreeVisitor<E>(isDeferred));
         
          writer.append(newKid);
        }

        IList children = writer.done();

        // update current tree with processed children
        arg = TreeAdapter.setArgs(arg, children);
      }
   
View Full Code Here

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

    this.list = list;
  }

  @Override
  public IValue up(IValue focus) {
    IList fl = (IList)focus;
    return new ListCursor(list.sublist(0, offset).concat(fl.concat(list.sublist(offset + length, list.length() - (offset + length)))), ctx);
  }
View Full Code Here

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

      fStream.write(Character.toChars(((IInteger) arg.get("character")).intValue()));
      return arg;
    }
   
    public IConstructor visitTreeAppl(IConstructor arg) throws IOException {
      IList children = (IList) arg.get("args");
      for (IValue child : children) {
        child.accept(this);
      }
      return arg;
    }
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.