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

Multiline strings are not accepted in define #81

Closed
Lysxia opened this issue Oct 30, 2021 · 2 comments · Fixed by #83
Closed

Multiline strings are not accepted in define #81

Lysxia opened this issue Oct 30, 2021 · 2 comments · Fixed by #83

Comments

@Lysxia
Copy link

Lysxia commented Oct 30, 2021

The docs say they should work. Minimal example:

#define x \
"a
"
Error: File "w.cppo", line 2, characters 2-3
Error: Unterminated string literal
@liyishuai
Copy link
Collaborator

First appearance of the documentation was in 2011:

cppo/README

Lines 264 to 273 in 6ce5f43

Comments and string literals constitute single tokens even when they
span across multiple lines. Therefore newlines within string literals
and comments should remain as-is (no preceding backslash) even in a
macro body:
#define welcome \
"**********
*Welcome!*
**********
"

However, the test suite for the same version requires backslash:

cppo/test.cppo

Lines 46 to 51 in 6ce5f43

#define test_multiline \
"abc\
def" \
(* 123 \
456 *)
test_multiline

Actually, backslash was required since the test suite was first written in 2009:

cppo/test.cppo

Lines 39 to 44 in 433bf21

#define test_esc \
"abc\
def" \
(* 123 \
456 *)
test_esc

I'd read the documentation as outdated. @mjambon Could you confirm my understanding?

@mjambon
Copy link
Member

mjambon commented May 16, 2022

It's likely that I wasn't careful about this issue when I wrote the code and the documentation at the time. My inclination today is indeed to allow and preserve all "lexical elements" as they exist in OCaml (string literals, comments, ...). This means multiline strings should use the same syntax as in OCaml. If a backslash is present at the end of a line within a string literal, it should not be removed by cppo. e.g.:

#define x "hello \
  world"
x

will be turned by cppo into

"hello \
  world"

not

"hello 
  world"

also not

"hello   world"

liyishuai added a commit to liyishuai/opam-repository that referenced this issue May 19, 2022
CHANGES:

- [bug] Fix multiline string support (ocaml-community/cppo#81)
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.

3 participants