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

add new line escapes #1157

Closed
dm9pZCAq opened this issue Apr 16, 2022 · 6 comments · Fixed by #1551
Closed

add new line escapes #1157

dm9pZCAq opened this issue Apr 16, 2022 · 6 comments · Fixed by #1551

Comments

@dm9pZCAq
Copy link
Contributor

dm9pZCAq commented Apr 16, 2022

here is Makefile

rule: many many \
    many many many requirements
%:
    @echo $@

it would be nice to have this also in Just

and some more examples

# this is Justfile
# for now ther is `error: Unknown start of token` at backslash

var := "a" \
       "b" \
       "c" \
       "d" \
       "e" \
       "f" \
       "..."

# or `if` inside rule
default:
   echo "hello, {{ \
     if "2" == "2" { \
       "long string so not Good!" \
     } else { \
       "it would be nice if i can split" \
       + " it to more lines 1984" \
     } \
   }}"
@casey
Copy link
Owner

casey commented Apr 16, 2022

For the var case you can use parenthesis:

var := (
  "a" + 
  "b"
)

For the other two cases line breaks would definitely be nice.

@dm9pZCAq
Copy link
Contributor Author

then there also should be added spaces

var := (
  "a " + 
  "b " +
  "c " +
  "..."
)

@nk9
Copy link
Contributor

nk9 commented Jul 6, 2022

For the record, a workaround for prerequisites is currently available by nesting them, e.g.:

@compound: a b
    echo "compound"

@a: one two three

@b: four five six

@one:
    echo "one"

@two:
    echo "two"

@three:
    echo "three"

@four:
    echo "four"

@five:
    echo "five"

@six:
    echo "six"
$ just compound
one
two
three
four
five
six
compound

ids1024 added a commit to ids1024/just that referenced this issue Feb 17, 2023
ids1024 added a commit to ids1024/just that referenced this issue Jul 24, 2023
@nk9
Copy link
Contributor

nk9 commented Jul 30, 2023

[Moved from the PR since it's already been merged.]

@casey, @laniakea64 has noticed that this works in a bunch of other cases. See nk9/just_sublime#23 and this gist: https://gist.github.com/laniakea64/b3381389beca11226cb8fefc4e1abf85

Just wanted to check: is this intentional/desired? If it is, there should probably be a lot more tests.

I should note that things like allowing an escaped newline between set and the setting name, or between the variable name and the assignment operator, will thoroughly break the existing syntaxes. Not clear to me that there's a compelling reason to allow escaping newlines this broadly.

@casey
Copy link
Owner

casey commented Jul 31, 2023

I think this is as expected. Only allowing \ in certain contexts would force processing it in the parser, instead of the lexer, which would be a weirder and more complicated implementation. I'm not sure if more tests are necessary though, since afaict, those different contexts that a \ can appear in don't exercise different code paths in the implementation.

@ids1024
Copy link
Contributor

ids1024 commented Jul 31, 2023

I think languages that allow newline escaping like this (which is pretty common) generally do so at a lexing level like this, so you can have an escaped newline anywhere a space can be. That's the behavior I'd expect.

It's useful in various contexts. And it's not a problem if it's allowed in places where it seems unusual to use. But if there are any specific behaviors that seem buggy, that's something to address.

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

Successfully merging a pull request may close this issue.

4 participants