Continue Line

This topic contains 26 replies, has 12 voices, and was last updated by  abakobo 1 year, 5 months ago.

Viewing 15 posts - 1 through 15 (of 27 total)
  • Author
    Posts
  • #7153

    TomToad
    Participant

    What is used to continue on the next line?

    BMAX

    #7154

    peterigz
    Participant

    You can just start a new line, no need for any dots:

    #7155

    TomToad
    Participant

    Thanks.  Now how would I break up a very long string onto separate lines?  A long expression?

    #7156

    abakobo
    Participant

    Last info i saw on this:

    Lines can currently only be split after ‘[‘, ‘(‘ or ‘,’ tokens.

    #7159

    nerobot
    Participant

    Now how would I break up a very long string onto separate lines?

    Just type string inside quotes and split it by Enter:

    #7160

    TomToad
    Participant

    @nerobot, that doesn’t work.  It includes the newline and tabs within the string.  So it prints

    instead of
    Hello, multiline world!
    Seems the only way to do it is

    #7164

    nobuyuki
    Participant

    might be best not to initialize strings that way anyway since strings are immutable and this creates junk for the gc to collect.  Maybe……

    Please pardon me if this is not valid mx2, I’m aware that array initialization may be different now and require something like “New Array<String>” before the open square bracket.

    #7165

    Mark Sibly
    Keymaster

    Lines can currently only be split after ‘[‘, ‘(‘ or ‘,’ tokens.

    This is pretty much the state of things, and it’s been enough for my needs so far.

    Assuming we want to ‘fix’ this (do we?), we can either add more ‘skip eols after this char’ chars, or something like ‘..’ – what’s the general preference here?

    One thing I don’t want to do is add hacks for auto-skipping eols. This is surprisingly hard to do in a ‘clean’ way (ie: without having some bizarre side effects), and I am, in general, OK with mx2 being a little bit ‘prescriptive’ about how code should be written.

    With this in mind, ‘..’ is probably the most flexible approach, although I guess a combination of ‘more chars’ and ‘..’ would work too.

    #7172

    AdamStrange
    Participant

    I would vote for not changing things or use the blitzmax .. to split lines

    #7173

    Danilo
    Participant

    There are many situations when line continuation can be useful:
    ‘+’ or ‘&’ for long string concat
    ‘And’, ‘Or’, ‘Xor’ in longer If-comparisions
    ‘|’ etc. when combining many binary flags
    ‘,’ for many parameters

    If all that is a problem, ‘..’ or ‘ _’ may be better.

    I think it’s easy to do. If the lexer/scanner detects one of
    ‘+’ ‘-‘ ‘&’ ‘And’ ‘Or’ ‘Xor’ ‘|’ ‘,’ ‘(‘ ‘[‘
    as a token, it sets a bool variable ‘LINE_CONTINUATION_OP = True’.
    The next call to the lexer, it removes whitespaces first (space+tabs+comments),
    and when it detects an EOL (end-of-line), it is skipped if
    LINE_CONTINUATION_OP is True.
    For all other tokens, LINE_CONTINUATION_OP is set to False.

    Using this way it is easy to add another token to the list of
    line continuation operators. Just add ‘LINE_CONTINUATION_OP = True’
    for this specific token. It’s a lexer/scanner-only thing, the parser
    does not notify any of this things.

    #7175

    TomToad
    Participant

    Can’t really use .. as it is being used by Using.  Could replace it with _ or or some other character so there would be no need to anticipate every possible scenario in which we need to continue a line.

    #7176

    peterigz
    Participant

    I guess you could always write a little function to clean up strings that are multi-line:

    #7177

    dmaz
    Participant

    I’m for combination of ‘more chars’ and ‘..’. I think Danilo pretty much nailed it.

    #7191

    arpie
    Participant

    How exactly would ‘..’ work to solve the OP’s question, ie. to write a multiline string?  The ‘..’ character would either end up in the string or you would also need to use ‘+ ..’ to concatenate each line, in which case there seems to be no need for the ‘..’ character since a line ending in a single ‘+’ is clearly intended to be a multiline expression (isn’t it?).

    I, personally, would go with Danilo’s suggested list of characters.  I can’t think of any others to add to his list.

    I would however add one extra detail (don’t know how hard this would be to implement).  Can the same list of characters be used at the beginning of a line to trigger a skip of the preceding line break?  I like to write code like this:

    I’m sure some of you will look at the above and go “yuk!”, but, well, you’d be wrong 🙂

    #7192

    arpie
    Participant

    And immediately I will contradict myself – Danilo’s list will need ‘)’ and ‘]’ added to it for my first code example to make sense.

Viewing 15 posts - 1 through 15 (of 27 total)

You must be logged in to reply to this topic.