camdencheek / tree-sitter-dockerfile

A tree-sitter grammar for Dockerfile
MIT License
71 stars 20 forks source link

Problem parsing trailing comment after line continuation #53

Open mjambon opened 3 months ago

mjambon commented 3 months ago

Here's some input that causes the parsing error:

$ cat trailing-comment.dockerfile 
FROM busybox
RUN ls \
# comment with nothing after

It is accepted by docker but not by tree-sitter-dockerfile:

$ tree-sitter parse trailing-comment.dockerfile 
(source_file [0, 0] - [3, 0]
  (from_instruction [0, 0] - [0, 12]
    (image_spec [0, 5] - [0, 12]
      name: (image_name [0, 5] - [0, 12])))
  (ERROR [1, 0] - [2, 0]
    (shell_fragment [1, 4] - [1, 7])
    (line_continuation [1, 7] - [2, 0]))
  (comment [2, 0] - [2, 28]))
trailing-comment.dockerfile 0 ms    (ERROR [1, 0] - [2, 0])
mjambon commented 3 months ago

btw, I'm going over our backlog of dockerfile-related issues in semgrep. Don't get alarmed if I open a bunch of tickets.