Add parse support for 'import', brush up 'package' a little. (#3347)

This detects ordering issues with the `package` and `import` statements.
`library` is changed from package-specific to instead be generic between
the two, since structurally it's non-specific.

The next step would be to start exposing the results for the driver to
make ordering decisions for checking. That'll involve further
modifications to this code, but this felt like a reasonable change point
because it's the extent of the parser enforcement, and still causes
significant refactoring.

---------

Co-authored-by: Richard Smith <richard@metafoo.co.uk>
This commit is contained in:
Jon Ross-Perkins
2023-10-31 21:26:49 +00:00
committed by GitHub
co-authored by Richard Smith
parent 428d11323a
commit c9458fe30a
39 changed files with 707 additions and 152 deletions
-6
View File
@@ -31,12 +31,6 @@ auto Tree::Parse(Lex::TokenizedBuffer& tokens, DiagnosticConsumer& consumer,
context.PushState(State::DeclarationScopeLoop);
// The package should always be the first token, if it's present. Any other
// use is invalid.
if (context.PositionIs(Lex::TokenKind::Package)) {
context.PushState(State::Package);
}
while (!context.state_stack().empty()) {
// clang warns on unhandled enum values; clang-tidy is incorrect here.
// NOLINTNEXTLINE(bugprone-switch-missing-default-case)