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

Interpolation expands too much in import #311

Closed
o314 opened this issue Sep 22, 2021 · 2 comments · Fixed by #313
Closed

Interpolation expands too much in import #311

o314 opened this issue Sep 22, 2021 · 2 comments · Fixed by #313
Labels

Comments

@o314
Copy link

o314 commented Sep 22, 2021

import CSTParser as C
using Test
@test_broken let s = raw"import a.$b.c"; (s |> Meta.parse) == (s |> C.parse |> Expr) end

FYI

raw"import a.$b.c" |> Meta.parse |> Meta.show_sexpr
(:import, (:., :a, (:$, :b), :c))
raw"import a.$b.c" |> C.parse |> Expr |> Meta.show_sexpr
(:import, (:., :a, (:., (:$, :b), (:quote, #QuoteNode
        :c
      ))))
@o314
Copy link
Author

o314 commented Sep 22, 2021

This needs to be reviewed @ https://github.com/julia-vscode/CSTParser.jl/blob/v3.2.4/src/components/internals.jl#L366-L367

function parse_importexport_item(ps, is_colon = false)
    if ...
    elseif kindof(ps.nt) === Tokens.EX_OR
        @closer ps :comma parse_expression(ps)
    elseif ...
    end
end

@o314
Copy link
Author

o314 commented Sep 22, 2021

repost of https://github.com/lezer-parser/julia/issues/4

the tree-sitter grammar offer a very partial implementation of the import/export rules. in particular

  • selected and scoped (tree-sitter lingo) are exclusive
  • aliasing is not supported
  • interpolation is not supported
  • etc.

Here is an update targeting Julia v1.6

# for julia v1.6
import_family ::=
    "import" _imex_bypath ("," _imex_bypath)*
  | "import" _imex_path ":" _imex_bypath ("," _imex_bypath)*
  | "using" _imex_path ("," _imex_path)*
  | "using" _imex_path ":" _imex_bypath ("," _imex_bypath)*
  .

export ::= _imex_path_elem ("," _imex_path_elem)* .

_imex_bypath ::= _imex_path ("as" _imex_path_elem)? .

_imex_path ::= _imex_path_dots _imex_path_elem ("." _imex_path_elem)* .

_imex_path_dots ::= "."* .

_imex_path_elem ::=
    id                                                      # std id
  | id string                                               # nonstd id
  | op                                                      # operator
  | "@" instance                                            # macro name
  | "$" expression                                          # interpolation
# | "(" expression ")"                                      # staging
    .

I write grammar in bnf format since i don't know the js lingo used by lezer, sorry for the inconvenience
Is there any way to update the lezer file ?

REFS

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants