-
Notifications
You must be signed in to change notification settings - Fork 476
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
Move !include processing into the parser #1618
Conversation
b485885
to
b8e1ba2
Compare
e388547
to
2e077a7
Compare
d62adff
to
14f56fb
Compare
@casey any chance you could take a look at this PR? It's a lengthy one, but I think doing an architectural change along these lines is a good idea in the long run. |
f8b4145
to
75aa6cc
Compare
Compiler::compile() now outputs a struct `Compilation` instead of a tuple of `Ast` and `Justfile`. Right now this `Compilation` struct contains the same ast and justfile, but abstracting this output into a new type will make it easier to handle justfiles with includes, which will necessarily have multiple Ast's (from different included files) as part of a coherent structure.
Still need to thread debug info through
I was looking at |
No worries thanks for taking a look. There shouldn't be any breaking changes to how I think the best natural entry point is the |
I don't quite remember what I had in mind here, and it's possible I just copy-pasted that code from something else. I don't think we want to treat |
I did a big refactor before merging. The main thing I wanted to do was reduce the size of the diff for review, the diff in the analyzer in particular was hard for me to read, so I refactored it to leave the analyzer mostly untouched. I moved the code to lex, parse, and load includes into the compiler, since that seems like a better place than the loader, which now just loads files into the arena. The Compiler creates adds canonical path to |
I created this #1735 to track actually stabilizing the feature. |
Handle
!include
directives as an ordinary parsed AST node rather than as a special-case text include in the loader. This requires a number of changes to the lexer, parser, loader, analyzer, and in-memory representation ofJustfile
s.With this change, the loader will load the root
justfile
given on the command line and pass the text to the parser to lex and parse it. This file may have!include
directives in it, which will be parsed as a new type ofItem
. After parsing, an analyze step will search the AST for any nodes corresponding to!include
s. If any are found, the loader will then load those externaljustfile
s, parse them into separate ASTs, and recursively search them for further!include
s until all recurisvely-includedjustfile
s are processed. At this point the analyzer will handle building theJustfile
data structure out of the combined set of ASTs, as if they corresponded to one large AST built from the concatenated text of all the included files. Once theJustfile
data structure is built,just
can run as normal.This change will make it possible to put
!include
directives anywhere in a justfile, make it easier to provide error messages that reference their actual source justfile, and make it easier to implement features that need to be aware of source justfiles like #1583 or #1580 .