MeAmAnUsername / pie

Pipelines for Interactive Environments
Apache License 2.0
0 stars 0 forks source link

Create libraries #7

Open MeAmAnUsername opened 4 years ago

MeAmAnUsername commented 4 years ago

pie standard library

module pie:std

// IO, like write file (should be build in?)
func projectRoot() -> path = ... // provides the root of the project, see https://slde.slack.com/archives/C7254SF60/p1593869119193700
func repositoryRoot() -> path = ... // provides the root of the repository. Will need to determine the repository type and then get the root. For git: walk up the tree until you find a .git folder.

Spoofax commons and spoofax 3 are one module because most spoofax commons stuff (strategoRuntime etc) is still spoofax 3

module mb:spoofax

data IStrategoTerm = foreign java org.spoofax.interpreter.terms.IStrategoTerm {}
transient data StrategoRuntime = foreign java mb.stratego.common.StrategoRuntime {
  func invoke(strategyId: string, term: IStrategoTerm) -> IStrategoTerm?
}

func buildStrategoRuntime() -> StrategoRuntime = foreign mb.spoofax.BuildStrategoRuntime

func invokeStrategoStrategy(strategy: string, ast: IStrategoTerm) -> IStrategoTerm = {
  val strategoRuntime = buildStrategoRuntime();
  val result = strategoRuntime.invoke(strategy, ast);
  if (result == null)
    fail "Executing Stratego strategy '$strategy' failed";
  result!
}

data ResourceKey = foreign java mb.resource.ResourceKey {}
data Region = foreign java mb.common.region.Region {}
data CommandOutput = foreign java mb.spoofax.core.language.command.CommandOutput {}

func supplierFrom(key: ResourceKey) -> supplier<string> = foreign java constructor mb.pie.api.ResourceStringSupplier
func getSmallestTermEncompassingRegion(ast: IStrategoTerm, region: Region) -> IStrategoTerm = foreign java mb.jsglr.common.TermTracer#getSmallestTermEncompassingRegion
func termToString(term: IStrategoTerm) -> string = foreign java mb.stratego.common.StrategoUtil#toString
func singleResultCommmandOutput(result: string, description: string) -> CommandOutput = foreign java 

func restrictToRegion(ast: IStrategoTerm, region: Region?) -> IStrategoTerm = {
  if (region != null)
    getSmallestTermEncompassingRegion(ast, region!)
  else
    ast  
}

testing

MeAmAnUsername commented 3 years ago

It may be better to just have libraries follow the Java package structure.