clarity-lang / reference

The Clarity Reference
149 stars 35 forks source link

Newline escape for string literals #23

Closed njordhov closed 4 years ago

njordhov commented 4 years ago

String literals should support a \n escape character for newline.

Currently, line breaks in string literals are typed as actual newline characters, violating the formatting/indent of the code and obfuscating whitespace trailing the line before the newline:

(define-constant newline "
")

(define-read-only (hello-world)
  (let ((text "Hello World!              
Another line"))
    text))

With newline escapes:

(define-constant newline "\n")

(define-read-only (hello-world)
  (let ((text "Hello World!\nAnother line"))
    text))
psq commented 4 years ago

You should be able to use \u{0A} with the new string support. Not sure the 0 is required, although \n is shorter...

njordhov commented 4 years ago

although \n is shorter...

... and likely the escape expected/recognized by many developers for newline.

lgalabru commented 4 years ago

Thank you @njordhov! This issue was addressed with https://github.com/blockstack/stacks-blockchain/pull/1779 (https://github.com/blockstack/stacks-blockchain/pull/1779/commits/0e995a99156f85b2b23e918af9af601572b70575). Will close, feel free to re-open if you had something different in mind.

njordhov commented 4 years ago

@lgalabru Thanks for taking care of implementing the newline escape. Are newline characters still allowed in strings or restricted to the escape character? I favor the latter for Clarity.