Save found scheme layer in tl/Abstract
This commit is contained in:
parent
bf318ae66d
commit
26c8660aba
|
@ -12,13 +12,15 @@ import java.util.Map;
|
||||||
|
|
||||||
public class Overgram {
|
public class Overgram {
|
||||||
public static void main(final String... args) throws IOException {
|
public static void main(final String... args) throws IOException {
|
||||||
|
int layer = 0;
|
||||||
final Map<String, List<TLObject>> objects = new HashMap<>();
|
final Map<String, List<TLObject>> objects = new HashMap<>();
|
||||||
for (int i = 1; i < args.length; ++i) {
|
for (int i = 1; i < args.length; ++i) {
|
||||||
TLReader.readTlObjects(objects, new File(args[i]));
|
layer = Math.max(layer, TLReader.readTlObjects(objects, new File(args[i])));
|
||||||
}
|
}
|
||||||
|
|
||||||
final File parent = new File(args[0]);
|
final File parent = new File(args[0]);
|
||||||
Generator.generateJava(
|
Generator.generateJava(
|
||||||
|
layer,
|
||||||
objects.get("types"),
|
objects.get("types"),
|
||||||
objects.get("functions"),
|
objects.get("functions"),
|
||||||
new File(parent, "Abstract.java"),
|
new File(parent, "Abstract.java"),
|
||||||
|
|
|
@ -12,11 +12,11 @@ public class Generator {
|
||||||
private static final String VARIABLE_SUFFIX = "$";
|
private static final String VARIABLE_SUFFIX = "$";
|
||||||
|
|
||||||
public static void generateJava(
|
public static void generateJava(
|
||||||
final List<TLObject> types, final List<TLObject> functions,
|
final int layer, final List<TLObject> types, final List<TLObject> functions,
|
||||||
final File abstractsFile, final File typesFile, final File functionsFile) throws IOException {
|
final File abstractsFile, final File typesFile, final File functionsFile) throws IOException {
|
||||||
makeParents(abstractsFile, typesFile, functionsFile);
|
makeParents(abstractsFile, typesFile, functionsFile);
|
||||||
try (final Writer writer = new BufferedWriter(new FileWriter(abstractsFile))) {
|
try (final Writer writer = new BufferedWriter(new FileWriter(abstractsFile))) {
|
||||||
writeAbstract(writer, types);
|
writeAbstract(writer, layer, types);
|
||||||
}
|
}
|
||||||
try (final Writer writer = new BufferedWriter(new FileWriter(typesFile))) {
|
try (final Writer writer = new BufferedWriter(new FileWriter(typesFile))) {
|
||||||
writeCode(writer, "Types", "%s", types, false);
|
writeCode(writer, "Types", "%s", types, false);
|
||||||
|
@ -26,10 +26,11 @@ public class Generator {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void writeAbstract(final Writer writer, final List<TLObject> objects) throws IOException {
|
private static void writeAbstract(final Writer writer, final int layer, final List<TLObject> objects) throws IOException {
|
||||||
writer.write("package io.github.lonamiwebs.overgram.tl;\n");
|
writer.write("package io.github.lonamiwebs.overgram.tl;\n");
|
||||||
writer.write("@SuppressWarnings(\"unused\")\n");
|
writer.write("@SuppressWarnings(\"unused\")\n");
|
||||||
writer.write("public class Abstract {\n");
|
writer.write("public class Abstract {\n");
|
||||||
|
writer.write("public static final int LAYER = " + layer + ";\n");
|
||||||
for (final Map.Entry<String, List<String>> nsNames : stringsByNamespace(uniqueTypes(objects)).entrySet()) {
|
for (final Map.Entry<String, List<String>> nsNames : stringsByNamespace(uniqueTypes(objects)).entrySet()) {
|
||||||
if (!nsNames.getKey().isEmpty()) {
|
if (!nsNames.getKey().isEmpty()) {
|
||||||
writer.write("public static class ");
|
writer.write("public static class ");
|
||||||
|
|
|
@ -12,16 +12,43 @@ import java.util.Map;
|
||||||
|
|
||||||
public class TLReader {
|
public class TLReader {
|
||||||
|
|
||||||
public static void readTlObjects(final Map<String, List<TLObject>> result, final File file) {
|
public static int readTlObjects(final Map<String, List<TLObject>> result, final File file) {
|
||||||
for (final Map.Entry<String, List<String>> entry : readTl(file).entrySet()) {
|
final int[] layer = new int[1];
|
||||||
|
for (final Map.Entry<String, List<String>> entry : readTl(file, layer).entrySet()) {
|
||||||
final List<TLObject> objects = result.computeIfAbsent(entry.getKey(), k -> new ArrayList<>());
|
final List<TLObject> objects = result.computeIfAbsent(entry.getKey(), k -> new ArrayList<>());
|
||||||
for (final String string : entry.getValue()) {
|
for (final String string : entry.getValue()) {
|
||||||
objects.add(TLObject.fromString(string));
|
objects.add(TLObject.fromString(string));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return layer[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Map<String, List<String>> readTl(final File file) {
|
private static void scanCommentForLayer(final CharacterIterator iter, final int[] layer) {
|
||||||
|
final String target = "/ LAYER ";
|
||||||
|
int i = 0;
|
||||||
|
char c = '\0';
|
||||||
|
while (iter.hasNext() && (c = iter.next()) != '\n') {
|
||||||
|
if (c != target.charAt(i)) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
++i;
|
||||||
|
if (i == target.length()) {
|
||||||
|
final StringBuilder builder = new StringBuilder();
|
||||||
|
while (iter.hasNext() && Character.isDigit(c = iter.next())) {
|
||||||
|
builder.append(c);
|
||||||
|
}
|
||||||
|
layer[0] = Integer.parseInt(builder.toString());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
while (iter.hasNext() && c != '\n') {
|
||||||
|
c = iter.next();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Map<String, List<String>> readTl(final File file, final int[] layer) {
|
||||||
final Map<String, List<String>> result = new HashMap<>();
|
final Map<String, List<String>> result = new HashMap<>();
|
||||||
|
|
||||||
String section = "types";
|
String section = "types";
|
||||||
|
@ -32,9 +59,7 @@ public class TLReader {
|
||||||
switch (c) {
|
switch (c) {
|
||||||
// Assume '/' only occurs in "// comments...\n"
|
// Assume '/' only occurs in "// comments...\n"
|
||||||
case '/':
|
case '/':
|
||||||
do {
|
scanCommentForLayer(iter, layer);
|
||||||
c = iter.next();
|
|
||||||
} while (iter.hasNext() && c != '\n');
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// Assume '-' only occurs in "---sections---\n"
|
// Assume '-' only occurs in "---sections---\n"
|
||||||
|
|
Loading…
Reference in New Issue