So I was going to implement JSON or XML to make my game saves today, but I didn’t like them, so I made my own
Here is basically an image that explains how it works.
Here are some code examples.
ParserDevice device = new ParserDevice();
device.put("apple", "a fruit.").put("color", "red");
System.out.println(device.generateString());
prints
{"apple","a fruit.",{"color","red"}};
Here is 2nd example.
ParserDevice device = new ParserDevice();
// null put null as parent argument, if you don't want branch to be automatically added.
ParserBranch branch = new ParserBranch("mercedes", "car", null);
device.add(branch);
branch.put("color", "white").put("color components", new float[] {1f, 1f, 1f});
branch.put("engine", "powerful").put("horsepower", 1000);
System.out.println(device.generateString());
prints
{"mercedes","car",{"color","white",{"color components","[1.0,1.0,1.0,]",{"type","float"},{"length","3"}}},{"engine","powerful",{"horsepower","1000"}}};
Here is a final example.
ParserDevice device = new ParserDevice();
device.put("mclaren", "formula 1 car").put("speed", "very fast");
device.put("ferrari", "formula 1 car").put("color", "red");
device.parseName("mclaren").put("gearbox", "7 gears");
device.parseTree(new String[] {"ferrari", "color"}).put("color components", new int[] {255, 0, 0});
System.out.println(device.generateString());
prints:
{"mclaren","formula 1 car",{"speed","very fast"},{"gearbox","7 gears"}}
{"ferrari","formula 1 car",{"color","red",{"color components","[255,0,0,]",{"type","integer"},{"length","3"}}}};
Here is the download link with src.
If you want to use/edit, you can do anything…
http://www.mediafire.com/download/6ece46z99aneuar/parser101.zip
Here is the download link with src.ere is the download link with src.
If you want to use/edit, you can do anything…f you want to use/edit, you can do anything…
To read the parser file, you need to create ParserDevice and give it a reader of the stream that contains parser format.
PARSER READER
Will cycle through branches that are within parsable object. If it runs out of branches to give you, it returns null. You can reset the reader with .reset
BUGS: ------------------------------------------------------------
- You need to pass an array of strings of at least length 2 to .parseTree method. It will return null for some reason otherwise. Use .parseName for single string paths.