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

Comment Parsing error #318

Closed
adamgordonbell opened this issue Sep 22, 2020 · 5 comments · Fixed by #645
Closed

Comment Parsing error #318

adamgordonbell opened this issue Sep 22, 2020 · 5 comments · Fixed by #645
Assignees
Labels
hacktoberfest type:bug Something isn't working

Comments

@adamgordonbell
Copy link
Contributor

I think this may be a bug. The following works in a docker file, but not in an Earthfile:

FROM gafiatulin/alpine-sbt

# install docker in docker
RUN set -eux; \
	apk add --no-cache \
		btrfs-progs \
		e2fsprogs \
		e2fsprogs-extra \
		iptables \
		openssl \
		shadow-uidmap \
		# xfsprogs \
		xz \
		pigz \
	; 

Output

line 13:2 token recognition error at: 'xz '
line 13:5 token recognition error at: '\'
line 14:2 token recognition error at: 'pigz '
line 14:7 token recognition error at: '\'
line 15:1 token recognition error at: ';'
line 13:6 no viable alternative at input '\n'
line 14:8 no viable alternative at input '\n'
line 15:2 no viable alternative at input ' \\n\n'
line 13:2 token recognition error at: 'xz '
line 13:5 token recognition error at: '\'
line 14:2 token recognition error at: 'pigz '
line 14:7 token recognition error at: '\'
line 15:1 token recognition error at: ';'
line 13:6 no viable alternative at input '\n'
line 14:8 no viable alternative at input '\n'
line 15:2 no viable alternative at input ' \\n\n'
Error: syntax error: line 13:6 no viable alternative at input '\n'
syntax error: line 14:8 no viable alternative at input '\n'
syntax error: line 15:2 no viable alternative at input ' \\n\n'
@adamgordonbell adamgordonbell added the type:bug Something isn't working label Sep 22, 2020
@alexcb
Copy link
Collaborator

alexcb commented Sep 22, 2020

That's interesting that docker supports that, it's definitely related to the inline comment.

I ran it with an older version of earth (before #288 was merged in) and it parsed it fine; however this is what was run:

+base | *cached* --> RUN set -eux; apk add --no-cache btrfs-progs e2fsprogs e2fsprogs-extra iptables openssl shadow-uidmap # xfsprogs xz pigz ;

which had the effect of not installing xz or pigz. Would this be the desired effect or a bug?

I took a quick look at python for inspiration, and noticed that both following code examples are invalid:

x = "a" \
    #hello \
    "b"
print(x)

and

x = "a" \
    \ #hello
    "b"
print(x)

@vladaionescu
Copy link
Member

FTR, we talked about this internally and we think the best approach is to treat comments as if they're not there. Also, it might be a good idea if blank lines are also ignored - meaning that you can have blank lines between continuations.

So all of these should work then:

Blank line would be ignored, so continuation still works.

... \

... \
...

Similar to above, but not as obvious, comment is treated like a blank line, and blank lines are ignored, so continuation still works.

... \
    #hello \
...\
...

Comment after continuation character is ok:

... \
    \ #hello
... \
...

@rafaeelaudibert
Copy link

Hello guys! Maybe I could tackle this issue?

Already tracked it down to stmtWords on EarthParser.g4 not allowing empty lines and/or comment lines in between statements.

I believe we could change this rule to use a new type of optional blank lines which would go towards the direction proposed by @vladaionescu

@vladaionescu
Copy link
Member

SGTM - it may require testing, experimentation and fiddling. I'll assign this to you.

@adamgordonbell
Copy link
Contributor Author

This problem also prevents commenting on long RUN statements which are required by WITH DOCKER, making it hard to document the build process.

WITH DOCKER 
        RUN docker-compose up -d & \                                                                                            # start docker compose
            MIX_ENV=test mix deps.compile && \                                                                                  # in parellel start compiling
            while ! sqlcmd -S tcp:localhost,1433 -U sa -P 'some!Password' -Q "SELECT 1" > /dev/null 2>&1; do sleep 1; done; \   # is sql server up?
            while ! mysqladmin ping --host=localhost --port=3306 --protocol=TCP --silent; do sleep 1; done; \                   # is mysql up? 
            while ! pg_isready --host=localhost --port=5432 --quiet; do sleep 1; done; \                                        # is pg up? 
            mix test --include database                                                                                         # lets test 
    END 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
hacktoberfest type:bug Something isn't working
Projects
None yet
5 participants