Commit dfbe78b5 authored by Custom2043's avatar Custom2043
Browse files

Add strictString

parent b726ffb8
No preview for this file type
......@@ -146,4 +146,14 @@ public class ParserCharacter
return true;
return false;
}
public boolean isStrict()
{
return !not && rangeStart.length == 1 && !needsEnd();
}
public char getStrictCharacter()
{
return this.rangeStart[0];
}
}
......@@ -39,6 +39,37 @@ public class ParserStringBuilder extends TokenBuilder
public ParserString getParserString(Result[] results)
{
return (ParserString)results[0].getToken();
//return (ParserString)results[this.getIgnore() == null ? 0 : 1].getToken();
}
public boolean isStringCorrect(String s)
{
int i = 0;
if (s.length() < ParserString.getString(index).length)
return false;
for (ParserCharacter pc : ParserString.getString(index))
if (pc.isCharCorrect(s.charAt(i++)))
return false;
return true;
}
public boolean isStrict()
{
for (ParserCharacter pc : ParserString.getString(index))
if (pc.isStrict())
return false;
return true;
}
public String getStrictString()
{
StringBuilder builder = new StringBuilder();
for (ParserCharacter pc : ParserString.getString(index))
builder.append(pc.getStrictCharacter());
return builder.toString();
}
}
package parser;
import java.lang.reflect.Array;
import java.lang.reflect.Field;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
public class TokenCreator
{
static void fill(List<Token> totalList, Result result, Token build, LinkedList<Integer> pos, LinkedList<Integer> max) throws Exception
{
if (result.getArray() == null && result.getToken() == null) // Probably optionnal search
{
if (result.getSearch().getSearchName() != null)
write(build, result.getSearch().getSearchName(), pos, max, result);
if (result.getSearch() instanceof MultipleSearch) // Optionnal search
{
System.out.println("Null : "+result.getSearch());
Search[] ss = ((MultipleSearch)result.getSearch()).getSearches();
for (int i=0;i<ss.length;i++)
{
/*System.out.println("In : "+ss[i]);
if (ss[i] instanceof ArraySearch)
{
pos.add(0);
max.add(0);
for (Search s : ((ArraySearch)ss[i]).getSearches())
{
if (s instanceof OrSearch)
{
for (Search ssss : ((OrSearch)s).getSearches())
if (ssss.getSearchName() != null)
write(build, ssss.getSearchName(), pos, max, null);
}
else
if (s.getSearchName() != null)
write(build, s.getSearchName(), pos, max, null);
}
max.removeLast();
pos.removeLast();
}*/
if (ss[i] instanceof ArraySearch)
{
pos.add(i);
max.add(ss.length);
}
if (ss[i].getSearchName() != null)
write(build, ss[i].getSearchName(), pos, max, null);
else if (ss[i] instanceof MultipleSearch)
fill(totalList, new Result(ss[i], (Token)null), build, pos, max);
if (ss[i] instanceof MultipleSearch)
{
System.out.println("Search in multiple null : "+ss[i].getClass());
for (Search sss : ((MultipleSearch)ss[i]).getSearches())
if (sss.getSearchName() != null)
{
System.out.println("Write null in : "+sss);
for (int ii : pos)
System.out.println(ii);
for (int ii : max)
System.out.println(ii);
write(build, sss.getSearchName(), pos, max, null);
}
}
if (ss[i] instanceof ArraySearch)
{
max.removeLast();
pos.removeLast();
}
}
}
}
if (result.isToken())
{
if (result.getSearch().getSearchName() != null)
write(build, result.getSearch().getSearchName(), pos, max, result);
totalList.add(result.getToken());
}
else
{
if (result.getSearch().getSearchName() != null)
if (result.getArray() != null)
for (int i=0;i<result.getArray().length;i++)
write(build, result.getSearch().getSearchName(), pos, max, result.getArray()[i]);
if (result.getArray() != null)
for (int i=0;i<result.getArray().length;i++)
{
if (result.getSearch() instanceof ArraySearch)
{
pos.add(i);
max.add(result.getArray().length);
}
fill(totalList, result.getArray()[i], build, pos, max);
if (result.getSearch() instanceof ArraySearch)
{
max.removeLast();
pos.removeLast();
}
}
}
}
private static void write(Token build, String to, List<Integer> pos, List<Integer> max, Result toWrite) throws Exception
{
if (pos.isEmpty())
{
Field f = build.getClass().getDeclaredField(to);
boolean assignable = Token.class.isAssignableFrom(f.getType());
if (assignable && toWrite != null && toWrite.isToken())
f.set(build, toWrite.getToken());
else if (assignable && toWrite != null && toWrite.getSearch() instanceof BracketSearch && toWrite.getArray().length == 1)
f.set(build, toWrite.getArray()[0].getToken());
else
f.set(build, toWrite);
}
else
{
Object[] current, total;
Class<?> currentType = build.getClass().getDeclaredField(to).getType().getComponentType();
current = total = (Object[])build.getClass().getDeclaredField(to).get(build);
Iterator<Integer> maxs = max.iterator(), poss = pos.iterator();
int m = maxs.next();
if (current == null)
{
current = total = (Object[])Array.newInstance(currentType, m);
if (currentType.getComponentType() != null)
currentType = currentType.getComponentType();
}
for (;maxs.hasNext();)
{
m = maxs.next();
int p = poss.next();
if (current[p] == null)
current = (Object[])(current[p] = Array.newInstance(currentType, m));
else
current = (Object[])current[p];
if (currentType.getComponentType() != null)
currentType = currentType.getComponentType();
}
boolean assignable = Token.class.isAssignableFrom(currentType);
if (assignable && toWrite != null && toWrite.isToken())
current[poss.next()] = toWrite.getToken();
else if (assignable && toWrite != null && toWrite.getSearch() instanceof BracketSearch && toWrite.getArray().length == 1)
current[poss.next()] = toWrite.getArray()[0].getToken();
else// if (current.length > 0)
current[poss.next()] = toWrite;
build.getClass().getDeclaredField(to).set(build, total);
}
}
}
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