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

Support begin/end indexing of SourceFile #201

Merged
merged 3 commits into from
Feb 18, 2023
Merged

Conversation

timholy
Copy link
Sponsor Member

@timholy timholy commented Feb 17, 2023

No description provided.

Copy link
Member

@c42f c42f left a comment

Choose a reason for hiding this comment

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

looks good to me

@test SourceFile("a\nb\n")[3:end] == "b\n"
if Base.VERSION >= v"1.4"
# Protect the `[begin` from being viewed by the parse on older Julia versions
@test eval(Meta.parse("""SourceFile("a\nb\n")[begin:end]""")) == "a\nb\n"
Copy link
Member

Choose a reason for hiding this comment

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

hehehe we are the parser!

So we can almost use JuliaSyntax.parse(Expr, """SourceFile("a\nb\n")[begin:end]""", version=v"1.6") unconditionally here.

But alas, lowering won't understand the result with the begin embedded in the Expr... so not really 😅

Copy link
Sponsor Member Author

Choose a reason for hiding this comment

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

It is indeed quite ironic! I guess if this were to swap itself in as the include parser, then even older Julia versions would be prepared for this. But given the necessary changes in JuliaLang/julia#46372, presumably this won't happen.

Copy link
Member

Choose a reason for hiding this comment

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

JuliaSyntax.enable_in_core!() does make it work with include()!

But only in Julia 1.6+ because it requires the hooks implemented in JuliaLang/julia#35243

@timholy timholy merged commit a941919 into main Feb 18, 2023
@timholy timholy deleted the teh/index_sourcefile branch February 18, 2023 14:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants