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

NE-ON: multiline string support #1375

Closed
ViliamKopecky opened this issue Jan 24, 2014 · 33 comments
Closed

NE-ON: multiline string support #1375

ViliamKopecky opened this issue Jan 24, 2014 · 33 comments

Comments

@ViliamKopecky
Copy link

I tried to make a pull-request, but got lost in the Tokenizer insides.

I propose using the python multiline string syntax.

From NE-ON:

"""
this
is
"multiline"
'string'
"""

To PHP:

"this\nis\n\"multiline\"\n'string'"
@enumag
Copy link
Contributor

enumag commented Jan 24, 2014

Are you sure such string should be in config and not database or a template?

@vojtech-dobes
Copy link
Contributor

@enumag I think that @ViliamKopecky would welcome it in Ristretto. Basically NEON is just data format, does not have to be necessarily for configuration (which should not contain such long strings).

@enumag
Copy link
Contributor

enumag commented Jan 24, 2014

In case of Ristretto, yes it might be a good thing. :-)

@ViliamKopecky
Copy link
Author

@vojtech-dobes exactly ;)

@Majkl578
Copy link
Contributor

It would be good for translations as well.

@dg
Copy link
Member

dg commented Jan 24, 2014

In Neon is missing support for multiline strings, because I don't know how handle indentation in this:

item:
    inner: 
        "multi
        line
        string"

@enumag
Copy link
Contributor

enumag commented Jan 24, 2014

@dg I'd do it like this:

item:
    inner: 
        "multi
        line
        string"

= "multi\nline\nstring"

item:
    inner: 
        "multi
         line
         string"

= "multi\n line\n string"

@Majkl578
Copy link
Contributor

Maybe something like HEREDOC in PHP? One line starts multiline content:

foo:
    bar: """
        abc
        def    
"""

But doesn't look good. :/

@enumag
Copy link
Contributor

enumag commented Jan 24, 2014

@Majkl578 What about this

foo:
    bar:
        """
        abc
        def    
        """

@Majkl578
Copy link
Contributor

It's still confusing since indentation level normally means "array"... But probably best option.

@ViliamKopecky
Copy link
Author

I think the indetation should be ignored (value should be as is, without removing indentation) inside the string. Its the value, what if you would want to have the indentation inside the string.

foo:
    bar:
        test:
            more:
"""
multi
line
string
"""
        blah: anything
    something:
        - 'i think'
        - 'this could work'

It's not nice, but multiline strings aren't nice anywhere :) so... And I presume it won't be widely used feature.

@vojtech-dobes
Copy link
Contributor

In response to @dg's example - I think it should strip the indentation.

item:
    inner:
        multi
        line
        string

Should return:

multi
line
string

But

item:
    inner:
        multi
          line
         string

Should return:

multi
  line
 string

If I am right, then just text without - at beginning or text without : after key part does not mean anything in NEON now.

@JanTvrdik
Copy link
Contributor

👎 all of the proposed syntaxes are ugly

@fprochazka
Copy link
Contributor

What about:

item:
    inner: "multi
        line
        string"

should return

multi
        line
        string

and

item:
    inner: 
        """
        multi
        line
        string
        """

should return

multi
line
string

@Elijen
Copy link
Contributor

Elijen commented Jan 29, 2014

What's wrong with:

item:
    inner: "multi\nline\nstring"

@fprochazka
Copy link
Contributor

@Elijen nothing, it works. But you have to write those \n which is annoying.

@Majkl578
Copy link
Contributor

Maybe not as annonying as telling your BFU translator to put "\n" instead of line break. :)

@milo
Copy link
Member

milo commented Jan 29, 2014

I would prefer to strip indentation. There can be condition "only if exists on every next line". Neon content stay readable.

@milo
Copy link
Member

milo commented Jan 29, 2014

Next question: Should be EOL normalized from \r\n to \n? I would prefer it.

@dg
Copy link
Member

dg commented Jan 29, 2014

\n, sure

@ViliamKopecky
Copy link
Author

What about, stripping indetation based on the ending """ indentation?

foo:
    bar: """
        this
        is
        string
"""

> "        this\n        is\n        string"
foo:
    bar: """
        this
        is
        string
        """

# or

foo:
    bar: """
this
is
string
"""

> "this\nis\nstring"

@hrach
Copy link
Contributor

hrach commented Jan 29, 2014

I think that the best distinctive solution is a different syntax.

With indentation

item:
    inner: 
        """
        multi
        line
        string
        """

No indentation

item:
    inner: 
        multi
        line
        string

@dg
Copy link
Member

dg commented Jan 29, 2014

This is

item:
    inner: {
        multi
        items
        list
    }

so it is not good idea to confuse it with multi line string. And """ looks really weird.

Stripping base indentation in quoted string in block flow is probably good enough.

@Majkl578
Copy link
Contributor

Stripping indentation is good.
There still must be way to use quotes, text often contains illegal characters which kill the parser, e.g. comma.

@ViliamKopecky
Copy link
Author

""" are used in Python and CoffeeScript (these I know about, but there are probably more).

And both use singificant whitespace syntax similarly to NE-ON.

I see the advantage in not needing to escape single " - which when writing longer text can be annoying (especially when writing HTML or Texy).

@hrach
Copy link
Contributor

hrach commented Jan 29, 2014

""" is also used in Mozilla localization language. http://l20n.org/

dg added a commit to dg/nette-neon that referenced this issue Mar 18, 2016
dg added a commit to dg/nette-neon that referenced this issue Mar 30, 2016
dg added a commit to nette/neon that referenced this issue Apr 1, 2016
added support for multilines strings [Closes nette/nette#1375]
@TomasVotruba
Copy link
Contributor

What is the multiline syntax apart using `\n' then?

@JanTvrdik
Copy link
Contributor

@TomasVotruba
Copy link
Contributor

I've read that and found only one liners. I'm looking for multiline string.

@JanTvrdik
Copy link
Contributor

JanTvrdik commented Oct 13, 2016

What can I say, read it again. Or maybe I don't understand your question at all.

@TomasVotruba
Copy link
Contributor

TomasVotruba commented Oct 13, 2016

I'm trying to write something like this but with no success:

key:
    multi
    line
    value

Edit: oh, so this is the syntax?

Is there any else?


key: """
    multi
    line
    value
"""
key: '''
    multi
    line
    value
''''

@TomasVotruba
Copy link
Contributor

Thanks, much better!

I expected that in the begging, since that's the real issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests