Giter Club home page Giter Club logo

Comments (4)

Wosi avatar Wosi commented on June 12, 2024

I added a handler for include directives in my fork at https://github.com/Wosi/DelphiAST/

How it works:
TmwBasePasLex can hold a member of the new interface type IIncludeHandler. When it is assigned it receives the name of the include file and should return the content of the file as string. A dummy implementation is provided in the demo project. The file content will be pasted at the start position of the include directive into the FOrigin string. The included content is going to be parsed like it has always been part of the original file. This way there is no need to start parsing the file again from the beginning. Nested includes are supported, too. SyntaxNodes that come into the file via include have a position of -1,-1. All other nodes will keep their original file position.

Since the original file content is hold as a PChar and there might be several pointers to different positions of the string it's not possible to create a new string at a new memory position during the include. That's why I need to alloc additional memory when SetOrigin is being called. Right now I reserve 1MiB for includes and need to free it manually when parsing is done.

You can pull it via the FPC support pull request.

from delphiast.

RomanYankovsky avatar RomanYankovsky commented on June 12, 2024

@Wosi thanks, this is great :)
I have merged the pull request and created a unit test for this functionality.

from delphiast.

Wosi avatar Wosi commented on June 12, 2024

Thanks. I made a shameful mistake regarding the memory management. That mistakes leads to access violations when includes are handled in very huge .pas files (like this one).
I strongly recommend you to cherry-pick my commit 1bed41b. It fixes this bug. Sorry for this mistake.

I also recommend you to cherry-pick cabbc17 in order to be able to compile the demo project with Lazarus again.

from delphiast.

RomanYankovsky avatar RomanYankovsky commented on June 12, 2024

Could you please create a pull request?

from delphiast.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.