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

Invalid syntax parsing error with PyreAst.Parser.Concrete.parse_expression #11

Open
jpham658 opened this issue Oct 13, 2024 · 0 comments

Comments

@jpham658
Copy link

Hi! I've been testing out pyre-ast as I'd like to use it in a project, and came across this behaviour:

If I call PyreAst.Parser.Concrete.parse_expression with "x = 4", I get an invalid syntax error, but the same does not occur when I use PyreAst.Parser.Concrete.parse_module. Why is this the case? I thought it would behave the same in both cases.

Code I used to test pyre-ast:

let example content =
  let open PyreAst.Parser in
  with_context (fun context ->
    (* replace parse_module here with parse_expression to get the error *)
  	match Concrete.parse_expression ~context content with
  	| Result.Error { Error.message; line; column; _ } ->
  	  let message = 
  	    Format.sprintf "Parsing error at line %d, column %d: %s"
  	    line column message
  	  in
  	  failwith message
  	| Result.Ok ast -> ast
  )

let () = 
  let ast = example "x = 4" in
  (* replace PyreAst.Concrete.Module with PyreAst.Concrete.Expression if you replace parse_module *)
  Sexplib0.Sexp.pp_hum Format.std_formatter (PyreAst.Concrete.Expression.sexp_of_t ast)

Error I received when parsing "x = 4" with parse_expression

Fatal error: exception Failure("Parsing error at line 1, column 3: invalid syntax")
Raised at Stdlib.failwith in file "stdlib.ml", line 29, characters 17-33
Called from Base__Exn.protectx in file "src/exn.ml", line 80, characters 8-11
Re-raised at Base__Exn.raise_with_original_backtrace in file "src/exn.ml" (inlined), line 60, characters 2-48
Called from Base__Exn.protectx in file "src/exn.ml", line 87, characters 13-49
Called from Dune__exe__Main in file "bin/main.ml", line 16, characters 12-27
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

No branches or pull requests

1 participant