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

Current filename not cleared in parser #14658

Closed
Keno opened this issue Jan 12, 2016 · 6 comments
Closed

Current filename not cleared in parser #14658

Keno opened this issue Jan 12, 2016 · 6 comments
Labels
parser Language parsing and surface syntax

Comments

@Keno
Copy link
Member

Keno commented Jan 12, 2016

$ cat testparse.jl
str = """
function foo()
  1+1
end
"""
dump(Base.parse(str))
$ ~/julia-target/julia testparse.jl
Expr
  head: Symbol function
  args: Array(Any,(2,))
    1: Expr
      head: Symbol call
      args: Array(Any,(1,))
        1: Symbol foo
      typ: Any
    2: Expr
      head: Symbol block
      args: Array(Any,(2,))
        1: LineNumberNode
          file: Symbol /Users/kfischer/testparse.jl
          line: Int64 2
        2: Expr
          head: Symbol call
          args: Array(Any,(3,))
          typ: Any
      typ: Any
  typ: Any

Note the presence of a line number node, even though the parser has no idea where the string is from.

@JeffBezanson
Copy link
Member

We should retire the jl_parse_next API. Probably makes sense to just parse a whole file at once.

@Keno
Copy link
Member Author

Keno commented Jan 12, 2016

I should also note that this is most likely a regression as the JuliaParser expect the filename to be cleared.

@JeffBezanson JeffBezanson added the parser Language parsing and surface syntax label Jan 12, 2016
@Keno
Copy link
Member Author

Keno commented Jan 16, 2016

Do you have a quick workaround? I'd like to do some experiments with JuliaParser.jl and it would be good if I can get the tests passing first.

@ihnorton
Copy link
Member

diff --git a/src/jlfrontend.scm b/src/jlfrontend.scm
index 41ecbab..04d83c9 100644
--- a/src/jlfrontend.scm
+++ b/src/jlfrontend.scm
@@ -132,6 +132,7 @@

 ;; parse only, returning end position, no expansion.
 (define (jl-parse-one-string s pos0 greedy)
+  (set! current-filename 'none)
   (let ((inp (open-input-string s)))
     (io.seek inp pos0)
     (let ((expr

@JeffBezanson
Copy link
Member

Even better, wrap the body of jl-parse-one-string with (with-bindings ((current-filename 'none)) ... ).

@JeffBezanson
Copy link
Member

Should be fixed by #14707

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

3 participants