Compare commits
No commits in common. "d319163f60dd7014f298466a1a52999ac2337703" and "d93c8c0f935f55ffd377f18d3d3e8c847de47efe" have entirely different histories.
d319163f60
...
d93c8c0f93
4 changed files with 36 additions and 58 deletions
|
@ -57,21 +57,17 @@ public class Annotation extends JavaElement{
|
|||
|
||||
@Override
|
||||
public <E extends JavaElement> E find(Function<JavaElement, Boolean> finder){
|
||||
if(this.values != null){
|
||||
for(Value value : this.values.values()){
|
||||
if(finder.apply(value)) return (E)value;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <E extends JavaElement> void findAll(Function<JavaElement, Boolean> finder, List<E> list){
|
||||
if(this.values != null){
|
||||
for(Value value : this.values.values()){
|
||||
if(finder.apply(value)) list.add((E)value);
|
||||
value.findAll(finder, list);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,10 +23,7 @@ import dev.peerat.parser.TokenValidator;
|
|||
import dev.peerat.parser.Tokenizer;
|
||||
import dev.peerat.parser.java.Annotation.AnnotableBuffer;
|
||||
import dev.peerat.parser.java.Function.FunctionContainer;
|
||||
import dev.peerat.parser.java.Operation.OperationContainer;
|
||||
import dev.peerat.parser.java.Value.BiValue;
|
||||
import dev.peerat.parser.java.Variable.VariableContainer;
|
||||
import dev.peerat.parser.java.operation.ReturnOperation;
|
||||
import dev.peerat.parser.state.BuilderStateTree;
|
||||
import dev.peerat.parser.state.InitialStateTree;
|
||||
import dev.peerat.parser.state.RedirectStateTree;
|
||||
|
@ -91,24 +88,6 @@ public class JavaParser extends Parser<JavaElement> {
|
|||
token = new Token(lineNumber, i+1, value, TokenType.STRING);
|
||||
i = j-1;
|
||||
System.out.println(token);
|
||||
}else if(c == '\''){
|
||||
String value = "'";
|
||||
int j = i+1;
|
||||
for(; j < line.length(); j++){
|
||||
c = line.charAt(j);
|
||||
if(c == '\''){
|
||||
value+=c;
|
||||
j++;
|
||||
break;
|
||||
}else if(c == '\\'){
|
||||
value+=c+line.charAt(++j);
|
||||
}else{
|
||||
value+=c;
|
||||
}
|
||||
}
|
||||
token = new Token(lineNumber, i+1, value, TokenType.CHAR);
|
||||
i = j-1;
|
||||
System.out.println(token);
|
||||
}else{
|
||||
if(c == '/' && (i < line.length()-1 && line.charAt(i+1) == '/')) break;
|
||||
if(c == '/' && (i < line.length()-1 && line.charAt(i+1) == '*')){
|
||||
|
@ -220,18 +199,17 @@ public class JavaParser extends Parser<JavaElement> {
|
|||
|
||||
//VALUE
|
||||
BiFunction<JavaElement, Bag, JavaElement> value_builder = (parent, bag) -> {
|
||||
System.out.println(bag);
|
||||
if(bag.has("right")){
|
||||
|
||||
BiValue result = new BiValue(
|
||||
|
||||
bag.get("left"),
|
||||
|
||||
bag.get("action"),
|
||||
|
||||
bag.get("right"));
|
||||
bag.set(result);
|
||||
}
|
||||
// if(bag.has("right")){
|
||||
//
|
||||
// BiValue result = new BiValue(
|
||||
//
|
||||
// bag.get("left"),
|
||||
//
|
||||
// bag.get("action"),
|
||||
//
|
||||
// bag.get("right"));
|
||||
// bag.set(result);
|
||||
// }
|
||||
return null;
|
||||
};
|
||||
|
||||
|
@ -256,8 +234,21 @@ public class JavaParser extends Parser<JavaElement> {
|
|||
value_list_element.then((validator) -> validator.validate((token) -> token.getValue().equals(",")))
|
||||
.then(value_list_element);
|
||||
|
||||
value.then((validator) -> {
|
||||
if(validator.validate((token) -> token.getValue().equals("'"))){
|
||||
validator.validate((token) -> token.getValue().equals("\\"));
|
||||
|
||||
return
|
||||
validator.validate((token) -> token.getValue().equals("'"))
|
||||
||
|
||||
(validator.validate((token) -> !token.getValue().equals("'"))
|
||||
&& validator.validate((token) -> token.getValue().equals("'")));
|
||||
}
|
||||
return false;
|
||||
}).end();
|
||||
|
||||
value.then((validator) -> validator.validate(
|
||||
(token) -> token.getType().equals(TokenType.STRING) || token.getType().equals(TokenType.CHAR),
|
||||
(token) -> token.getType().equals(TokenType.STRING),
|
||||
(bag, token) -> bag.set(token)))
|
||||
.end((parent,bag) -> {
|
||||
bag.set(new Value(bag.<Token>get()));
|
||||
|
@ -267,7 +258,7 @@ public class JavaParser extends Parser<JavaElement> {
|
|||
StateTree<JavaElement> value_instance = value.then((validator) -> validator.validate((token) -> token.getValue().equals("new")));
|
||||
StateTree<JavaElement> value_name = new StateTree<JavaElement>();
|
||||
value.then(value_name);
|
||||
value_instance.then(new RedirectStateTree<>(value_name, (global, local) -> global.set(local.get())))
|
||||
value_instance.then(new RedirectStateTree<>(value_name, (global, local) -> global.set(null)))
|
||||
.end((a,b) -> a)
|
||||
.then((validator) -> validator.validate((token) -> token.getValue().equals("{")))
|
||||
.end((a,b) -> a)
|
||||
|
@ -557,20 +548,11 @@ public class JavaParser extends Parser<JavaElement> {
|
|||
operation_value.then((validator) -> validator.validate((token) -> token.getValue().equals(","))).then(operation_value);
|
||||
|
||||
StateTree<JavaElement> operation_return = operation.then((validator) -> validator.validate((token) -> token.getValue().equals("return")));
|
||||
operation_return.then(new RedirectStateTree<>(value_container, (global, local) -> global.set(local.get())))
|
||||
operation_return.then(new RedirectStateTree<>(value_container, (global, local) -> global.set(null)))
|
||||
.then((validator) -> validator.validate((token) -> token.getValue().equals(";")))
|
||||
.end((parent,bag) -> {
|
||||
ReturnOperation op = new ReturnOperation(bag.get());
|
||||
if(parent instanceof OperationContainer) ((OperationContainer)parent).addOperation(op);
|
||||
return null;
|
||||
});
|
||||
|
||||
.end((a,b) -> a);
|
||||
operation_return.then((validator) -> validator.validate((token) -> token.getValue().equals(";")))
|
||||
.end((parent,bag) -> {
|
||||
ReturnOperation op = new ReturnOperation(bag.get());
|
||||
if(parent instanceof OperationContainer) ((OperationContainer)parent).addOperation(op);
|
||||
return null;
|
||||
});
|
||||
.end((a,b) -> a);
|
||||
operation.then((validator) -> validator.validate((token) -> token.getValue().equals("throw")))
|
||||
.then(new RedirectStateTree<>(value_container, (global, local) -> global.set(null)))
|
||||
.then((validator) -> validator.validate((token) -> token.getValue().equals(";")))
|
||||
|
|
|
@ -14,7 +14,7 @@ public class WhileOperation extends OperationBag{
|
|||
this.condition = condition;
|
||||
}
|
||||
|
||||
public Value getCondition(){
|
||||
public Value getCondition(){s
|
||||
return this.condition;
|
||||
}
|
||||
|
||||
|
|
|
@ -267,6 +267,6 @@ public class ValueTests {
|
|||
|
||||
@Test
|
||||
void doubleInDouble() throws Exception{
|
||||
JavaElement result = testCase("(jeffcheasey88 == goefra) || (yuzzu == yugs)");
|
||||
JavaElement result = testCase("(jeffcheasey88 == goefra) || (yuzzu == yugs) || (test == \"Content-Disposition: form-data; name=\\\"?\\\"\")");
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue