Model und ModelImpl

This commit is contained in:
uogau 2021-01-27 21:59:39 +01:00
parent 143999d6e9
commit a7bcf15c99
2 changed files with 60 additions and 0 deletions

View File

@ -0,0 +1,21 @@
package edu.kit.typicalc.model;
import java.util.Map;
import edu.kit.typicalc.model.parser.ParseError;
import edu.kit.typicalc.util.Result;
/**
* This interface accepts user input and returns a type inference result.
*/
public interface Model {
/**
* Given the user input, an implementation of this method should compute the type
* inference results.
* @param lambdaTerm the lambda term to type-infer
* @param typeAssumptions the type assumptions to use
* @return either an error or a TypeInfererInterface on success
*/
Result<TypeInfererInterface, ParseError> getTypeInferer(String lambdaTerm,
Map<String, String> typeAssumptions);
}

View File

@ -0,0 +1,39 @@
package edu.kit.typicalc.model;
import edu.kit.typicalc.model.parser.LambdaParser;
import edu.kit.typicalc.model.parser.ParseError;
import edu.kit.typicalc.model.term.LambdaTerm;
import edu.kit.typicalc.util.Result;
import java.util.Map;
/**
* Accepts user input and returns a type inference result.
*/
public class ModelImpl implements Model {
/**
*Parses the user input given as the lambdaTerm and typeAssumptions and creates
* a TypeInferer object.
* @param lambdaTerm the lambda term to type-infer
* @param typeAssumptions the type assumptions to use
* @return A TypeInferer object that has calculated the type Inference for the given Lambda Term
* and type Assumptions
*
*/
@Override
public Result<TypeInfererInterface, ParseError> getTypeInferer(String lambdaTerm,
Map<String, String> typeAssumptions) {
// Parse Lambda Term
LambdaParser parser = new LambdaParser(lambdaTerm);
Result<LambdaTerm, ParseError> result = parser.parse();
if (result.isError()) {
return new Result<>(null, result.unwrapError());
}
//TODO: Parse Type Assumptions and add list to typeInferer
//Create and return TypeInferer
TypeInferer typeInferer = new TypeInferer(result.unwrap(), null);
return new Result<>(typeInferer, null);
}
}