Commit c48863c7 authored by Custom2043's avatar Custom2043
Browse files

doesn't regenerate if not necessary

parent b4e2b439
No preview for this file type
......@@ -19,17 +19,17 @@ notToken = "!"
orToken = "|"
transientToken = "#"
equals = "="
nonGeneratedName = "_"
Jump = "\r\n"|"\r"|"\n"
Space = " "|"\t"
allToken = "*"
Identifier = firstLetter:letter [{idName:(letter|digit)}]
ignore = {Space|Jump}
SearchName = id:Identifier ":"
SearchName = [notGenerated:nonGeneratedName] id:Identifier ":"
LineHeader = [trans:transientToken] id:Identifier equals
TokenSearchToken = ([trans:transientToken] id:Identifier)|string:StringToken|any:"*"
TokenSearchToken = ([trans:transientToken] id:Identifier)|string:StringToken
ArraySearchToken = [{minSize:digit} "-"] arrayOpen [orToken left:SearchToken] {searches:SearchToken} [right:SearchToken orToken] arrayClose ["-" {maxSize:digit}]
OptionalSearchToken = optionOpen {searches:SearchToken} optionClose
BracketSearchToken = exprOpen {searches:SearchToken} exprClose
......
......@@ -81,7 +81,7 @@ public class ClassGenerator
classBuilder.append(Generator.getLineJump());
classBuilder.append(Generator.getLineJump());
classBuilder.append("\tpublic Result searchResults[];");
classBuilder.append(VariableGenerator.generateTokenVariables(l, lines));
classBuilder.append(VariableGenerator.generateTokenVariables(l, lines, existAlready));
classBuilder.append(Generator.getLineJump());
classBuilder.append("\tpublic static final Search builderSearches[] = {");
classBuilder.append(Generator.getLineJump());
......
......@@ -134,7 +134,7 @@ public class Compiler
{
pathForThisName = new SearchNameMemory(level);
pathForThisName.add(level, new SearchPath(currentPath, token));
paths.put(type.searchName.id.getName(), pathForThisName);
paths.put((type.searchName.notGenerated == null ? "" : "_") +type.searchName.id.getName(), pathForThisName);
}
else
{
......
......@@ -58,21 +58,24 @@ public class Generator
for (String s : classToCopy)
{
File f = new File(outputDirectory+"/parser/"+s+".java");
OutputStream fos = new BufferedOutputStream(new FileOutputStream(f));
String ss = new String(getContentFromClass("parser/"+s+".java", true));
fos.write(ss.replace("parser;", Main.pack+"parser;").getBytes());
fos.close();
generatedClasses.add(outputDirectory + "/" + "parser/"+s+".java");
if (!f.exists())
{
OutputStream fos = new BufferedOutputStream(new FileOutputStream(f));
String ss = new String(getContentFromClass("parser/"+s+".java", true));
fos.write(ss.replace("parser;", Main.pack+"parser;").getBytes());
fos.close();
generatedClasses.add(outputDirectory + "/" + "parser/"+s+".java");
}
}
int i=0;
for (Line l : lines)
generateLine(l, lines, i++);
prepareToFill(true, "parser/Ignore.java", IgnoreGenerator.getString());
prepareToFill(true, "parser/Token.java", ClassGenerator.getString());
prepareToFill(true, "parser/ParserString.java", ParserStringGenerator.getString());
prepareToFill(true, "parser/ParserCharacter.java", ParserStringGenerator.getCharacterString());
prepareToFill("parser/Ignore.java", IgnoreGenerator.getString());
prepareToFill("parser/Token.java", ClassGenerator.getString());
prepareToFill("parser/ParserString.java", ParserStringGenerator.getString());
prepareToFill("parser/ParserCharacter.java", ParserStringGenerator.getCharacterString());
}
catch(Exception e)
{
......@@ -90,7 +93,7 @@ public class Generator
File f = new File(outputDirectory+"/tokens/"+l.header.id.getName()+".java");
if (f.exists())
prepareToFill(false, "tokens/"+l.header.id.getName()+".java", ClassGenerator.getTokenString(l, lines, lineIndex, true));
prepareToFill("tokens/"+l.header.id.getName()+".java", ClassGenerator.getTokenString(l, lines, lineIndex, true));
else
{
OutputStream out = new BufferedOutputStream(new FileOutputStream(outputDirectory+"/tokens/"+l.header.id.getName()+".java"));
......@@ -107,6 +110,7 @@ public class Generator
else
ClassGenerator.generateLine(l, lines, lineIndex);
}
/**
* source true if the file is inside current source folder / jar
* else look in the outputDirectory
......@@ -149,8 +153,9 @@ public class Generator
* If replace, we look in the sources
* @throws IOException
*/
private static void prepareToFill(boolean replace, String path, String toPut) throws IOException
private static void prepareToFill(String path, String toPut) throws IOException
{
boolean replace = !new File(outputDirectory + path).exists();
byte[] previousContent = getContentFromClass(path, replace);
if (!searchForParserComment(previousContent))
{
......
......@@ -11,7 +11,7 @@ public class VariableGenerator
{
private static final String RESULT = "Result", TOKEN = "Token", PARSERSTRING = "ParserString";
private static StringBuilder builder;
public static String generateTokenVariables(Line l, List<Line> lines)
public static String generateTokenVariables(Line l, List<Line> lines, boolean exist)
{
builder = new StringBuilder();
......@@ -19,11 +19,17 @@ public class VariableGenerator
for (String s : paths.keySet())
{
SearchNameMemory list = paths.get(s);
String type = getOrType(lines, list.getSearchArray());
generateVariable(type, s, list.getLevel());
if (!(s.startsWith("_") && !exist))
{
if (s.startsWith("_"))
s = s.substring(1);
SearchNameMemory list = paths.get(s);
String type = getOrType(lines, list.getSearchArray());
generateVariable(type, s, list.getLevel());
}
}
return builder.toString();
......
......@@ -39,11 +39,11 @@ public class ParserCharacter
new ParserCharacter(false, new char[]{'|'}), //22
new ParserCharacter(false, new char[]{'#'}), //23
new ParserCharacter(false, new char[]{'='}), //24
new ParserCharacter(false, new char[]{'\r'}), //25
new ParserCharacter(false, new char[]{'\n'}), //26
new ParserCharacter(false, new char[]{' '}), //27
new ParserCharacter(false, new char[]{'\t'}), //28
new ParserCharacter(false, new char[]{'*'}), //29
new ParserCharacter(false, new char[]{'_'}), //25
new ParserCharacter(false, new char[]{'\r'}), //26
new ParserCharacter(false, new char[]{'\n'}), //27
new ParserCharacter(false, new char[]{' '}), //28
new ParserCharacter(false, new char[]{'\t'}), //29
new ParserCharacter(false, new char[]{':'}), //30
};
......@@ -149,7 +149,7 @@ public class ParserCharacter
public boolean isStrict()
{
return !not && rangeStart.length == 1 && !needsEnd();
return !this.not && this.rangeStart.length == 1 && !this.needsEnd();
}
public char getStrictCharacter()
......
......@@ -30,16 +30,15 @@ public class ParserString extends Token
orToken = new ParserStringBuilder(false, 16, 22),
transientToken = new ParserStringBuilder(false, 17, 23),
equals = new ParserStringBuilder(false, 18, 24),
trans11 = new ParserStringBuilder(true, 19, 25),
trans12 = new ParserStringBuilder(true, 19, 26),
trans13 = new ParserStringBuilder(true, 19, 27),
trans14 = new ParserStringBuilder(true, 20, 28),
trans15 = new ParserStringBuilder(true, 20, 29),
allToken = new ParserStringBuilder(false, 21, 30),
nonGeneratedName = new ParserStringBuilder(false, 19, 25),
trans11 = new ParserStringBuilder(true, 20, 26),
trans12 = new ParserStringBuilder(true, 20, 27),
trans13 = new ParserStringBuilder(true, 20, 28),
trans14 = new ParserStringBuilder(true, 21, 29),
trans15 = new ParserStringBuilder(true, 21, 30),
trans16 = new ParserStringBuilder(true, 24, 31),
trans17 = new ParserStringBuilder(true, 26, 30),
trans17 = new ParserStringBuilder(true, 27, 12),
trans18 = new ParserStringBuilder(true, 27, 12),
trans19 = new ParserStringBuilder(true, 27, 12),
anyChar = new ParserStringBuilder(false, 33, 32)
;
......@@ -70,8 +69,8 @@ public class ParserString extends Token
new ParserCharacter[]{ParserCharacter.chars[22]}, //22
new ParserCharacter[]{ParserCharacter.chars[23]}, //23
new ParserCharacter[]{ParserCharacter.chars[24]}, //24
new ParserCharacter[]{ParserCharacter.chars[25],ParserCharacter.chars[26]}, //25
new ParserCharacter[]{ParserCharacter.chars[25]}, //26
new ParserCharacter[]{ParserCharacter.chars[25]}, //25
new ParserCharacter[]{ParserCharacter.chars[26],ParserCharacter.chars[27]}, //26
new ParserCharacter[]{ParserCharacter.chars[26]}, //27
new ParserCharacter[]{ParserCharacter.chars[27]}, //28
new ParserCharacter[]{ParserCharacter.chars[28]}, //29
......
......@@ -45,10 +45,10 @@ public class ParserStringBuilder extends TokenBuilder
{
int i = 0;
if (s.length() < ParserString.getString(index).length)
if (s.length() < ParserString.getString(this.index).length)
return false;
for (ParserCharacter pc : ParserString.getString(index))
for (ParserCharacter pc : ParserString.getString(this.index))
if (pc.isCharCorrect(s.charAt(i++)))
return false;
......@@ -57,7 +57,7 @@ public class ParserStringBuilder extends TokenBuilder
public boolean isStrict()
{
for (ParserCharacter pc : ParserString.getString(index))
for (ParserCharacter pc : ParserString.getString(this.index))
if (pc.isStrict())
return false;
......@@ -66,7 +66,7 @@ public class ParserStringBuilder extends TokenBuilder
public String getStrictString()
{
StringBuilder builder = new StringBuilder();
for (ParserCharacter pc : ParserString.getString(index))
for (ParserCharacter pc : ParserString.getString(this.index))
builder.append(pc.getStrictCharacter());
return builder.toString();
......
......@@ -28,9 +28,9 @@ public abstract class Token
ParserString.orToken,
ParserString.transientToken,
ParserString.equals,
ParserString.nonGeneratedName,
Jump.builder,
Space.builder,
ParserString.allToken,
Identifier.builder,
SearchName.builder,
LineHeader.builder,
......
......@@ -26,7 +26,7 @@ public class ArraySearchToken extends Token implements MultipleSearchToken
new ArraySearch(
new TokenSearch("minSize", ParserString.digit)
),
new TokenSearch(ParserString.trans18)
new TokenSearch(ParserString.trans17)
),
new TokenSearch(ParserString.arrayOpen),
new OptionalSearch(
......@@ -42,7 +42,7 @@ public class ArraySearchToken extends Token implements MultipleSearchToken
),
new TokenSearch(ParserString.arrayClose),
new OptionalSearch(
new TokenSearch(ParserString.trans19),
new TokenSearch(ParserString.trans18),
new ArraySearch(
new TokenSearch("maxSize", ParserString.digit)
)
......
......@@ -6,7 +6,7 @@ public class Jump extends Token
{
/******** Java Meta Parser Generation ********/
public static final TokenBuilder builder = new TokenBuilder(false, 19, Jump.class);
public static final TokenBuilder builder = new TokenBuilder(false, 20, Jump.class);
public Result searchResults[];
public static final Search builderSearches[] = {
......
......@@ -10,7 +10,11 @@ public class SearchName extends Token
public Result searchResults[];
public Identifier id;
public ParserString notGenerated;
public static final Search builderSearches[] = {
new OptionalSearch(
new TokenSearch("notGenerated", ParserString.nonGeneratedName)
),
new TokenSearch("id", Identifier.builder),
new TokenSearch(ParserString.trans16)
};
......
......@@ -6,7 +6,7 @@ public class Space extends Token
{
/******** Java Meta Parser Generation ********/
public static final TokenBuilder builder = new TokenBuilder(false, 20, Space.class);
public static final TokenBuilder builder = new TokenBuilder(false, 21, Space.class);
public Result searchResults[];
public static final Search builderSearches[] = {
......
......@@ -11,7 +11,6 @@ public class TokenSearchToken extends Token
public Result searchResults[];
public StringToken string;
public Identifier id;
public ParserString any;
public ParserString trans;
public static final Search builderSearches[] = {
new OrSearch(
......@@ -21,8 +20,7 @@ public class TokenSearchToken extends Token
),
new TokenSearch("id", Identifier.builder)
),
new TokenSearch("string", StringToken.builder),
new TokenSearch("any", ParserString.trans17)
new TokenSearch("string", StringToken.builder)
)
};
......
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