Skip to content

Commit

Permalink
GH-556 Rename pipeline to parser pool and improve stage api by stage …
Browse files Browse the repository at this point in the history
…service
  • Loading branch information
dzikoysk committed Oct 1, 2020
1 parent 666c1f7 commit c5eda0e
Show file tree
Hide file tree
Showing 85 changed files with 974 additions and 1,325 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
import org.panda_lang.language.architecture.statement.Scope;
import org.panda_lang.language.architecture.module.TypeLoader;
import org.panda_lang.language.interpreter.parser.expression.ExpressionParser;
import org.panda_lang.language.interpreter.parser.stage.StageController;
import org.panda_lang.language.interpreter.parser.pipeline.PipelinePath;
import org.panda_lang.language.interpreter.parser.stage.StageManager;
import org.panda_lang.language.interpreter.parser.pool.ParserPoolService;
import org.panda_lang.language.interpreter.source.SourceSet;
import org.panda_lang.language.interpreter.token.Snippet;
import org.panda_lang.language.interpreter.token.SourceStream;
Expand All @@ -48,12 +48,12 @@ public final class Components {
/**
* Represents the generation
*/
public static final ContextComponent<StageController> GENERATION = ContextComponent.of("generation", StageController.class);
public static final ContextComponent<StageManager> STAGE = ContextComponent.of("generation", StageManager.class);

/**
* Represents the pipeline path with all registered pipelines
*/
public static final ContextComponent<PipelinePath> PIPELINE = ContextComponent.of("pipeline-path", PipelinePath.class);
public static final ContextComponent<ParserPoolService> PIPELINE = ContextComponent.of("pipeline-path", ParserPoolService.class);

/**
* Represents the main expression parser with all registered subparsers
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,32 +16,63 @@

package org.panda_lang.language.interpreter.parser;

import java.util.Map;
import org.panda_lang.language.FrameworkController;
import org.panda_lang.language.architecture.Application;
import org.panda_lang.language.architecture.Environment;
import org.panda_lang.language.architecture.Script;
import org.panda_lang.language.architecture.module.Imports;
import org.panda_lang.language.architecture.module.TypeLoader;
import org.panda_lang.language.architecture.statement.Scope;
import org.panda_lang.language.interpreter.logging.LoggerHolder;
import org.panda_lang.language.interpreter.parser.expression.ExpressionParser;
import org.panda_lang.language.interpreter.parser.pool.ParserPoolService;
import org.panda_lang.language.interpreter.parser.stage.StageService;
import org.panda_lang.language.interpreter.source.SourceSet;
import org.panda_lang.language.interpreter.token.Snippet;
import org.panda_lang.language.interpreter.token.SourceStream;

/**
* Component based set of data used during the interpretation process
*/
public interface Context extends Contextual {
public interface Context<T> extends Contextual<T>, LoggerHolder {

/**
* Clone context to a new independent instance
*/
Context fork();
Context<T> fork();

/**
* @param componentName a name of the specified component
*/
<T> Context withComponent(ContextComponent<T> componentName, T component);
ContextCreator<T> forkCreator();

/***
* @param componentName a name of the specified component
* @return selected component
*/
<T> T getComponent(ContextComponent<T> componentName);
T getSubject();

/**
* @return all components stored in the current parser data
*/
Map<? extends ContextComponent<?>, ? extends Object> getComponents();
SourceStream getStream();

LocalChannel getChannel();

Snippet getSource();

Scope getScope();

Imports getImports();

Snippet getScriptSource();

Script getScript();

SourceSet getSourceSet();

Application getApplication();

TypeLoader getTypeLoader();

ExpressionParser getExpressionParser();

ParserPoolService getPoolService();

StageService getStageService();

Environment getEnvironment();

FrameworkController getFrameworkController();

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package org.panda_lang.language.interpreter.parser;

import org.panda_lang.language.architecture.Script;
import org.panda_lang.language.architecture.module.Imports;
import org.panda_lang.language.architecture.statement.Scope;
import org.panda_lang.language.interpreter.token.Snippet;
import org.panda_lang.language.interpreter.token.SourceStream;

public interface ContextCreator<T> extends Contextual<T> {

ContextCreator<T> fork();

ContextCreator<T> withSubject(T subject);

ContextCreator<T> withStream(SourceStream stream);

ContextCreator<T> withSource(Snippet source);

ContextCreator<T> withScope(Scope scope);

ContextCreator<T> withImports(Imports imports);

ContextCreator<T> withScriptSource(Snippet scriptSource);

ContextCreator<T> withScript(Script script);

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,24 @@

package org.panda_lang.language.interpreter.parser;

import org.panda_lang.utilities.commons.function.Option;

import java.util.concurrent.CompletableFuture;

/**
* Represents parsers supported by pipelines
*
* @param <T> type of result
*/
public interface ContextParser<T> extends Parser {
public interface ContextParser<T, R> extends Parser {

default void initialize(Context<T> context) { }

/**
* Parse context
*
* @param context set of information about source and interpretation process
*/
T parse(Context context);
Option<CompletableFuture<R>> parse(Context<T> context);

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@

package org.panda_lang.language.interpreter.parser;

public interface Contextual {
public interface Contextual<T> {

Context toContext();
Context<T> toContext();

}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -16,50 +16,96 @@

package org.panda_lang.language.interpreter.parser;

import java.util.HashMap;
import java.util.Map;
import org.panda_lang.language.FrameworkController;
import org.panda_lang.language.architecture.Application;
import org.panda_lang.language.architecture.Environment;
import org.panda_lang.language.architecture.Script;
import org.panda_lang.language.architecture.module.Imports;
import org.panda_lang.language.architecture.module.TypeLoader;
import org.panda_lang.language.architecture.statement.Scope;
import org.panda_lang.language.interpreter.logging.Logger;
import org.panda_lang.language.interpreter.parser.expression.ExpressionParser;
import org.panda_lang.language.interpreter.parser.pool.ParserPoolService;
import org.panda_lang.language.interpreter.parser.stage.StageService;
import org.panda_lang.language.interpreter.source.SourceSet;
import org.panda_lang.language.interpreter.token.Snippet;
import org.panda_lang.language.interpreter.token.SourceStream;

public final class PandaContext implements Context {
// @formatter:off
public class PandaContext<T> implements Context<T> {

private final Map<ContextComponent<?>, Object> components;
protected final PandaContextCreator<T> creator;

private PandaContext(Map<ContextComponent<?>, Object> components) {
this.components = components;
protected PandaContext(PandaContextCreator<T> creator) {
this.creator = creator;
}

public PandaContext() {
this(new HashMap<>());
@Override
public PandaContext<T> fork() {
return new PandaContext<T>(creator.fork());
}

@Override
public PandaContext fork() {
return new PandaContext(new HashMap<>(components));
public ContextCreator<T> forkCreator() {
return creator.fork();
}

@Override
public <T> PandaContext withComponent(ContextComponent<T> component, T value) {
this.components.put(component, value);
public Context<T> toContext() {
return this;
}

/**
* @param componentName a name of the specified component
* @return selected component
*/
@Override
@SuppressWarnings({ "unchecked" })
public <T> T getComponent(ContextComponent<T> componentName) {
return (T) components.get(componentName);
public Logger getLogger() {
return getFrameworkController().getLogger();
}

@Override
public Map<? extends ContextComponent<?>, ? extends Object> getComponents() {
return new HashMap<>(components);
}
public T getSubject() { return creator.subject; }

@Override
public Context toContext() {
return this;
}
public SourceStream getStream() { return creator.stream; }

@Override
public LocalChannel getChannel() { return creator.channel; }

@Override
public Snippet getSource() { return creator.source; }

@Override
public Scope getScope() { return creator.scope; }

@Override
public Imports getImports() { return creator.imports; }

@Override
public Snippet getScriptSource() { return creator.scriptSource; }

@Override
public Script getScript() { return creator.script; }

@Override
public SourceSet getSourceSet() { return creator.sourceSet; }

@Override
public Application getApplication() { return creator.application; }

@Override
public TypeLoader getTypeLoader() { return creator.typeLoader; }

@Override
public ExpressionParser getExpressionParser() { return creator.expressionParser; }

@Override
public ParserPoolService getPoolService() { return creator.parserPoolService; }

@Override
public StageService getStageService() { return creator.stageService; }

@Override
public Environment getEnvironment() { return creator.environment; }

@Override
public FrameworkController getFrameworkController() { return creator.frameworkController; }

}
Loading

0 comments on commit c5eda0e

Please sign in to comment.