[Build] Function (signature)
This commit is contained in:
parent
18c2d0cfa1
commit
5394d21552
4 changed files with 74 additions and 7 deletions
|
@ -42,6 +42,10 @@ public class Bag{
|
||||||
return this.map.containsKey(key);
|
return this.map.containsKey(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void remove(String key){
|
||||||
|
this.map.remove(key);
|
||||||
|
}
|
||||||
|
|
||||||
public void set(String key, Object value){
|
public void set(String key, Object value){
|
||||||
this.map.put(key, value);
|
this.map.put(key, value);
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,7 +8,7 @@ public class Function extends JavaElement{
|
||||||
|
|
||||||
private List<Annotation> annotations;
|
private List<Annotation> annotations;
|
||||||
|
|
||||||
private int modifier;
|
private int mod;
|
||||||
private Token generic;
|
private Token generic;
|
||||||
private Token type;
|
private Token type;
|
||||||
private Token name;
|
private Token name;
|
||||||
|
@ -17,6 +17,25 @@ public class Function extends JavaElement{
|
||||||
|
|
||||||
private List<JavaElement> elements;
|
private List<JavaElement> elements;
|
||||||
|
|
||||||
public Function(){}
|
public Function(int mod, Token type, Token name){
|
||||||
|
this.mod = mod;
|
||||||
|
this.type = type;
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Function(int mod, Token generic, Token type, Token name){
|
||||||
|
this(mod, type, name);
|
||||||
|
this.generic = generic;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Function(int mod, Token generic, Token type, Token name, List<Variable> parameters){
|
||||||
|
this(mod, generic, type, name);
|
||||||
|
this.parameters = parameters;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Function(int mod, Token generic, Token type, Token name, List<Variable> parameters, List<Token> throwables){
|
||||||
|
this(mod, generic, type, name, parameters);
|
||||||
|
this.throwables = throwables;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,5 +14,24 @@ public class Variable extends JavaElement{
|
||||||
private boolean elips;
|
private boolean elips;
|
||||||
private Value value;
|
private Value value;
|
||||||
|
|
||||||
public Variable(){}
|
public Variable(int mod, Token type, Token name){
|
||||||
|
this.mod = mod;
|
||||||
|
this.type = type;
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Variable(int mod, Token type, Token name, boolean elips){
|
||||||
|
this(mod, type, name);
|
||||||
|
this.elips = elips;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Variable(int mod, Token type, Token name, boolean elips, Value value){
|
||||||
|
this(mod, type, name, elips);
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString(){
|
||||||
|
return "Variable[mod="+mod+", type="+type+", name="+name+", elips="+elips+", value="+value+"]";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,8 +23,10 @@ public class FunctionTests {
|
||||||
public static StateTree<JavaElement> get(){
|
public static StateTree<JavaElement> get(){
|
||||||
|
|
||||||
BiFunction<JavaElement, Bag, JavaElement> function_builder = (parent, bag) -> {
|
BiFunction<JavaElement, Bag, JavaElement> function_builder = (parent, bag) -> {
|
||||||
System.out.println(bag);
|
buildVariable(bag);
|
||||||
return null;
|
Integer mod = bag.get("mod");
|
||||||
|
Function function = new Function(mod == null ? 0 : mod, bag.get("generic"), bag.get("type"), bag.get("name"), bag.get("param"), bag.get("throws"));
|
||||||
|
return function;
|
||||||
};
|
};
|
||||||
|
|
||||||
InitialStateTree<JavaElement> function = new InitialStateTree<>();
|
InitialStateTree<JavaElement> function = new InitialStateTree<>();
|
||||||
|
@ -71,7 +73,7 @@ public class FunctionTests {
|
||||||
}));
|
}));
|
||||||
BuilderStateTree<JavaElement,JavaElement> function_start_throws = function_throws.then((validator) -> validator.validate((token) -> token.getValue().equals("{"))).end(function_builder);
|
BuilderStateTree<JavaElement,JavaElement> function_start_throws = function_throws.then((validator) -> validator.validate((token) -> token.getValue().equals("{"))).end(function_builder);
|
||||||
// function_start_throws.multiple(function_container);
|
// function_start_throws.multiple(function_container);
|
||||||
function_start_throws.unique((validator) -> validator.validate((token) -> token.getValue().equals("}"))).end((a,b) -> a);
|
function_start_throws.unique((validator) -> validator.validate((token) -> token.getValue().equals("}"))).end();
|
||||||
function_throws.then((validator) -> validator.validate((token) -> token.getValue().equals(","))).then(function_throws);
|
function_throws.then((validator) -> validator.validate((token) -> token.getValue().equals(","))).then(function_throws);
|
||||||
function_throws.then((validator) -> validator.validate((token) -> token.getValue().equals(";"))).end(function_builder);
|
function_throws.then((validator) -> validator.validate((token) -> token.getValue().equals(";"))).end(function_builder);
|
||||||
|
|
||||||
|
@ -89,7 +91,9 @@ public class FunctionTests {
|
||||||
validator.validate((token) -> token.getValue().equals(".")) &&
|
validator.validate((token) -> token.getValue().equals(".")) &&
|
||||||
validator.validate((token) -> token.getValue().equals("."), (bag, token) -> bag.set("arg_elips", true)))
|
validator.validate((token) -> token.getValue().equals("."), (bag, token) -> bag.set("arg_elips", true)))
|
||||||
.then(function_arg_name);
|
.then(function_arg_name);
|
||||||
StateTree<JavaElement> function_arg_split = function_arg_name.then((validator) -> validator.validate((token) -> token.getValue().equals(",")));
|
StateTree<JavaElement> function_arg_split = function_arg_name.then((validator) -> validator.validate((token) -> token.getValue().equals(","), (bag, token) -> {
|
||||||
|
buildVariable(bag);
|
||||||
|
}));
|
||||||
function_arg_split.then(function_arg_mod);
|
function_arg_split.then(function_arg_mod);
|
||||||
function_arg_split.then(function_arg_type);
|
function_arg_split.then(function_arg_type);
|
||||||
function_arg_name.then(function_end);
|
function_arg_name.then(function_end);
|
||||||
|
@ -97,6 +101,27 @@ public class FunctionTests {
|
||||||
return function;
|
return function;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void buildVariable(Bag bag){
|
||||||
|
if(!bag.has("arg_name")) return;
|
||||||
|
|
||||||
|
List<Variable> parameters = bag.get("param");
|
||||||
|
if(parameters == null){
|
||||||
|
parameters = new ArrayList<>();
|
||||||
|
bag.set("param", parameters);
|
||||||
|
}
|
||||||
|
|
||||||
|
Integer mod = bag.get("arg_mod");
|
||||||
|
|
||||||
|
Variable variable = new Variable(mod == null ? 0 : mod, bag.<Token>get("arg_type"), bag.<Token>get("arg_name"), bag.get("arg_elips") == Boolean.TRUE);
|
||||||
|
bag.remove("arg_name");
|
||||||
|
bag.remove("arg_mod");
|
||||||
|
bag.remove("arg_type");
|
||||||
|
bag.remove("arg_name");
|
||||||
|
bag.remove("arg_elips");
|
||||||
|
|
||||||
|
parameters.add(variable);
|
||||||
|
}
|
||||||
|
|
||||||
private static Parser<JavaElement> parser = new Parser<JavaElement>(){
|
private static Parser<JavaElement> parser = new Parser<JavaElement>(){
|
||||||
{
|
{
|
||||||
setTokenizer(ModifierTests.TOKENIZER);
|
setTokenizer(ModifierTests.TOKENIZER);
|
||||||
|
|
Loading…
Add table
Reference in a new issue