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

Comments

Projects
None yet
@ViliamKopecky
Copy link

commented Jan 24, 2014

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

This comment has been minimized.

Copy link
Contributor

commented Jan 24, 2014

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

@vojtech-dobes

This comment has been minimized.

Copy link
Contributor

commented Jan 24, 2014

@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

This comment has been minimized.

Copy link
Contributor

commented Jan 24, 2014

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

@ViliamKopecky

This comment has been minimized.

Copy link
Author

commented Jan 24, 2014

@vojtech-dobes exactly ;)

@Majkl578

This comment has been minimized.

Copy link
Contributor

commented Jan 24, 2014

It would be good for translations as well.

@dg

This comment has been minimized.

Copy link
Member

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

This comment has been minimized.

Copy link
Contributor

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

This comment has been minimized.

Copy link
Contributor

commented Jan 24, 2014

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

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

But doesn't look good. :/

@enumag

This comment has been minimized.

Copy link
Contributor

commented Jan 24, 2014

@Majkl578 What about this

foo:
    bar:
        """
        abc
        def    
        """
@Majkl578

This comment has been minimized.

Copy link
Contributor

commented Jan 24, 2014

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

@ViliamKopecky

This comment has been minimized.

Copy link
Author

commented Jan 24, 2014

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

This comment has been minimized.

Copy link
Contributor

commented Jan 24, 2014

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

This comment has been minimized.

Copy link
Contributor

commented Jan 24, 2014

👎 all of the proposed syntaxes are ugly

@fprochazka

This comment has been minimized.

Copy link
Contributor

commented Jan 25, 2014

What about:

item:
    inner: "multi
        line
        string"

should return

multi
        line
        string

and

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

should return

multi
line
string
@Elijen

This comment has been minimized.

Copy link
Contributor

commented Jan 29, 2014

What's wrong with:

item:
    inner: "multi\nline\nstring"
@fprochazka

This comment has been minimized.

Copy link
Contributor

commented Jan 29, 2014

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

@Majkl578

This comment has been minimized.

Copy link
Contributor

commented Jan 29, 2014

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

@milo

This comment has been minimized.

Copy link
Member

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

This comment has been minimized.

Copy link
Member

commented Jan 29, 2014

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

@dg

This comment has been minimized.

Copy link
Member

commented Jan 29, 2014

\n, sure

@ViliamKopecky

This comment has been minimized.

Copy link
Author

commented Jan 29, 2014

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

This comment has been minimized.

Copy link
Contributor

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

This comment has been minimized.

Copy link
Member

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

This comment has been minimized.

Copy link
Contributor

commented Jan 29, 2014

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

This comment has been minimized.

Copy link
Author

commented Jan 29, 2014

""" 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

This comment has been minimized.

Copy link
Contributor

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

Merge pull request #28 from dg/pull-multi
added support for multilines strings [Closes nette/nette#1375]
@TomasVotruba

This comment has been minimized.

Copy link
Contributor

commented Oct 13, 2016

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

@JanTvrdik

This comment has been minimized.

@TomasVotruba

This comment has been minimized.

Copy link
Contributor

commented Oct 13, 2016

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

@JanTvrdik

This comment has been minimized.

Copy link
Contributor

commented Oct 13, 2016

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

@TomasVotruba

This comment has been minimized.

Copy link
Contributor

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

This comment has been minimized.

Copy link
Contributor

commented Oct 13, 2016

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
You can’t perform that action at this time.