Skip to content

high-level parseFile #102

Open
Open

Description

@wilzbach

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

Activity

  1. Hackerpilot commented on May 31, 2016

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

  2. wilzbach commented on Jun 2, 2016

    @wilzbach
    MemberAuthor

    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

  3. added this to the v1.0.0 milestone on May 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions