BEdit»Forums
Benjamin Pedersen
46 posts
Mathematician
include?
Edited by Benjamin Pedersen on Reason: Initial post
I am working with two related formats. They share an enum. I suspect some include feature is on the todo. Is it coming soon?
Jens
51 posts / 1 project
include?
Include (or some variant of it) is very much on the todo-list!

I don't think a C-preprocessor "copy-paste"-styled include would be the best though. Say you have:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
// In formatA.bet
struct Header
{
    string(4) magic;
    u(4) version;
    ...
};

struct File
{
    Header header;
    ...
};

layout File;


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
// In composite.bet

include("formatA.bet");
include("formatB.bet"); // Also defines type File and does layout

struct CompositeFile
{
    // What type is what here?
    File fileOfTypeA;
    File fileOfTypeB;
};

layout CompositeFile; // Is this layout done after the included files? Is the included files not doing layout?


Include is also a feature that is needed before some of the incoming major addition to the layout language, so it's somewhat high on the todo list.


I'm currently leaning on a more Python like include, like:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
include(A="formatA.bet");
include("formatB.bet");

// or maybe even:

include(A = "formatA.bet", "formatB.bet")

struct CompositeFile
{
    // Dot is getting very overloaded so might be something like : instead...
    A.File fileA;
    formatB.File fileB;
};

layout CompositeFile;


and only run layout commands if it's the "main" file being executed.

This is currently very much in idea phase so any suggestions would be highly appreciated.
Benjamin Pedersen
46 posts
Mathematician
include?
Makes sense, and "Import" might honestly be a better keyword to differentiate it from preprocessor-include. I think I used "include" because of the syntax being very C-like.
Jens
51 posts / 1 project
include?
Edited by Jens on
The next version of BEdit is planned to include the import statement. If you want to try it out before the next release for the command line viewer, the functionality is already available in the public repository. The command line viewer does currently assume the "import path" is current directory only, something that will get improved before incoming release.

UPDATE: Currently the "namespacing" isn't implemented and might be delayed for the release after.