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

Add recursive descent expansion of ksx "import" and "from x import y" statements #7

Open
LeonardMH opened this issue Jun 4, 2019 · 1 comment
Assignees
Labels
bug Something isn't working ksx-compile Related to the ksx compile tool ksx.py

Comments

@LeonardMH
Copy link
Owner

Currently, if you import a file that imports another file, only the first file will be included, this is functionality breaking behavior and needs to be fixed ASAP. Every import and from x import y statement should be expanded recursively until there are no more statements to expand.

I can easily see this leading to duplicate imports though, so that needs to be considered, it would be a shame if the 'minifier' tool ended up with exploding file sizes because of duplicate imports.

@LeonardMH LeonardMH added bug Something isn't working ksx-compile Related to the ksx compile tool ksx.py labels Jun 4, 2019
@LeonardMH LeonardMH self-assigned this Jun 4, 2019
LeonardMH added a commit that referenced this issue Jun 7, 2019
This commit implements the relatively easier part of the recursive descent
compiler which is to just continually compile the given lines until there are no
more ksx statements.

This does choke however when two files create a circular reference. I have
added a recursion limit of 6 (which may actually be too low) to catch this
possible condition. Python actually chokes at some point too, but it takes a
while and I'd rather catch it sooner (also prefer giving a more friendly error
message).

I attempted to use a hash of the file contents to track whether we have already
compiled that file, but that is not working because the thing being hashed is
accumulating each compilation step, so it changes.

Anyways, recursion is hard, and this still needs some work, but it's usable
enough as long as you don't have any circular references.

Related to issue #7
@LeonardMH
Copy link
Owner Author

LeonardMH commented Jun 7, 2019

Pushed a commit that partially implements this, but there is still some work to do. See acf0134 for details. In short, it basically works, but will die if there are circular imports, this should be good enough for simple cases though.

@LeonardMH LeonardMH pinned this issue Jun 7, 2019
@LeonardMH LeonardMH unpinned this issue Jun 7, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working ksx-compile Related to the ksx compile tool ksx.py
Projects
None yet
Development

No branches or pull requests

1 participant