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