An initial dump of ideas for a php generator
- use composer and symfony console tools for cli manipulation
- pluggable architecture
components needed - configuration parsing scanning? (helper for generating definitions) templating
An initial dump of ideas for a php generator
components needed - configuration parsing scanning? (helper for generating definitions) templating
So you're basically using json as an intermediate "cached" format? That's... not a good format for it
the json parser is OK in PHP, but it's not as nice as other formats and escaping might be problematic (oy, the charset issues you could discover)
If you want to have an easy to use intermediate format (as you're using json) you should use something more accessible and less prone memory eating
Might I suggest perhaps using sqlite as an intermediate cached format instead if you want to have that functionality? - it would be a single file and easily query-able, which would make updating WAY faster (you could store hashes of the original defs files in any format and check if they've changed since the last lexer pass with one query - tada, incremental lexing and parsing for free)
Another option would be to even just write out PHP files with the definitions of the classes/methods embedded right in, then you could totally skip any kind of json_decode or anything else and just include the intermediate files to get the definitions
I love sqlite the problem with sqlite is that i cant use a text editor in case i want to manually modify or fix something on the definitions/cache.
Before using json the original wxphp developer used serialize/unserialize but if editing was required it was almost impossible.
Php format sounds good, but parsing a huge php file would surely take some time and memory too.
In my experience json hasnt been bad and wxWidgets is a huge library check https://github.com/wxphp/wxphp/blob/master/json/classes.json
Anyways if we choose php I would be happy, everything would PHP xd even template files :D it would just require a little bit more of work at first.
An example of definitions/classes.php could be:
<?php
$class = new ClassSymbol("SomeClassName");
$class->AddMethod(
"MethodName",
[
"static" => false,
"const" => true,
"virtual" => true,
"pure_virtual" => false,
"protected" => false,
"return_type" => "const int*",
"description" => "This method does this and that",
"parameters" => new Parameters() //Will think on this later
]
);
Peg\Application->GetSymbolsTable()->AddClass($class);
//etc...
I actually have quite a bit of that already done in one fashion - see https://github.com/gtkforphp/generator/tree/master/lib/objects - - we'll need to set up the proper hierarchy - module -> package (actually this is namespace but namespace is a reserved word - we'll have similar issues with clas) -> class -> method but also namespace -> function or just package->function - then for both return values and parameters they are subclasses of args - and we should probably do a "documentation" type with info to fill in docblocks, etc
Also I didn't mention it much but we should make this with a pluggable front-end
So we can have peg-cli and peg-gtk adn peg-web versions for people to play with ;)
Then lets call it scan xD, I used the term parser, because in doxygen's case there are lots of xml files that contain the whole structure of a library. So I wrote an xml parser? to extract all definitions and store them in a easy to read json format with an established format to feed the code generator (with easy to read I also mean json -> php array with json_decode)
Instead of lexer I call it the parser :D
wxphp generator works the same except that instead of creating PHP objects it creates an associative array for classes, constants, enumerations, etc... But we should definitely use PHP objects to traverse the definitions|tokens once loaded in memory.
Also I established a format for the json definition files so it doesn't matters if the original definitions are in GIR, doxygen, etc... So I called parser the process of extracting definitions from doxygen|GIR and storing it on an established json format that can be read by the code generator and distributed as part of your source repository (so the usage of the definitions directory is to store those json files with an established format).
This way, any one is able to work-with/regenerate the source code without the need of having original GIR, doxygen definition files, and without leaving the extensions directory.
Same on wxphp, but instead of parser I called it the generator xD (so it seems I'm using wrong terms). In my sucky english dictionary I used generator as the word referring to the process of reading the json definitions and creating the c/c++ source code, config.m4/w32 of the extension.
so peg generate would do something like this:
Obviously more code is required, but it is just a sample so I can better transmit my spaghetti ideas.
Exactly :)
Ahhh nice ideas the [build] and deps options, we can surely make a great team xD