PAN-64 Refactored ParserService.
This commit is contained in:
@@ -39,10 +39,8 @@ class ParserService {
|
||||
return root;
|
||||
}
|
||||
|
||||
private void recurse(final Node current)
|
||||
public void recurse(final Node current)
|
||||
{
|
||||
int startIndex;
|
||||
int endIndex;
|
||||
final String statement;
|
||||
|
||||
if (current != null) {
|
||||
@@ -51,60 +49,80 @@ class ParserService {
|
||||
return;
|
||||
}
|
||||
|
||||
String nextStatement;
|
||||
|
||||
if(statement.contains("let"))
|
||||
{
|
||||
current.setLeft(new Node("let", current));
|
||||
|
||||
startIndex = statement.indexOf("let")+"let".length();
|
||||
|
||||
if(statement.contains("if")){
|
||||
endIndex = statement.indexOf("if");
|
||||
} else if(statement.contains("then")){
|
||||
endIndex = statement.indexOf("then");
|
||||
} else {
|
||||
endIndex = statement.length();
|
||||
}
|
||||
|
||||
nextStatement = statement.substring(startIndex, endIndex);
|
||||
|
||||
current.getLeft().setCenter(new Node(nextStatement, current.getLeft()));
|
||||
recurse(current.getLeft().getCenter());
|
||||
separateByLet(current, statement);
|
||||
}
|
||||
|
||||
|
||||
if(statement.contains("if"))
|
||||
{
|
||||
current.setCenter(new Node("if", current));
|
||||
|
||||
startIndex = statement.indexOf("if")+"if".length();
|
||||
endIndex = (statement.contains("then") ? statement.indexOf("then") : statement.length());
|
||||
nextStatement = statement.substring(startIndex, endIndex);
|
||||
|
||||
current.getCenter().setCenter(new Node(nextStatement, current.getCenter()));
|
||||
recurse(current.getCenter().getCenter());
|
||||
separateByIf(current, statement);
|
||||
}
|
||||
|
||||
|
||||
if(current.getStatement().contains("then"))
|
||||
{
|
||||
current.setRight(new Node("then", current));
|
||||
|
||||
startIndex = statement.indexOf("then")+"then".length();
|
||||
nextStatement = statement.substring(startIndex);
|
||||
|
||||
current.getRight().setCenter(new Node(nextStatement, current.getRight()));
|
||||
recurse(current.getRight().getCenter());
|
||||
separateByThen(current, statement);
|
||||
}
|
||||
}
|
||||
|
||||
public void separateByLet(final Node current, final String statement){
|
||||
final int startIndex;
|
||||
final int endIndex;
|
||||
final String nextStatement;
|
||||
|
||||
current.setLeft(new Node("let", current));
|
||||
|
||||
startIndex = statement.indexOf("let")+"let".length();
|
||||
|
||||
if(statement.contains("if")){
|
||||
endIndex = statement.indexOf("if");
|
||||
} else if(statement.contains("then")){
|
||||
endIndex = statement.indexOf("then");
|
||||
} else {
|
||||
endIndex = statement.length();
|
||||
}
|
||||
|
||||
nextStatement = statement.substring(startIndex, endIndex);
|
||||
|
||||
current.getLeft().setCenter(new Node(nextStatement, current.getLeft()));
|
||||
recurse(current.getLeft().getCenter());
|
||||
}
|
||||
|
||||
public void separateByIf(final Node current, final String statement){
|
||||
final int startIndex;
|
||||
final int endIndex;
|
||||
final String nextStatement;
|
||||
|
||||
current.setCenter(new Node("if", current));
|
||||
|
||||
startIndex = statement.indexOf("if")+"if".length();
|
||||
endIndex = (statement.contains("then") ? statement.indexOf("then") : statement.length());
|
||||
nextStatement = statement.substring(startIndex, endIndex);
|
||||
|
||||
current.getCenter().setCenter(new Node(nextStatement, current.getCenter()));
|
||||
recurse(current.getCenter().getCenter());
|
||||
}
|
||||
|
||||
public void separateByThen(final Node current, final String statement){
|
||||
final int startIndex;
|
||||
final String nextStatement;
|
||||
|
||||
current.setRight(new Node("then", current));
|
||||
|
||||
startIndex = statement.indexOf("then")+"then".length();
|
||||
nextStatement = statement.substring(startIndex);
|
||||
|
||||
current.getRight().setCenter(new Node(nextStatement, current.getRight()));
|
||||
recurse(current.getRight().getCenter());
|
||||
}
|
||||
|
||||
public List<String> retrieveStatements(final Node parsedTree)
|
||||
{
|
||||
return populateStatementList(parsedTree, new ArrayList<>());
|
||||
}
|
||||
|
||||
private ArrayList<String> populateStatementList(final Node node, final ArrayList<String> statementList)
|
||||
public ArrayList<String> populateStatementList(final Node node, final ArrayList<String> statementList)
|
||||
{
|
||||
if(node == null)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user