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"
Identifier = firstLetter:letter [{idName:(letter|digit)}]
ignore = {Space|Jump}
SearchName = [notGenerated:nonGeneratedName] id:Identifier ":"
SearchName = [list:transientToken] [notGenerated:nonGeneratedName] id:Identifier ":"
LineHeader = [trans:transientToken] id:Identifier equals
TokenSearchToken = ([trans:transientToken [included:nonGeneratedName]] id:Identifier)|string:StringToken
......
T = {"a" [b:"b" [c:"c"]]}
T = "a"
......@@ -249,6 +249,8 @@ public class ClassGenerator
builder.append("\"");
builder.append(name.id.getName());
builder.append("\", ");
builder.append(name.list);
builder.append(", ");
}
}
}
......@@ -21,47 +21,47 @@ public class ArraySearch extends MultipleSearch
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)
{
this(null, min, max, s);
this(null, false, min, max, 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)
{
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.rightSearches = rS;
this.minSize = min;
......@@ -200,7 +200,7 @@ public class ArraySearch extends MultipleSearch
if (rightWithIgnored.size() > 0)
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()]),
coreWithIgnored.toArray(new Search[coreWithIgnored.size()]),
rightWithIgnored.toArray(new Search[rightWithIgnored.size()])
......
......@@ -5,14 +5,14 @@ package parser;
*/
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)
{
this((String)null, searches);
this((String)null, false, searches);
}
@Override
......@@ -30,6 +30,6 @@ public class BracketSearch extends MultipleSearch
@Override
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;
public abstract class MultipleSearch extends Search
{
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;
}
......
......@@ -2,13 +2,13 @@ package parser;
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)
{
this(null, s);
this(null, false, s);
}
/**
......@@ -34,6 +34,6 @@ public class OptionalSearch extends MultipleSearch
@Override
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
{
public OrSearch(Search... searches)
{
super(null, searches);
super(null, false, searches);
}
@Override
......
......@@ -8,9 +8,11 @@ public abstract class Search
{
private Builder declarationBuilder;
private final String searchName;
public Search(String sN)
private final boolean list;
public Search(String sN, boolean list)
{
this.searchName = sN;
this.list = list;
}
public String getSearchName()
{
......@@ -29,6 +31,11 @@ public abstract class Search
*/
public abstract boolean executeSearch(boolean hasCurrent, Token current, int position, Result[] results, Search[] searches);
public boolean isList()
{
return list;
}
@Override
public final String toString()
{
......
......@@ -49,7 +49,7 @@ public abstract class Token
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 nextIgnore;
......
......@@ -2,7 +2,6 @@ package parser;
import java.lang.reflect.Array;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
......@@ -14,14 +13,14 @@ public class TokenCreator
if (result.getSearch() instanceof OptionalSearch && result.getArray() == 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();
for (int i=0;i<ss.length;i++)
{
if (ss[i].getSearchName() != null)
write(build, ss[i].getSearchName(), pos, max, null);
if (ss[i] instanceof ArraySearch)
write(build, ss[i], pos, max, null);
/*if (ss[i] instanceof ArraySearch)
{
pos.add(i);
max.add(0);
......@@ -31,14 +30,14 @@ public class TokenCreator
max.removeLast();
pos.removeLast();
}
}*/
}
}
if (result.isToken())
{
if (result.getSearch().getSearchName() != null)
write(build, result.getSearch().getSearchName(), pos, max, result);
write(build, result.getSearch(), pos, max, result);
totalList.add(result.getToken());
}
......@@ -47,7 +46,7 @@ public class TokenCreator
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]);
write(build, result.getSearch(), pos, max, result.getArray()[i]);
if (result.getArray() != null)
for (int i=0;i<result.getArray().length;i++)
......@@ -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())
{
Field f = build.getClass().getDeclaredField(to);
Field f = build.getClass().getDeclaredField(s.getSearchName());
f.setAccessible(true);
boolean assignable = Token.class.isAssignableFrom(f.getType());
if (assignable && toWrite != null && toWrite.isToken())
......@@ -84,7 +83,7 @@ public class TokenCreator
else
{
Object[] current, total;
Field f = build.getClass().getDeclaredField(to);
Field f = build.getClass().getDeclaredField(s.getSearchName());
Class<?> currentType = f.getType().getComponentType();
f.setAccessible(true);
current = total = (Object[])f.get(build);
......@@ -122,11 +121,11 @@ public class TokenCreator
else
current[i] = toWrite;
//if (i == total.length - 1)
//total = eliminateNulls(total, currentType);
if (s.isList() && i == total.length - 1)
total = eliminateNulls(total, currentType);
// 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
{
field.setAccessible(true);
Field modifiersField = Field.class.getDeclaredField("modifiers");
/*Field modifiersField = Field.class.getDeclaredField("modifiers");
modifiersField.setAccessible(true);
modifiersField.setInt(field, field.getModifiers() & ~Modifier.FINAL);
modifiersField.setInt(field, field.getModifiers() & ~Modifier.FINAL);*/
field.set(to, newValue);
}
......
......@@ -11,19 +11,19 @@ public class TokenSearch extends Search
private final TokenBuilder builder;
private final boolean fromThisLine, isThisLineIncluded;
public TokenSearch(TokenBuilder b) {this(null, b);}
public TokenSearch(TokenBuilder b, boolean included) {this(null, b, true, included);}
public TokenSearch(String searchName, TokenBuilder b)
public TokenSearch(TokenBuilder b) {this(null, false, b);}
public TokenSearch(TokenBuilder b, boolean included) {this(null, false, b, true, included);}
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.fromThisLine = line;
this.isThisLineIncluded = included;
......
......@@ -24,27 +24,27 @@ public class ArraySearchToken extends Token implements MultipleSearchToken
public static final Search builderSearches[] = {
new OptionalSearch(
new ArraySearch(
new TokenSearch("minSize", ParserString.digit)
new TokenSearch("minSize", false, ParserString.digit)
),
new TokenSearch(ParserString.trans17)
),
new TokenSearch(ParserString.arrayOpen),
new OptionalSearch(
new TokenSearch(ParserString.orToken),
new TokenSearch("left", SearchToken.builder)
new TokenSearch("left", false, SearchToken.builder)
),
new ArraySearch(
new TokenSearch("searches", SearchToken.builder)
new TokenSearch("searches", false, SearchToken.builder)
),
new OptionalSearch(
new TokenSearch("right", SearchToken.builder),
new TokenSearch("right", false, SearchToken.builder),
new TokenSearch(ParserString.orToken)
),
new TokenSearch(ParserString.arrayClose),
new OptionalSearch(
new TokenSearch(ParserString.trans18),
new ArraySearch(
new TokenSearch("maxSize", ParserString.digit)
new TokenSearch("maxSize", false, ParserString.digit)
)
)
};
......
......@@ -19,7 +19,7 @@ public class BracketSearchToken extends Token implements MultipleSearchToken
public static final Search builderSearches[] = {
new TokenSearch(ParserString.exprOpen),
new ArraySearch(
new TokenSearch("searches", SearchToken.builder)
new TokenSearch("searches", false, SearchToken.builder)
),
new TokenSearch(ParserString.exprClose)
};
......
......@@ -25,11 +25,11 @@ public class CharacterToken extends Token
public static final Search builderSearches[] = {
new TokenSearch(ParserString.singleQuote),
new OptionalSearch(
new TokenSearch("notToken", ParserString.notToken)
new TokenSearch("notToken", false, ParserString.notToken)
),
new ArraySearch(true, false,
new TokenSearch(ParserString.orToken),
new BracketSearch("character1",
new BracketSearch("character1", false,
new OrSearch(
new TokenSearch(NumberChar.builder),
new TokenSearch(SingleChar.builder)
......@@ -37,7 +37,7 @@ public class CharacterToken extends Token
),
new OptionalSearch(
new TokenSearch(ParserString.trans10),
new BracketSearch("character2",
new BracketSearch("character2", false,
new OrSearch(
new TokenSearch(NumberChar.builder),
new TokenSearch(SingleChar.builder)
......
......@@ -21,10 +21,10 @@ public class Identifier extends Token
public ParserString idName[];
public ParserString firstLetter;
public static final Search builderSearches[] = {
new TokenSearch("firstLetter", ParserString.letter),
new TokenSearch("firstLetter", false, ParserString.letter),
new OptionalSearch(
new ArraySearch(
new BracketSearch("idName",
new BracketSearch("idName", false,
new OrSearch(
new TokenSearch(ParserString.letter),
new TokenSearch(ParserString.digit)
......
......@@ -14,15 +14,15 @@ public class Line extends Token
public LineHeader header;
public ParserString lastIgnore;
public static final Search builderSearches[] = {
new TokenSearch("header", LineHeader.builder),
new TokenSearch("header", false, LineHeader.builder),
new OptionalSearch(
new TokenSearch("firstIgnore", ParserString.ignoreKeyword)
new TokenSearch("firstIgnore", false, ParserString.ignoreKeyword)
),
new ArraySearch(
new TokenSearch("searchTokens", SearchToken.builder)
new TokenSearch("searchTokens", false, SearchToken.builder)
),
new OptionalSearch(
new TokenSearch("lastIgnore", ParserString.ignoreKeyword)
new TokenSearch("lastIgnore", false, ParserString.ignoreKeyword)
)
};
......
......@@ -19,9 +19,9 @@ public class LineHeader extends Token
public ParserString trans;
public static final Search builderSearches[] = {
new OptionalSearch(
new TokenSearch("trans", ParserString.transientToken)
new TokenSearch("trans", false, ParserString.transientToken)
),
new TokenSearch("id", Identifier.builder),
new TokenSearch("id", false, Identifier.builder),
new TokenSearch(ParserString.equals)
};
......
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