示例#1
0
文件: KApp.java 项目: kszr/k
 /** Constructs a {@link KApp} object from an XML {@link Element}. */
 public KApp(Element element, org.kframework.kil.loader.Context context) {
   super(element);
   List<Element> childrenElements = XML.getChildrenElements(element);
   Element body = XML.getChildrenElements(childrenElements.get(0)).get(0);
   setLabel((Term) JavaClassesFactory.getTerm(body));
   Term term = (Term) JavaClassesFactory.getTerm(childrenElements.get(1));
   if (!(term.getSort().equals(Sort.KLIST) || term instanceof Ambiguity)) {
     setChild(new KList(Collections.<Term>singletonList(term)));
   } else {
     setChild(term);
   }
 }
示例#2
0
文件: Attributes.java 项目: jcnm/k
  public Attributes(Element element, JavaClassesFactory factory) {
    super(element);

    contents = new LinkedHashMap<>();
    List<Element> children = XML.getChildrenElements(element);
    for (Element e : children) add((Attribute<?>) factory.getTerm(e));
  }
示例#3
0
  /**
   * Load program file to ASTNode.
   *
   * <p>Write pgm.xml cache in given dotk folder.
   *
   * @param kappize If true, then apply KAppModifier to AST.
   */
  public static ASTNode loadPgmAst(
      String content, String filename, Boolean kappize, String startSymbol, Context context)
      throws IOException, TransformerException {
    File tbl = new File(context.kompiled.getCanonicalPath() + "/pgm/Program.tbl");

    // ------------------------------------- import files in Stratego
    ASTNode out;

    if (GlobalSettings.fastKast) {
      // out = Sglri.run_sglri(context.kompiled.getAbsolutePath() + "/pgm/Program.tbl", startSymbol,
      // content);
      JavaClassesFactory.startConstruction(context);
      out =
          Sglr.run_sglri(
              context.kompiled.getAbsolutePath() + "/pgm/Program.tbl",
              startSymbol,
              content,
              filename);
      out.accept(new ReportErrorsVisitor(context, "file"));
      JavaClassesFactory.endConstruction();
    } else {
      org.kframework.parser.concrete.KParser.ImportTblPgm(tbl.getAbsolutePath());
      String parsed =
          org.kframework.parser.concrete.KParser.ParseProgramString(content, startSymbol);
      Document doc = XmlLoader.getXMLDoc(parsed);

      XmlLoader.addFilename(doc.getFirstChild(), filename);
      XmlLoader.reportErrors(doc);
      FileUtil.save(context.kompiled.getAbsolutePath() + "/pgm.xml", parsed);
      JavaClassesFactory.startConstruction(context);
      out =
          JavaClassesFactory.getTerm(
              (Element) doc.getDocumentElement().getFirstChild().getNextSibling());
      JavaClassesFactory.endConstruction();
    }

    out = out.accept(new PriorityFilter(context));
    out = out.accept(new PreferAvoidFilter(context));
    out = out.accept(new AmbFilter(context));
    out = out.accept(new RemoveBrackets(context));

    if (kappize) out = out.accept(new FlattenSyntax(context));

    return out;
  }
示例#4
0
  public TermCons(Element element, Context context) {
    super(element);
    this.sort = element.getAttribute(Constants.SORT_sort_ATTR);
    this.cons = element.getAttribute(Constants.CONS_cons_ATTR);
    this.production = context.conses.get(cons);
    assert this.production != null;

    contents = new ArrayList<Term>();
    List<Element> children = XML.getChildrenElements(element);
    for (Element e : children) contents.add((Term) JavaClassesFactory.getTerm(e));
  }
示例#5
0
  public TermCons(ATermAppl atm, Context context) {
    super(atm);
    this.cons = atm.getName();
    this.sort = StringUtil.getSortNameFromCons(cons);
    this.production = context.conses.get(cons);
    assert this.production != null;

    contents = new ArrayList<Term>();
    if (atm.getArity() == 0) {
      contents = new ArrayList<Term>();
    } else if (atm.getArgument(0) instanceof ATermList) {
      ATermList list = (ATermList) atm.getArgument(0);
      for (; !list.isEmpty(); list = list.getNext()) {
        if (isColon(list.getFirst())) continue;
        contents.add((Term) JavaClassesFactory.getTerm(list.getFirst()));
      }
      contents.add(new ListTerminator(sort, null));
    } else {
      for (int i = 0; i < atm.getArity(); i++) {
        if (isColon(atm.getArgument(i))) continue;
        contents.add((Term) JavaClassesFactory.getTerm(atm.getArgument(i)));
      }
    }
  }