PAN-64 Refactored ParserService.
This commit is contained in:
@@ -39,10 +39,8 @@ class ParserService {
|
|||||||
return root;
|
return root;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void recurse(final Node current)
|
public void recurse(final Node current)
|
||||||
{
|
{
|
||||||
int startIndex;
|
|
||||||
int endIndex;
|
|
||||||
final String statement;
|
final String statement;
|
||||||
|
|
||||||
if (current != null) {
|
if (current != null) {
|
||||||
@@ -51,10 +49,28 @@ class ParserService {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
String nextStatement;
|
|
||||||
|
|
||||||
if(statement.contains("let"))
|
if(statement.contains("let"))
|
||||||
{
|
{
|
||||||
|
separateByLet(current, statement);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(statement.contains("if"))
|
||||||
|
{
|
||||||
|
separateByIf(current, statement);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if(current.getStatement().contains("then"))
|
||||||
|
{
|
||||||
|
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));
|
current.setLeft(new Node("let", current));
|
||||||
|
|
||||||
startIndex = statement.indexOf("let")+"let".length();
|
startIndex = statement.indexOf("let")+"let".length();
|
||||||
@@ -73,9 +89,11 @@ class ParserService {
|
|||||||
recurse(current.getLeft().getCenter());
|
recurse(current.getLeft().getCenter());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void separateByIf(final Node current, final String statement){
|
||||||
|
final int startIndex;
|
||||||
|
final int endIndex;
|
||||||
|
final String nextStatement;
|
||||||
|
|
||||||
if(statement.contains("if"))
|
|
||||||
{
|
|
||||||
current.setCenter(new Node("if", current));
|
current.setCenter(new Node("if", current));
|
||||||
|
|
||||||
startIndex = statement.indexOf("if")+"if".length();
|
startIndex = statement.indexOf("if")+"if".length();
|
||||||
@@ -86,9 +104,10 @@ class ParserService {
|
|||||||
recurse(current.getCenter().getCenter());
|
recurse(current.getCenter().getCenter());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void separateByThen(final Node current, final String statement){
|
||||||
|
final int startIndex;
|
||||||
|
final String nextStatement;
|
||||||
|
|
||||||
if(current.getStatement().contains("then"))
|
|
||||||
{
|
|
||||||
current.setRight(new Node("then", current));
|
current.setRight(new Node("then", current));
|
||||||
|
|
||||||
startIndex = statement.indexOf("then")+"then".length();
|
startIndex = statement.indexOf("then")+"then".length();
|
||||||
@@ -97,14 +116,13 @@ class ParserService {
|
|||||||
current.getRight().setCenter(new Node(nextStatement, current.getRight()));
|
current.getRight().setCenter(new Node(nextStatement, current.getRight()));
|
||||||
recurse(current.getRight().getCenter());
|
recurse(current.getRight().getCenter());
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public List<String> retrieveStatements(final Node parsedTree)
|
public List<String> retrieveStatements(final Node parsedTree)
|
||||||
{
|
{
|
||||||
return populateStatementList(parsedTree, new ArrayList<>());
|
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)
|
if(node == null)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user