Skip to content

Commit

Permalink
Use latest pfff not generating NO_FILE_INFO_YET when parsing invalid …
Browse files Browse the repository at this point in the history
…C code

Fixes #1925

test plan:
$ /home/pad/semgrep/_build/default/cli/Main.exe -dump_ast foo.c
foo.c:3:0: Lexical error: unrecognised symbol, in token rule:#
Raised at file "parsing/Parse_code.ml", line 144, characters 24-27
Called from file "parsing/Parse_code.ml", line 236, characters 18-48

no more NO_FILE_INFO_YET error (which causes the python wrapper
to crash).

Also:
$ semgrep -l c -e 'FOO' tests/OTHER/parsing_errors/foo.c
ran 1 rules on 1 files: 0 findings
1 files could not be analyzed; run with --verbose for details or run with --strict to exit non-zero if any file cannot be analyzed
  • Loading branch information
aryx committed Nov 9, 2020
1 parent 07ec23a commit 98ad81c
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 1 deletion.
2 changes: 2 additions & 0 deletions semgrep-core/cli/Main.ml
Original file line number Diff line number Diff line change
Expand Up @@ -850,13 +850,15 @@ let dump_pattern (file: Common.filename) =
let dump_ast file =
match Lang.langs_of_filename file with
| lang::_ ->
E.try_with_print_exn_and_reraise file (fun () ->
let (x, errs) =
Parse_code.parse_and_resolve_name_use_pfff_or_treesitter lang file in
if errs <> []
then failwith (spf "fail to fully parse %s" file);
let v = Meta_AST.vof_any (AST_generic.Pr x) in
let s = dump_v_to_format v in
pr s
)
| [] -> failwith (spf "unsupported language for %s" file)
(*e: function [[Main_semgrep_core.dump_ast]] *)

Expand Down
2 changes: 1 addition & 1 deletion semgrep-core/pfff
Submodule pfff updated from 5b7211 to f0b5b5
4 changes: 4 additions & 0 deletions semgrep-core/tests/OTHER/parsing_errors/foo.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@


# this is invalid code
int x = 1

0 comments on commit 98ad81c

Please sign in to comment.