Commit fd06002d authored by Milhomme Allan's avatar Milhomme Allan
Browse files

GNEAY

parent a33500db
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.7
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.source=1.7
File deleted
...@@ -27,7 +27,7 @@ Space = " "|"\t" ...@@ -27,7 +27,7 @@ Space = " "|"\t"
Identifier = firstLetter:letter [{idName:(letter|digit)}] Identifier = firstLetter:letter [{idName:(letter|digit)}]
ignore = {Space|Jump} ignore = {Space|Jump}
SearchName = [notGenerated:nonGeneratedName] id:Identifier ":" SearchName = [list:transientToken] [notGenerated:nonGeneratedName] id:Identifier ":"
LineHeader = [trans:transientToken] id:Identifier equals LineHeader = [trans:transientToken] id:Identifier equals
TokenSearchToken = ([trans:transientToken [included:nonGeneratedName]] id:Identifier)|string:StringToken TokenSearchToken = ([trans:transientToken [included:nonGeneratedName]] id:Identifier)|string:StringToken
......
T = {"a" [b:"b" [c:"c"]]} T = "a"
...@@ -249,6 +249,8 @@ public class ClassGenerator ...@@ -249,6 +249,8 @@ public class ClassGenerator
builder.append("\""); builder.append("\"");
builder.append(name.id.getName()); builder.append(name.id.getName());
builder.append("\", "); builder.append("\", ");
builder.append(name.list);
builder.append(", ");
} }
} }
} }
...@@ -21,47 +21,47 @@ public class ArraySearch extends MultipleSearch ...@@ -21,47 +21,47 @@ public class ArraySearch extends MultipleSearch
public ArraySearch(Search... s) public ArraySearch(Search... s)
{ {
this(null, false, false, s); this(null, false, false, false, s);
} }
public ArraySearch(String name, Search... s) public ArraySearch(String name, boolean list, Search... s)
{ {
this(name, false, false, s); this(name, list, false, false, s);
} }
public ArraySearch(int min, int max, Search... s) public ArraySearch(int min, int max, Search... s)
{ {
this(null, min, max, s); this(null, false, min, max, s);
} }
public ArraySearch(boolean left, boolean right, Search... s) public ArraySearch(boolean left, boolean right, Search... s)
{ {
this(null, left, right, s); this(null, false, left, right, s);
} }
public ArraySearch(boolean left, boolean right, int min, int max, Search... s) public ArraySearch(boolean left, boolean right, int min, int max, Search... s)
{ {
this(null, left, right, min, max, s); this(null, false, left, right, min, max, s);
} }
public ArraySearch(String name, int min, int max, Search... searches) public ArraySearch(String name, boolean list, int min, int max, Search... searches)
{ {
this(name, min, max, new Search[0], searches, new Search[0]); this(name, list, min, max, new Search[0], searches, new Search[0]);
} }
public ArraySearch(String name, boolean left, boolean right, Search... searches) public ArraySearch(String name, boolean list, boolean left, boolean right, Search... searches)
{ {
this(name, left, right, 1, Integer.MAX_VALUE, searches); this(name, list, left, right, 1, Integer.MAX_VALUE, searches);
} }
public ArraySearch(String name, boolean left, boolean right, int min, int max, Search... searches) public ArraySearch(String name, boolean list, boolean left, boolean right, int min, int max, Search... searches)
{ {
this(name, min, max, left ? new Search[] {searches[0]} : new Search[0], getCoreSearches(left, right, searches), right ? new Search[] {searches[searches.length - 1]} : new Search[0]); this(name, list, min, max, left ? new Search[] {searches[0]} : new Search[0], getCoreSearches(left, right, searches), right ? new Search[] {searches[searches.length - 1]} : new Search[0]);
} }
private ArraySearch(String name, int min, int max, Search[] lS, Search[] coreSearch, Search[] rS) private ArraySearch(String name, boolean list, int min, int max, Search[] lS, Search[] coreSearch, Search[] rS)
{ {
super(name, coreSearch); super(name, list, coreSearch);
this.leftSearches = lS; this.leftSearches = lS;
this.rightSearches = rS; this.rightSearches = rS;
this.minSize = min; this.minSize = min;
...@@ -200,7 +200,7 @@ public class ArraySearch extends MultipleSearch ...@@ -200,7 +200,7 @@ public class ArraySearch extends MultipleSearch
if (rightWithIgnored.size() > 0) if (rightWithIgnored.size() > 0)
rightWithIgnored.add(0, ignore.getRealSearch()); rightWithIgnored.add(0, ignore.getRealSearch());
return new ArraySearch(this.getSearchName(), this.minSize, this.maxSize, return new ArraySearch(this.getSearchName(), this.isList(), this.minSize, this.maxSize,
leftWithIgnored.toArray(new Search[leftWithIgnored.size()]), leftWithIgnored.toArray(new Search[leftWithIgnored.size()]),
coreWithIgnored.toArray(new Search[coreWithIgnored.size()]), coreWithIgnored.toArray(new Search[coreWithIgnored.size()]),
rightWithIgnored.toArray(new Search[rightWithIgnored.size()]) rightWithIgnored.toArray(new Search[rightWithIgnored.size()])
......
...@@ -5,14 +5,14 @@ package parser; ...@@ -5,14 +5,14 @@ package parser;
*/ */
public class BracketSearch extends MultipleSearch public class BracketSearch extends MultipleSearch
{ {
public BracketSearch(String searchName, Search... searches) public BracketSearch(String searchName, boolean list, Search... searches)
{ {
super(searchName, searches); super(searchName, list, searches);
} }
public BracketSearch(Search... searches) public BracketSearch(Search... searches)
{ {
this((String)null, searches); this((String)null, false, searches);
} }
@Override @Override
...@@ -30,6 +30,6 @@ public class BracketSearch extends MultipleSearch ...@@ -30,6 +30,6 @@ public class BracketSearch extends MultipleSearch
@Override @Override
MultipleSearch addIgnore(Ignore ignore) MultipleSearch addIgnore(Ignore ignore)
{ {
return new BracketSearch(this.getSearchName(), TokenBuilder.addIgnoresToArray(ignore, this.getSearches())); return new BracketSearch(this.getSearchName(), this.isList(), TokenBuilder.addIgnoresToArray(ignore, this.getSearches()));
} }
} }
...@@ -3,9 +3,9 @@ package parser; ...@@ -3,9 +3,9 @@ package parser;
public abstract class MultipleSearch extends Search public abstract class MultipleSearch extends Search
{ {
private final Search[] searches; private final Search[] searches;
public MultipleSearch(String searchName, Search... searches) public MultipleSearch(String searchName, boolean list, Search... searches)
{ {
super(searchName); super(searchName, list);
this.searches = searches; this.searches = searches;
} }
......
...@@ -2,13 +2,13 @@ package parser; ...@@ -2,13 +2,13 @@ package parser;
public class OptionalSearch extends MultipleSearch public class OptionalSearch extends MultipleSearch
{ {
public OptionalSearch(String searchName, Search... s) public OptionalSearch(String searchName, boolean list, Search... s)
{ {
super(searchName, s); super(searchName, list, s);
} }
public OptionalSearch(Search... s) public OptionalSearch(Search... s)
{ {
this(null, s); this(null, false, s);
} }
/** /**
...@@ -34,6 +34,6 @@ public class OptionalSearch extends MultipleSearch ...@@ -34,6 +34,6 @@ public class OptionalSearch extends MultipleSearch
@Override @Override
MultipleSearch addIgnore(Ignore ignore) MultipleSearch addIgnore(Ignore ignore)
{ {
return new OptionalSearch(this.getSearchName(), TokenBuilder.addIgnoresToArray(ignore, this.getSearches())); return new OptionalSearch(this.getSearchName(), this.isList(), TokenBuilder.addIgnoresToArray(ignore, this.getSearches()));
} }
} }
...@@ -4,7 +4,7 @@ public class OrSearch extends MultipleSearch ...@@ -4,7 +4,7 @@ public class OrSearch extends MultipleSearch
{ {
public OrSearch(Search... searches) public OrSearch(Search... searches)
{ {
super(null, searches); super(null, false, searches);
} }
@Override @Override
......
...@@ -8,9 +8,11 @@ public abstract class Search ...@@ -8,9 +8,11 @@ public abstract class Search
{ {
private Builder declarationBuilder; private Builder declarationBuilder;
private final String searchName; private final String searchName;
public Search(String sN) private final boolean list;
public Search(String sN, boolean list)
{ {
this.searchName = sN; this.searchName = sN;
this.list = list;
} }
public String getSearchName() public String getSearchName()
{ {
...@@ -29,6 +31,11 @@ public abstract class Search ...@@ -29,6 +31,11 @@ public abstract class Search
*/ */
public abstract boolean executeSearch(boolean hasCurrent, Token current, int position, Result[] results, Search[] searches); public abstract boolean executeSearch(boolean hasCurrent, Token current, int position, Result[] results, Search[] searches);
public boolean isList()
{
return list;
}
@Override @Override
public final String toString() public final String toString()
{ {
......
...@@ -49,7 +49,7 @@ public abstract class Token ...@@ -49,7 +49,7 @@ public abstract class Token
private int start, length, line, column, index, containerPosition; private int start, length, line, column, index, containerPosition;
/** /**
* Only make sens in an array * Only make sense in an array
*/ */
private Result previousIgnore; private Result previousIgnore;
private Result nextIgnore; private Result nextIgnore;
......
...@@ -2,7 +2,6 @@ package parser; ...@@ -2,7 +2,6 @@ package parser;
import java.lang.reflect.Array; import java.lang.reflect.Array;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.util.Iterator; import java.util.Iterator;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
...@@ -14,14 +13,14 @@ public class TokenCreator ...@@ -14,14 +13,14 @@ public class TokenCreator
if (result.getSearch() instanceof OptionalSearch && result.getArray() == null) if (result.getSearch() instanceof OptionalSearch && result.getArray() == null)
{ {
if (result.getSearch().getSearchName() != null) if (result.getSearch().getSearchName() != null)
write(build, result.getSearch().getSearchName(), pos, max, result); write(build, result.getSearch(), pos, max, result);
Search[] ss = ((OptionalSearch)result.getSearch()).getSearches(); Search[] ss = ((OptionalSearch)result.getSearch()).getSearches();
for (int i=0;i<ss.length;i++) for (int i=0;i<ss.length;i++)
{ {
if (ss[i].getSearchName() != null) if (ss[i].getSearchName() != null)
write(build, ss[i].getSearchName(), pos, max, null); write(build, ss[i], pos, max, null);
if (ss[i] instanceof ArraySearch) /*if (ss[i] instanceof ArraySearch)
{ {
pos.add(i); pos.add(i);
max.add(0); max.add(0);
...@@ -31,14 +30,14 @@ public class TokenCreator ...@@ -31,14 +30,14 @@ public class TokenCreator
max.removeLast(); max.removeLast();
pos.removeLast(); pos.removeLast();
} }*/
} }
} }
if (result.isToken()) if (result.isToken())
{ {
if (result.getSearch().getSearchName() != null) if (result.getSearch().getSearchName() != null)
write(build, result.getSearch().getSearchName(), pos, max, result); write(build, result.getSearch(), pos, max, result);
totalList.add(result.getToken()); totalList.add(result.getToken());
} }
...@@ -47,7 +46,7 @@ public class TokenCreator ...@@ -47,7 +46,7 @@ public class TokenCreator
if (result.getSearch().getSearchName() != null) if (result.getSearch().getSearchName() != null)
if (result.getArray() != null) if (result.getArray() != null)
for (int i=0;i<result.getArray().length;i++) for (int i=0;i<result.getArray().length;i++)
write(build, result.getSearch().getSearchName(), pos, max, result.getArray()[i]); write(build, result.getSearch(), pos, max, result.getArray()[i]);
if (result.getArray() != null) if (result.getArray() != null)
for (int i=0;i<result.getArray().length;i++) for (int i=0;i<result.getArray().length;i++)
...@@ -67,11 +66,11 @@ public class TokenCreator ...@@ -67,11 +66,11 @@ public class TokenCreator
} }
} }
private static void write(Token build, String to, LinkedList<Integer> pos, LinkedList<Integer> max, Result toWrite) throws Exception private static void write(Token build, Search s, LinkedList<Integer> pos, LinkedList<Integer> max, Result toWrite) throws Exception
{ {
if (pos.isEmpty()) if (pos.isEmpty())
{ {
Field f = build.getClass().getDeclaredField(to); Field f = build.getClass().getDeclaredField(s.getSearchName());
f.setAccessible(true); f.setAccessible(true);
boolean assignable = Token.class.isAssignableFrom(f.getType()); boolean assignable = Token.class.isAssignableFrom(f.getType());
if (assignable && toWrite != null && toWrite.isToken()) if (assignable && toWrite != null && toWrite.isToken())
...@@ -84,7 +83,7 @@ public class TokenCreator ...@@ -84,7 +83,7 @@ public class TokenCreator
else else
{ {
Object[] current, total; Object[] current, total;
Field f = build.getClass().getDeclaredField(to); Field f = build.getClass().getDeclaredField(s.getSearchName());
Class<?> currentType = f.getType().getComponentType(); Class<?> currentType = f.getType().getComponentType();
f.setAccessible(true); f.setAccessible(true);
current = total = (Object[])f.get(build); current = total = (Object[])f.get(build);
...@@ -122,11 +121,11 @@ public class TokenCreator ...@@ -122,11 +121,11 @@ public class TokenCreator
else else
current[i] = toWrite; current[i] = toWrite;
//if (i == total.length - 1) if (s.isList() && i == total.length - 1)
//total = eliminateNulls(total, currentType); total = eliminateNulls(total, currentType);
// Uncomment to behave like a stack // Uncomment to behave like a stack
setFieldValue(build, build.getClass().getDeclaredField(to), total); setFieldValue(build, build.getClass().getDeclaredField(s.getSearchName()), total);
} }
} }
...@@ -152,9 +151,9 @@ public class TokenCreator ...@@ -152,9 +151,9 @@ public class TokenCreator
{ {
field.setAccessible(true); field.setAccessible(true);
Field modifiersField = Field.class.getDeclaredField("modifiers"); /*Field modifiersField = Field.class.getDeclaredField("modifiers");
modifiersField.setAccessible(true); modifiersField.setAccessible(true);
modifiersField.setInt(field, field.getModifiers() & ~Modifier.FINAL); modifiersField.setInt(field, field.getModifiers() & ~Modifier.FINAL);*/
field.set(to, newValue); field.set(to, newValue);
} }
......
...@@ -11,19 +11,19 @@ public class TokenSearch extends Search ...@@ -11,19 +11,19 @@ public class TokenSearch extends Search
private final TokenBuilder builder; private final TokenBuilder builder;
private final boolean fromThisLine, isThisLineIncluded; private final boolean fromThisLine, isThisLineIncluded;
public TokenSearch(TokenBuilder b) {this(null, b);} public TokenSearch(TokenBuilder b) {this(null, false, b);}
public TokenSearch(TokenBuilder b, boolean included) {this(null, b, true, included);} public TokenSearch(TokenBuilder b, boolean included) {this(null, false, b, true, included);}
public TokenSearch(String searchName, TokenBuilder b) public TokenSearch(String searchName, boolean list, TokenBuilder b)
{ {
this(searchName, b, false, false); this(searchName, list, b, false, false);
} }
public TokenSearch(String searchName, TokenBuilder b, boolean included) public TokenSearch(String searchName, boolean list, TokenBuilder b, boolean included)
{ {
this(searchName, b, true, included); this(searchName, list, b, true, included);
} }
private TokenSearch(String searchName, TokenBuilder b, boolean line, boolean included) private TokenSearch(String searchName, boolean list, TokenBuilder b, boolean line, boolean included)
{ {
super(searchName); super(searchName, list);
this.builder = b; this.builder = b;
this.fromThisLine = line; this.fromThisLine = line;
this.isThisLineIncluded = included; this.isThisLineIncluded = included;
......
...@@ -24,27 +24,27 @@ public class ArraySearchToken extends Token implements MultipleSearchToken ...@@ -24,27 +24,27 @@ public class ArraySearchToken extends Token implements MultipleSearchToken
public static final Search builderSearches[] = { public static final Search builderSearches[] = {
new OptionalSearch( new OptionalSearch(
new ArraySearch( new ArraySearch(
new TokenSearch("minSize", ParserString.digit) new TokenSearch("minSize", false, ParserString.digit)
), ),
new TokenSearch(ParserString.trans17) new TokenSearch(ParserString.trans17)
), ),
new TokenSearch(ParserString.arrayOpen), new TokenSearch(ParserString.arrayOpen),
new OptionalSearch( new OptionalSearch(
new TokenSearch(ParserString.orToken), new TokenSearch(ParserString.orToken),
new TokenSearch("left", SearchToken.builder) new TokenSearch("left", false, SearchToken.builder)
), ),
new ArraySearch( new ArraySearch(
new TokenSearch("searches", SearchToken.builder) new TokenSearch("searches", false, SearchToken.builder)
), ),
new OptionalSearch( new OptionalSearch(
new TokenSearch("right", SearchToken.builder), new TokenSearch("right", false, SearchToken.builder),
new TokenSearch(ParserString.orToken) new TokenSearch(ParserString.orToken)
), ),
new TokenSearch(ParserString.arrayClose), new TokenSearch(ParserString.arrayClose),
new OptionalSearch( new OptionalSearch(
new TokenSearch(ParserString.trans18), new TokenSearch(ParserString.trans18),
new ArraySearch( new ArraySearch(
new TokenSearch("maxSize", ParserString.digit) new TokenSearch("maxSize", false, ParserString.digit)
) )
) )
}; };
......
...@@ -19,7 +19,7 @@ public class BracketSearchToken extends Token implements MultipleSearchToken ...@@ -19,7 +19,7 @@ public class BracketSearchToken extends Token implements MultipleSearchToken
public static final Search builderSearches[] = { public static final Search builderSearches[] = {
new TokenSearch(ParserString.exprOpen), new TokenSearch(ParserString.exprOpen),
new ArraySearch( new ArraySearch(
new TokenSearch("searches", SearchToken.builder) new TokenSearch("searches", false, SearchToken.builder)
), ),
new TokenSearch(ParserString.exprClose) new TokenSearch(ParserString.exprClose)
}; };
......
...@@ -25,11 +25,11 @@ public class CharacterToken extends Token ...@@ -25,11 +25,11 @@ public class CharacterToken extends Token
public static final Search builderSearches[] = { public static final Search builderSearches[] = {
new TokenSearch(ParserString.singleQuote), new TokenSearch(ParserString.singleQuote),
new OptionalSearch( new OptionalSearch(
new TokenSearch("notToken", ParserString.notToken) new TokenSearch("notToken", false, ParserString.notToken)
), ),
new ArraySearch(true, false, new ArraySearch(true, false,
new TokenSearch(ParserString.orToken), new TokenSearch(ParserString.orToken),
new BracketSearch("character1", new BracketSearch("character1", false,
new OrSearch( new OrSearch(
new TokenSearch(NumberChar.builder), new TokenSearch(NumberChar.builder),
new TokenSearch(SingleChar.builder) new TokenSearch(SingleChar.builder)
...@@ -37,7 +37,7 @@ public class CharacterToken extends Token ...@@ -37,7 +37,7 @@ public class CharacterToken extends Token
), ),
new OptionalSearch( new OptionalSearch(
new TokenSearch(ParserString.trans10), new TokenSearch(ParserString.trans10),
new BracketSearch("character2", new BracketSearch("character2", false,
new OrSearch( new OrSearch(
new TokenSearch(NumberChar.builder), new TokenSearch(NumberChar.builder),
new TokenSearch(SingleChar.builder) new TokenSearch(SingleChar.builder)
......
...@@ -21,10 +21,10 @@ public class Identifier extends Token ...@@ -21,10 +21,10 @@ public class Identifier extends Token
public ParserString idName[]; public ParserString idName[];
public ParserString firstLetter; public ParserString firstLetter;
public static final Search builderSearches[] = { public static final Search builderSearches[] = {
new TokenSearch("firstLetter", ParserString.letter),