Examples of IConstructor


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

    return new StandardTextReader().read(ValueFactoryFactory.getValueFactory(), Factory.uptr, Factory.Tree, new StringReader(expectedInput));
  }

  public static void main(String[] args){
    CILiteral cil = new CILiteral();
    IConstructor result = cil.executeParser();
    System.out.println(result);
   
    System.out.println("S(Bla) <- good");
  }
View Full Code Here

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

    return new StandardTextReader().read(ValueFactoryFactory.getValueFactory(), Factory.uptr, Factory.Tree, new StringReader(expectedInput));
  }
 
  public static void main(String[] args){
    AmbiguousNonTerminalPlusList2 nrpl2 = new AmbiguousNonTerminalPlusList2();
    IConstructor result = nrpl2.executeParser();
    System.out.println(result);
   
    System.out.println("S([A+(A(a),A(aa)),A+([A+(A(aa)),A+(A(a),A(a))],A(a))]) <- good");
  }
View Full Code Here

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

  }
 
  // REFLECT -- copy in PreludeCompiled
  public IValue parse(IValue start, IMap robust, ISourceLocation input, IEvaluatorContext ctx) {
    Type reified = start.getType();
    IConstructor startSort = checkPreconditions(start, reified);
   
    try {
      IConstructor pt = ctx.getEvaluator().parseObject(ctx.getEvaluator().getMonitor(), startSort, robust, input.getURI());

      if (TreeAdapter.isAppl(pt)) {
        if (SymbolAdapter.isStart(TreeAdapter.getType(pt))) {
          pt = (IConstructor) TreeAdapter.getArgs(pt).get(1);
        }
View Full Code Here

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

    return new StandardTextReader().read(ValueFactoryFactory.getValueFactory(), Factory.uptr, Factory.Tree, new StringReader(expectedInput));
  }
 
  public static void main(String[] args){
    NullableSharing ns = new NullableSharing();
    IConstructor result = ns.executeParser();
    System.out.println(result);
   
    System.out.println("S(N(A()),N(A())) <- good");
  }
View Full Code Here

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

    return parse(start, values.mapWriter().done(), input, ctx);
  }
 
  public IValue parse(IValue start, IMap robust, IString input, IEvaluatorContext ctx) {
    Type reified = start.getType();
    IConstructor startSort = checkPreconditions(start, reified);
    try {
      IConstructor pt = ctx.getEvaluator().parseObject(ctx.getEvaluator().getMonitor(), startSort, robust, input.getValue());

      if (TreeAdapter.isAppl(pt)) {
        if (SymbolAdapter.isStart(TreeAdapter.getType(pt))) {
          pt = (IConstructor) TreeAdapter.getArgs(pt).get(1);
        }
View Full Code Here

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

    return parse(start, values.mapWriter().done(), input, loc, ctx);
  }
 
  public IValue parse(IValue start, IMap robust, IString input, ISourceLocation loc, IEvaluatorContext ctx) {
    Type reified = start.getType();
    IConstructor startSort = checkPreconditions(start, reified);
    try {
      IConstructor pt = ctx.getEvaluator().parseObject(ctx.getEvaluator().getMonitor(), startSort, robust, input.getValue(), loc);

      if (TreeAdapter.isAppl(pt)) {
        if (SymbolAdapter.isStart(TreeAdapter.getType(pt))) {
          pt = (IConstructor) TreeAdapter.getArgs(pt).get(1);
        }
View Full Code Here

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

      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) &&
            !TreeAdapter.isCILiteral((IConstructor) kid) &&
            !TreeAdapter.isEmpty((IConstructor) kid)) {
          aw.append(kid);
        }
      }
      args = aw.done();
      int length = args.length();
      IMap comments = cw.done();
     
//      // this could be optimized.
//      i = 0;
//      int length = args.length();
//      while (i < length) {
//        if (TreeAdapter.isEmpty((IConstructor) args.get(i))) {
//          length--;
//          args = args.delete(i);
//        }
//        else {
//          i++;
//        }
//      }
     
     
      java.lang.String constructorName = unescapedConsName(tree);     
     
      if (constructorName == null) {
        if (length == 1) {
          // jump over injection
          return implode(store, type, (IConstructor) args.get(0), splicing, ctx);
        }
       
       
        // make a tuple if we're in node space
        if (isUntypedNodeType(type)) {
          return values.tuple(implodeArgs(store, type, args, ctx));
        }

        if (!type.isTuple()) {
          throw new Backtrack(RuntimeExceptionFactory.illegalArgument(tree, null, null, "Constructor does not match with " + type));
        }
       
        if (length != type.getArity()) {
          throw new Backtrack(RuntimeExceptionFactory.arityMismatch(type.getArity(), length, null, null));
        }

        return values.tuple(implodeArgs(store, type, args, ctx));
      }
     
      // if in node space, make untyped nodes
      if (isUntypedNodeType(type)) {
        INode ast = values.node(constructorName, implodeArgs(store, type, args, ctx));
        return ast.asAnnotatable().setAnnotation("location", TreeAdapter.getLocation(tree)).asAnnotatable().setAnnotation("comments", comments);
      }
     
      // make a typed constructor
      if (!type.isAbstractData()) {
        throw new Backtrack(RuntimeExceptionFactory.illegalArgument(tree, null, null, "Constructor (" + constructorName + ") should match with abstract data type and not with " + type));
      }

      Set<Type> conses = findConstructors(type, constructorName, length, store);
      Iterator<Type> iter = conses.iterator();
      while (iter.hasNext()) {
        try {
          Type cons = iter.next();
          ISourceLocation loc = TreeAdapter.getLocation(tree);
          IValue[] implodedArgs = implodeArgs(store, cons, args, ctx);
          IConstructor ast = makeConstructor(type, constructorName, ctx, implodedArgs);
          return ast.asAnnotatable().setAnnotation("location", loc).asAnnotatable().setAnnotation("comments", comments);
        }
        catch (Backtrack b) {
          continue;
        }
      }
View Full Code Here

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

   
    if (!(nt instanceof NonTerminalType)) {
      throw RuntimeExceptionFactory.illegalArgument(start, null, null, "A non-terminal type is required instead of  " + nt);
    }
   
    IConstructor symbol = ((NonTerminalType) nt).getSymbol();
   
    return symbol;
  }
View Full Code Here

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

    return new StandardTextReader().read(ValueFactoryFactory.getValueFactory(), Factory.uptr, Factory.Tree, new StringReader(expectedInput));
  }

  public static void main(String[] args){
    Ambiguous3 a3 = new Ambiguous3();
    IConstructor result = a3.executeParser();
    System.out.println(result);
   
    System.out.println("[S(A(a),A(aa)),S(A(aa),A(a))] <- good");
  }
View Full Code Here

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

    return new StandardTextReader().read(ValueFactoryFactory.getValueFactory(), Factory.uptr, Factory.Tree, new StringReader(expectedInput));
  }

  public static void main(String[] args){
    Ambiguous2 a2 = new Ambiguous2();
    IConstructor result = a2.executeParser();
    System.out.println(result);
   
    System.out.println("[S(bab),S(A(B(b)),ab)] <- good");
  }
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.