Skip to content

Instantly share code, notes, and snippets.

@auroraeosrose
Created June 19, 2014 23:22
Show Gist options
  • Save auroraeosrose/e90155727703190ab64c to your computer and use it in GitHub Desktop.
Save auroraeosrose/e90155727703190ab64c to your computer and use it in GitHub Desktop.
Ideas for merged extension generator

An initial dump of ideas for a php generator

  1. use composer and symfony console tools for cli manipulation
  2. pluggable architecture

components needed - configuration parsing scanning? (helper for generating definitions) templating

@auroraeosrose
Copy link
Author

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

@jgmdev
Copy link

jgmdev commented Jun 24, 2014

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.

@jgmdev
Copy link

jgmdev commented Jun 24, 2014

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...

@auroraeosrose
Copy link
Author

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 ;)

@jgmdev
Copy link

jgmdev commented Dec 1, 2015

TODO (Reminder)

  • Use CastXML to parse C/C++ header files directly and convert them to an easy to parse xml file.
  • Add GIR support in order to parse GTK documentation.
  • Finish codegenerator for PHP version 5 (generate classes)
  • Use PHP version 5 codegenerator as base to start writing a PHP 7 code generator.
  • Also add HHVM code generation support.
  • Implement C++ templates support
  • Write a webui that could be launched from command line (eg: peg ui) in order to graphically modify definition files and enable/disable classes, methods, functions, etc...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment