About Monkey 2 › Forums › Monkey 2 Programming Help › Continue Line
This topic contains 26 replies, has 12 voices, and was last updated by 
 abakobo
 1 year, 5 months ago.
- 
		AuthorPosts
 - 
		
			
				
February 14, 2017 at 5:12 pm #7153
What is used to continue on the next line?
BMAX
Monkey12Function MyFunction:int( Parm1:int, Parm2:int, Parm3:int, .. '<-What replaces the .. in MX2?Parm4:int, Parm5:int)February 14, 2017 at 5:59 pm #7154You can just start a new line, no need for any dots:
Monkey12Function MyFunction:int( Parm1:int, Parm2:int, Parm3:int,Parm4:int, Parm5:int)February 14, 2017 at 6:29 pm #7155Thanks. Now how would I break up a very long string onto separate lines? A long expression?
Monkey1234567891011Function Main()Local Name:String = "This is a very long " +"string I wish to break up onto " +"multiple lines"Local n:Int = 10 + 12 / 2- 3 * 5Print NamePrint nEndFebruary 14, 2017 at 7:03 pm #7156Last info i saw on this:
Lines can currently only be split after ‘[‘, ‘(‘ or ‘,’ tokens.
February 15, 2017 at 7:32 am #7159Now how would I break up a very long string onto separate lines?
Just type string inside quotes and split it by Enter:
Monkey123Global multi := "Hello,multilineworld!"February 15, 2017 at 8:51 am #7160@nerobot, that doesn’t work. It includes the newline and tabs within the string. So it prints
123Hello,multilineworld!instead of
Hello, multiline world!
Seems the only way to do it isMonkey123Local multi:="Hello, "multi += "multiline "multi += "world!"February 15, 2017 at 7:29 pm #7164might be best not to initialize strings that way anyway since strings are immutable and this creates junk for the gc to collect. Maybe……
Monkey123local multi:= String.Join(["hello ","multiline ","world!"])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.
February 15, 2017 at 10:17 pm #7165Lines 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.
February 16, 2017 at 6:19 am #7172I would vote for not changing things or use the blitzmax .. to split lines
February 16, 2017 at 6:47 am #7173There 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 parametersIf 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.February 16, 2017 at 11:01 am #7175Can’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.
February 16, 2017 at 11:48 am #7176I guess you could always write a little function to clean up strings that are multi-line:
Monkey12345678910111213141516171819202122Namespace myapp#Import "<std>"Using std..Function Main()Print CleanString("This is a very longstring I wish to break up ontomultiple lines")EndFunction CleanString:String(input:String)Local lines:= input.Split("~n")Local output:StringFor Local line:=Eachin linesoutput += line.Trim() + " "NextReturn output.Trim()EndFebruary 16, 2017 at 7:23 pm #7177I’m for combination of ‘more chars’ and ‘..’. I think Danilo pretty much nailed it.
February 17, 2017 at 11:34 pm #7191How 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:
Monkey12345678910111213Int thing := blah_function("really long string being passed to a function looks nicer in multiline layout",another_parameter)If condition = 5Or simon_says = "jump" ThenPrint "Jump"EndIflongstring := "First words"+ "then some more"+ "and that's all folks"I’m sure some of you will look at the above and go “yuk!”, but, well, you’d be wrong
February 17, 2017 at 11:40 pm #7192And immediately I will contradict myself – Danilo’s list will need ‘)’ and ‘]’ added to it for my first code example to make sense.
 - 
		AuthorPosts
 
You must be logged in to reply to this topic.