Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

high-level parseFile #102

Open
wilzbach opened this issue May 31, 2016 · 2 comments
Open

high-level parseFile #102

wilzbach opened this issue May 31, 2016 · 2 comments
Milestone

Comments

@wilzbach
Copy link
Member

wilzbach commented May 31, 2016

Now after using the libdparse API again, I have to complain a bit.

As a user I don't care about LexerConfig, StringCache, RollBackAllocator etc. - those are mostly implementation details and once you added the RollbackAllocator it broke my code and other code.
Here's the most minimal example to read in a module:

    File f = File(fileName);
    ubyte[] sourceCode = uninitializedArray!(ubyte[])(to!size_t(f.size));
    f.rawRead(sourceCode);
    LexerConfig config;
    StringCache cache = StringCache(StringCache.defaultBucketCount);
    auto tokens = getTokensForParser(sourceCode, config, &cache);
    RollbackAllocator rba;
    Module m = parseModule(tokens.array, fileName, &rba);

How about adding a parseFile method that abstracts this for the user and allows use to swap around the internals in the future?

   Module m  = parseFile(fileName);
@Hackerpilot
Copy link
Collaborator

That might work if we allocate the string cache and the rollback allocator using the GC. Those need to have a longer lifetime than the AST returned from the function.

@wilzbach
Copy link
Member Author

wilzbach commented Jun 2, 2016

That might work if we allocate the string cache and the rollback allocator using the GC. Those need to have a longer lifetime than the AST returned from the function.

Yep and my point was that for simple use cases that's the case. Don't give simple users control about something they don't care/know about.

Btw another interesting idea that Ilya is using in his ndslice API is to let the user pass in his allocator and then return everything that has been allocated:

http://docs.mir.dlang.io/latest/mir_ndslice_slice.html#.makeSlice

@WebFreak001 WebFreak001 added this to the v1.0.0 milestone May 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants