Commit 1ea3048b authored by Custom2043's avatar Custom2043
Browse files

add ignored in token and getTotal in result

parent 065591dd
No preview for this file type
......@@ -125,19 +125,20 @@ public class Parser
if (tokenBuilder instanceof ParserStringBuilder)
return ((ParserStringBuilder)tokenBuilder).getParserString(results);
results = tokenBuilder.getResultWithoutIgnores(results);
Result[][] sortedResults = tokenBuilder.separateIgnoreResults(results);
try
{
Token build = tokenBuilder.getTokenClass().getConstructor().newInstance();
LinkedList<Token> total = new LinkedList<>();
for (int i=0;i<results.length;i++)
TokenCreator.fill(total, results[i], build, new LinkedList<Integer>(), new LinkedList<Integer>());
for (int i=0;i<sortedResults[0].length;i++)
TokenCreator.fill(total, sortedResults[0][i], build, new LinkedList<Integer>(), new LinkedList<Integer>());
build.setDatas(start, index-start, getLine(start), Parser.getTokenStartColumn(start), Parser.readFrom(start, index-start), total.toArray(new Token[total.size()]));
build.setDatas(start, index-start, getLine(start), Parser.getTokenStartColumn(start), Parser.readFrom(start, index-start),
total.toArray(new Token[total.size()]), sortedResults[1]);
build.getClass().getDeclaredField("searchResults").set(build, results);
build.getClass().getDeclaredField("searchResults").set(build, sortedResults[0]);
return build;
}
......@@ -179,7 +180,8 @@ public class Parser
if (correct)
{
ParserString string = new ParserString(stringIndex);
string.setDatas(start, index - start, getLine(start), Parser.getTokenStartColumn(start), Parser.readFrom(start, index-start), new Token[0]);
string.setDatas(start, index - start, getLine(start), Parser.getTokenStartColumn(start),
Parser.readFrom(start, index-start), new Token[0], new Result[0]);
return string;
}
......
......@@ -80,4 +80,18 @@ public class Result
tokens.addAll(r.getTokensIn(c));
return tokens;
}
public String getTotal()
{
if (this.isToken)
return this.getToken().getTotal();
if (this.array == null)
return "";
StringBuilder builder = new StringBuilder();
for (Result r : this.array)
builder.append(r.getTotal());
return builder.toString();
}
}
......@@ -49,8 +49,9 @@ public abstract class Token
private int start, length, line, column;
private String total;
private Token[] totalTokens;
private Result[] ignored;
void setDatas(int s, int l, int li, int c, String t, Token[] tokens)
void setDatas(int s, int l, int li, int c, String t, Token[] tokens, Result[] ir)
{
this.start = s;
this.length = l;
......@@ -58,6 +59,7 @@ public abstract class Token
this.column = c;
this.total = t;
this.totalTokens = tokens;
this.ignored = ir;
}
public int getStart()
......@@ -87,6 +89,11 @@ public abstract class Token
return this.totalTokens;
}
public Result[] getIgnoredResults()
{
return this.ignored;
}
@Override
public String toString()
{
......
......@@ -95,6 +95,67 @@ public class TokenBuilder extends Builder
{
return "TokenBuilder of "+this.tokenClass.getName()+" at line "+this.getLine();
}
public Result[][] separateIgnoreResults(Result[] results)
{
return this.separateIgnoreResults(results, this.searchesWithIgnore);
}
private Result[][] separateIgnoreResults(Result[] results, Search[] searchesWithIgnore)
{
if (this.getIgnore() == null || results == null)
return new Result[][] {results, new Result[0]};
List<Result> resultWithoutIgnore = new LinkedList<>(), ignoredResults = new LinkedList<>();
int position = 0;
for (Search s : searchesWithIgnore)
{
if (s != this.ignore.getRealSearch())
{
if (s instanceof ArraySearch)
{
Result[] array = results[position].getArray();
Search[] toSearchIn;
List<Result> r = new LinkedList<>(), rIgnored = new LinkedList<>();
for (int i=0;i<array.length;i++)
{
toSearchIn = ((BracketSearch)array[i].getSearch()).getSearches();
Result[][] sortedResults = this.separateIgnoreResults(array[i].getArray(), toSearchIn);
r.add(new Result(new BracketSearch(toSearchIn), sortedResults[0]));
toSearchIn = new Search[sortedResults[1].length];
for (int j=0;j<toSearchIn.length;j++)
toSearchIn[j] = this.ignore.getRealSearch();
rIgnored.add(new Result(new BracketSearch(toSearchIn), sortedResults[1]));
}
resultWithoutIgnore.add(new Result(s, r.toArray(new Result[r.size()])));
ignoredResults.add(new Result(s, rIgnored.toArray(new Result[r.size()])));
}
else if (s instanceof OrSearch || s instanceof TokenSearch)
{
resultWithoutIgnore.add(results[position]);
}
else if (s instanceof MultipleSearch)
{
Result[][] sortedResults = this.separateIgnoreResults(results[position].getArray(), ((MultipleSearch) s).getSearches());
resultWithoutIgnore.add(new Result(results[position].getSearch(), sortedResults[0]));
ignoredResults.add(new Result(this.ignore.getRealSearch(), sortedResults[1]));
}
}
else
ignoredResults.add(results[position]);
position ++;
}
return new Result[][] {resultWithoutIgnore.toArray(new Result[resultWithoutIgnore.size()]),
ignoredResults.toArray(new Result[ignoredResults.size()])};
}
public Result[] getResultWithoutIgnores(Result[] results)
{
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment