Esempio n. 1
0
  @Override
  public IStrategoTerm invoke(Context context, IStrategoTerm current, IStrategoTerm projectName) {
    if (!isTermString(current) || !isTermString(projectName)) return null;
    String filename = ((IStrategoString) current).stringValue();

    ISourceProject project = findProject(((IStrategoString) projectName).stringValue());
    if (project == null) return null;

    File file = new File(filename);

    Descriptor descriptor = Environment.getDescriptor(LanguageRegistry.findLanguage("SugarTest"));
    IStrategoTerm result = null;
    try {
      IParseController ip = descriptor.createParseController();
      if (ip instanceof DynamicParseController) ip = ((DynamicParseController) ip).getWrapped();
      if (ip instanceof SGLRParseController) {
        SGLRParseController sglrController = (SGLRParseController) ip;
        sglrController.initialize(new Path(filename), project, null);
        // Must lock the parse lock of this controller
        // or hit the assertion in AbstractSGLRI.parse
        sglrController.getParseLock().lock();
        try {
          JSGLRI parser = sglrController.getParser();
          parser.setUseRecovery(false);
          result = parser.parse(new FileInputStream(file), file.getAbsolutePath());
        } finally {
          sglrController.getParseLock().unlock();
        }
      }
    } catch (Exception e) {
      Environment.logException("Could not parse testing string", e);
    }
    return result;
  }
 public ParseControllerBase(String languageID) {
   fLanguage = LanguageRegistry.findLanguage(languageID);
 }