Examples of IConstructor


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

     return (IConstructor) module.accept(new IdentityTreeVisitor<ImplementationError>() {
       final IValueFactory vf = eval.getValueFactory();
      
       @Override
       public IConstructor visitTreeAppl(IConstructor tree)  {
         IConstructor pattern = getConcretePattern(tree);
        
         if (pattern != null) {
           IConstructor parsedFragment = parseFragment(eval, env, (IConstructor) TreeAdapter.getArgs(tree).get(0), location);
           return TreeAdapter.setArgs(tree, vf.list(parsedFragment));
         }
         else {
           IListWriter w = vf.listWriter();
           IList args = TreeAdapter.getArgs(tree);
View Full Code Here

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

      throw new ImplementationError(e.getMessage(), e);
    }
  }
 
  private static IConstructor parseFragment(IEvaluator<Result<IValue>> eval, ModuleEnvironment env, IConstructor tree, URI uri) {
    IConstructor symTree = TreeAdapter.getArg(tree, "symbol");
    IConstructor lit = TreeAdapter.getArg(tree, "parts");
    Map<String, IConstructor> antiquotes = new HashMap<String,IConstructor>();
   
    IGTD<IConstructor, IConstructor, ISourceLocation> parser = env.getBootstrap() ? new RascalParser() : getParser(eval, env, TreeAdapter.getLocation(tree).getURI(), false);
   
    try {
      String parserMethodName = eval.getParserGenerator().getParserMethodName(symTree);
      DefaultNodeFlattener<IConstructor, IConstructor, ISourceLocation> converter = new DefaultNodeFlattener<IConstructor, IConstructor, ISourceLocation>();
      UPTRNodeFactory nodeFactory = new UPTRNodeFactory();
   
      char[] input = replaceAntiQuotesByHoles(eval, lit, antiquotes);
     
      IConstructor fragment = (IConstructor) parser.parse(parserMethodName, uri, input, converter, nodeFactory);
      fragment = replaceHolesByAntiQuotes(eval, fragment, antiquotes);

      IConstructor prod = TreeAdapter.getProduction(tree);
      IConstructor sym = ProductionAdapter.getDefined(prod);
      sym = SymbolAdapter.delabel(sym);
      IValueFactory vf = eval.getValueFactory();
      prod = ProductionAdapter.setDefined(prod, vf.constructor(Factory.Symbol_Label, vf.string("$parsed"), sym));
      return TreeAdapter.setProduction(TreeAdapter.setArg(tree, "parts", fragment), prod);
    }
View Full Code Here

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

  private static char[] replaceAntiQuotesByHoles(IEvaluator<Result<IValue>> eval, IConstructor lit, Map<String, IConstructor> antiquotes) {
    IList parts = TreeAdapter.getArgs(lit);
    StringBuilder b = new StringBuilder();
   
    for (IValue elem : parts) {
      IConstructor part = (IConstructor) elem;
      String cons = TreeAdapter.getConstructorName(part);
     
      if (cons.equals("text")) {
        b.append(TreeAdapter.yield(part));
      }
View Full Code Here

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

            args = w.done();
           
            return TreeAdapter.setArgs(tree, args);
          }
         
          IConstructor type = retrieveHoleType(tree);
          return antiquotes.get(TreeAdapter.yield(tree)).asAnnotatable().setAnnotation("holeType", type);
        }
       
        private IConstructor retrieveHoleType(IConstructor tree) {
          IConstructor prod = TreeAdapter.getProduction(tree);
          ISet attrs = ProductionAdapter.getAttributes(prod);

          for (IValue attr : attrs) {
            if (((IConstructor) attr).getConstructorType() == Factory.Attr_Tag) {
              IValue arg = ((IConstructor) attr).get(0);
View Full Code Here

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

    }
    return new Document(nodeToElement(node));
  }

  private Element nodeToElement(IConstructor elt) {
    IConstructor ns = (IConstructor) elt.get(0);
    IString name = (IString) elt.get(1);
    IList kids = (IList) elt.get(2);
    Element e = new Element(name.getValue(), namespaceToNamespace(ns));
    for (IValue k: kids) {
      IConstructor n = (IConstructor) k;
      if (n.getConstructorType() == Factory.Node_attribute) {
        e.setAttribute(nodeToAttribute(n));
      }
      else {
        e.addContent(nodeToContent(n));
      }
View Full Code Here

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

    wellformednessError();
    return null;
  }

  private Attribute nodeToAttribute(IConstructor n) {
    IConstructor ns = (IConstructor) n.get(0);
    IString name = (IString) n.get(1);
    IString data = (IString) n.get(2);
    return new Attribute(name.getValue(), data.getValue(), namespaceToNamespace(ns));
  }
View Full Code Here

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

    throw new RuntimeException("Nonwellformed XML node (TODO: make Rascal runtime exception)");
  }

 
  private IConstructor convertDocument(Document doc, boolean trim) {
    IConstructor root = convertElement(doc.getRootElement(), trim);
    return vf.constructor(Factory.Node_document, root);
  }
View Full Code Here

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

    if (ns == Namespace.NO_NAMESPACE) {
      return vf.constructor(Factory.Namespace_none);
    }
    IString prefix = vf.string(ns.getPrefix());
    IString uri = vf.string(ns.getURI());
    IConstructor nscon = vf.constructor(Factory.Namespace_namespace, prefix, uri);
    return nscon;
  }
View Full Code Here

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

      String filename = ((IString) loc.get("filename")).getValue();
      return factory.sourceLocation(filename, 0, 0,
          0, 0, 0, 0);
    } else if (type == Location_Area) {
      String filename = "/";
      IConstructor area = (IConstructor) loc.get("area");
      if (area.getConstructorType() == Area_Area) {
        int offset = ((IInteger) area.get("offset")).intValue();
        int startLine = ((IInteger) area.get("beginLine")).intValue();
        int endLine = ((IInteger) area.get("endLine")).intValue();
        int startCol = ((IInteger) area.get("beginColumn")).intValue();
        int endCol = ((IInteger) area.get("endColumn")).intValue();
        int length = ((IInteger) area.get("length")).intValue();

        return factory.sourceLocation(filename,
            offset, length, startLine, endLine, startCol, endCol);
      }
      throw new UnexpectedConstructorTypeException(Area, area.getType());
    } else if (type == Location_AreaInFile) {
      String filename = ((IString) loc.get("filename")).getValue();
      IConstructor area = (IConstructor) loc.get("area");
      if (area.getConstructorType() == Area_Area) {
        int offset = ((IInteger) area.get("offset")).intValue();
        int startLine = ((IInteger) area.get("beginLine")).intValue();
        int endLine = ((IInteger) area.get("endLine")).intValue();
        int startCol = ((IInteger) area.get("beginColumn")).intValue();
        int endCol = ((IInteger) area.get("endColumn")).intValue();
        int length = ((IInteger) area.get("length")).intValue();

        return factory.sourceLocation(filename,
            offset, length, startLine, endLine, startCol, endCol);
      }

      throw new UnexpectedConstructorTypeException(Area, area.getType());

    }

    throw new UnexpectedConstructorTypeException(Location, type);
  }
View Full Code Here

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

    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;
        }
      }
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.