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

Implement simpler import syntax #2207

Merged
merged 1 commit into from
Jan 16, 2025
Merged

Conversation

tstirrat15
Copy link
Contributor

Description

After discussion, we decided to go with an import "some/path/to/file.zed" as the syntax and drop the explicit list of imports. This is based on an assumption that users mostly want to decompose a singles schema file into several, and code reuse is not high on the list of priorities.

This changes the parser, compiler, and importer behavior to match.

Changes

  • Update parser behavior
  • Update parser tests and remove now-irrelevant tests
  • Add parser impl for string consume
  • Update compiler, translator, and importer behavior
  • Add validation of local import

Testing

Review. See that things are green.

@tstirrat15 tstirrat15 marked this pull request as ready for review January 15, 2025 22:03
@tstirrat15 tstirrat15 requested a review from a team as a code owner January 15, 2025 22:03
@github-actions github-actions bot added the area/tooling Affects the dev or user toolchain (e.g. tests, ci, build tools) label Jan 15, 2025
@@ -1,4 +1,4 @@
from .path.to. import user, persona
import "path/to/user.zed
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add an error case test where the string is not closed

// the compiler is being invoked, rather than whether it's local to the source
// folder of the current context. The assumption is that that won't matter
// right now, and we can fix it if we need to.
if !filepath.IsLocal(path) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should also add a check for .. anywhere in the path; if so, we can also quick-error

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Like at the parser level?

@@ -198,6 +198,37 @@ func (p *sourceParser) tryConsumeKeyword(keyword string) bool {
return true
}

// consumeString consumes a string token and returns the unwrapped string or adds an error node.
func (p *sourceParser) consumeString() (string, bool) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's name this consumeStringLiteral

@@ -1,4 +1,4 @@
from .path.to. import user, persona
import 'path/to/user.zed'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add one more test which uses ' and " within the other kind of quotes

if !ok {
return "", false
}
wrappedString := wrappedStringToken.Value
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: newline before large comments here and above

@tstirrat15 tstirrat15 force-pushed the implement-simpler-import-syntax branch from c517486 to c1756e6 Compare January 16, 2025 19:35
Copy link
Member

@josephschorr josephschorr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@tstirrat15 tstirrat15 enabled auto-merge January 16, 2025 19:36
@tstirrat15 tstirrat15 added this pull request to the merge queue Jan 16, 2025
Merged via the queue into main with commit ec216dc Jan 16, 2025
39 checks passed
@tstirrat15 tstirrat15 deleted the implement-simpler-import-syntax branch January 16, 2025 21:07
@github-actions github-actions bot locked and limited conversation to collaborators Jan 16, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area/tooling Affects the dev or user toolchain (e.g. tests, ci, build tools)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants