use of org.whole.lang.visitors.IVisitor in project whole by wholeplatform.
the class ReusablesLanguageDeployer method deploy.
public void deploy(ReflectionFactory platform) {
platform.addLanguageKit(new ReusablesLanguageKit());
platform.addOperationFactory(ReusablesLanguageKit.URI, GenericBuilderAdapterOperation.ID, new IBuilderFactory() {
public IBuilder create(IBuilder strategy, IEntityContext entityContext) {
return new ReusablesGenericBuilderAdapter((IReusablesBuilder) strategy, entityContext);
}
});
platform.addOperationFactory(ReusablesLanguageKit.URI, SpecificBuilderAdapterOperation.ID, new IBuilderFactory() {
public IBuilder create(IBuilder strategy, IEntityContext entityContext) {
return new ReusablesSpecificBuilderAdapter(strategy, entityContext);
}
});
platform.addOperationFactory(ReusablesLanguageKit.URI, InterpreterOperation.ID, new IVisitorFactory() {
public IVisitor create(IOperation operation, int stage) {
if (stage == 0)
return new ReusablesInterpreterVisitor();
else
return null;
}
});
platform.addOperationFactory(ReusablesLanguageKit.URI, DynamicCompilerOperation.ID, new IVisitorFactory() {
public IVisitor create(IOperation operation, int stage) {
if (stage == 0)
return new ReusablesDynamicCompilerVisitor();
else
return null;
}
});
platform.addOperationFactory(ReusablesLanguageKit.URI, ArtifactsGeneratorOperation.ID, new IVisitorFactory() {
public IVisitor create(IOperation operation, int stage) {
return new ReusablesArtifactsGeneratorVisitor();
}
});
// platform.addReactionsHandler(ReusablesLanguageKit.URI, new ReusablesReactionsHandler());
}
use of org.whole.lang.visitors.IVisitor in project whole by wholeplatform.
the class AttributesMatcherFactory method matchNamespaceDeclaration.
public static IVisitor matchNamespaceDeclaration(IBindingManager bm) {
IVisitor ov = GenericTraversalFactory.instance.one(GenericMatcherFactory.instance.matchInScope(getNsDeclPattern()), GenericMatcherFactory.instance.matchInScope(getDefaultNsDeclPattern()));
ov.setBindings(bm);
return ov;
}
use of org.whole.lang.visitors.IVisitor in project whole by wholeplatform.
the class ScriptsInterpreterVisitor method visit.
@Override
public void visit(Script entity) {
Writer outputWriter = op().getWriter();
IBindingManager bm = getBindings();
BindingsAdapter bindingsAdapter = new BindingsAdapter(bm, true);
LanguageName languageName = entity.getLanguageName();
/*
* TODO
* if contains an upper level fragment fail
*/
Source source = entity.getSource();
IEntity sourceRoot = EntityUtils.isFragment(source) ? source.wGetRoot() : source;
IEntity result0 = bm.getResult();
IVisitor ov = op().setVisitor(sourceRoot, 0, op().getVisitor(sourceRoot, 1));
op().stagedVisit(source);
IEntity sourceModel = bm.getResult();
// workaround restore previous value (also for self and queryIterator?)
bm.setResult(result0);
op().setVisitor(sourceRoot, 0, ov);
String sourceString = toPrettyPrintString(sourceModel);
ScriptEngineManager scriptEngineManager = new ScriptEngineManager();
ScriptEngine scriptEngine = scriptEngineManager.getEngineByName(languageName.getValue());
if (scriptEngine == null)
throw new VisitException("Cannot find an interpreter for the language: " + languageName);
scriptEngine.setBindings(bindingsAdapter, ScriptContext.ENGINE_SCOPE);
PrintWriter printWriter = new PrintWriter(outputWriter);
scriptEngine.getContext().setWriter(printWriter);
scriptEngine.getContext().setErrorWriter(printWriter);
Object result = null;
bm.wEnterScope();
do {
try {
result = scriptEngine.eval(sourceString);
break;
} catch (ScriptException e) {
bm.wExitScope();
if (!bindingsAdapter.isAutoboxing())
throw new VisitException("Script Interpreter failure.", e);
bindingsAdapter.setAutoboxing(false);
bm.wEnterScope();
}
} while (true);
bm.wExitScope(true);
if (result instanceof IEntity)
bm.setResult((IEntity) result);
else if (result != null)
bm.setResult(BindingManagerFactory.instance.createSpecificValue(result));
}
use of org.whole.lang.visitors.IVisitor in project whole by wholeplatform.
the class RewriteTest method testRewrite.
@Test
public void testRewrite() {
IEntity program = buildImpProgram();
PrettyPrinterOperation.prettyPrint(program);
GenericMatcherFactory mf = GenericMatcherFactory.instance;
GenericTraversalFactory tf = GenericTraversalFactory.instance;
IVisitor v = tf.innermost(tf.concurrentSome(mf.rewrite(IfElseEmptyPattern(), IfElseEmptyRewrite(), false), mf.rewrite(IfTruePattern(), IfTrueRewrite(), false), mf.rewrite(IfTrueElsePattern(), IfTrueRewrite(), false), mf.rewrite(IfNotPattern(), IfNotRewrite(), false)));
v.visit(program);
PrettyPrinterOperation.prettyPrint(program);
}
use of org.whole.lang.visitors.IVisitor in project whole by wholeplatform.
the class ModelsLanguageDeployer method deploy.
public void deploy(ReflectionFactory platform) {
platform.addLanguageKit(new ModelsLanguageKit());
platform.addOperationFactory(ModelsLanguageKit.URI, GenericBuilderAdapterOperation.ID, new IBuilderFactory() {
public IBuilder create(IBuilder strategy, IEntityContext entityContext) {
return new ModelsGenericBuilderAdapter((IModelsBuilder) strategy, entityContext);
}
});
platform.addOperationFactory(ModelsLanguageKit.URI, SpecificBuilderAdapterOperation.ID, new IBuilderFactory() {
public IBuilder create(IBuilder strategy, IEntityContext entityContext) {
return new ModelsSpecificBuilderAdapter(strategy, entityContext);
}
});
platform.addOperationFactory(ModelsLanguageKit.URI, ExportTexOperation.ID, new IVisitorFactory() {
public IVisitor create(IOperation operation, int stage) {
return new TeXGeneratorVisitor((ExportTexOperation) operation);
}
});
platform.addOperationFactory(ModelsLanguageKit.URI, PrettyPrinterOperation.ID, new IVisitorFactory() {
public IVisitor create(IOperation operation, int stage) {
return new ModelsPrettyPrinterVisitor((PrettyPrinterOperation) operation);
}
});
platform.addOperationFactory(ModelsLanguageKit.URI, ValidatorOperation.ID, new IVisitorFactory() {
public IVisitor create(IOperation operation, int stage) {
return new ModelsValidatorVisitor();
}
});
platform.addOperationFactory(ModelsLanguageKit.URI, InterpreterOperation.ID, new IVisitorFactory() {
public IVisitor create(IOperation operation, int stage) {
if (stage == 0)
return new ModelsInterpreterVisitor();
else
return null;
}
});
platform.addOperationFactory(ModelsLanguageKit.URI, NormalizerOperation.ID, new IVisitorFactory() {
public IVisitor create(IOperation operation, int stage) {
return new ModelsNormalizerVisitor();
}
});
}
Aggregations