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

parsing getindex (or :ref) with only keyword arguments (:parameters) #33328

Open
Jutho opened this issue Sep 19, 2019 · 3 comments
Open

parsing getindex (or :ref) with only keyword arguments (:parameters) #33328

Jutho opened this issue Sep 19, 2019 · 3 comments
Labels
parser Language parsing and surface syntax

Comments

@Jutho
Copy link
Contributor

Jutho commented Sep 19, 2019

I noticed that the following does not parse:

julia> Expr(:ref, :a, Expr(:parameters, :x, :y))
:(a[; x, y])
julia>:(a[; x, y])

ERROR: syntax: unexpected ";"

For a regular function call, there is no problem

julia> Expr(:call, :a, Expr(:parameters, :x, :y))
:(a(; x, y))
julia> :(a(; x, y))
:(a(; x, y))

Arises in the context of experimenting with DSLs (with macros) for tensors

@JeffBezanson JeffBezanson added the parser Language parsing and surface syntax label Sep 19, 2019
@KristofferC
Copy link
Sponsor Member

Ref #25631

@c42f
Copy link
Member

c42f commented Oct 1, 2019

The place this gets tricky is in combination with typed_vcat syntax which also uses the semicolon. So we're toying with syntactic inconsistency if we have T[; x] mean something completely different from T[y; x], which already means Expr(:typed_vcat, :T, :y, :x).

Having said that, we're not very consistent at the moment. We have:

julia> dump(:(x[y; a=1]))
Expr
  head: Symbol typed_vcat
  args: Array{Any}((3,))
    1: Symbol x
    2: Symbol y
    3: Expr
      head: Symbol =
      args: Array{Any}((2,))
        1: Symbol a
        2: Int64 1

which parses but turns into a lowering error unless you translate it via a macro. And that's inconsistent with the following which parses to contain a :parameters Expr...

julia> dump(:(x[y,z; a=1]))
Expr
  head: Symbol ref
  args: Array{Any}((4,))
    1: Symbol x
    2: Expr
      head: Symbol parameters
      args: Array{Any}((1,))
        1: Expr
          head: Symbol =
          args: Array{Any}((2,))
            1: Symbol a
            2: Int64 1
    3: Symbol y
    4: Symbol z

@Jutho
Copy link
Contributor Author

Jutho commented Oct 1, 2019

For my use case, I don't quite care how it is parsed, just that it parses such that it is valid input within my macro context, and I can recognise the expression and transform it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
parser Language parsing and surface syntax
Projects
None yet
Development

No branches or pull requests

4 participants