static L<PTElement> ai_scanParseTreeForCategory(PTElement e, S category) {
  new L<PTElement> out;
  ai_scanParseTreeForCategory_scan(e, category, out);
  ret out;
}

svoid ai_scanParseTreeForCategory_scan(PTElement e, S category, L<PTElement> out) {
  if (e == null) ret;
  if (e cast HaveCategory)
    if (eq(e.category, category))
      out.add(e);
  for (PTElement child : unnull(e.children))
    ai_scanParseTreeForCategory_scan(child, category, out);
}