Print without newlines

main
Micke Nordin 2 years ago
parent be9e6b9e2b
commit 888dd29517
Signed by: micke
GPG Key ID: 0DA0A7A5708FE257

@ -3,13 +3,8 @@ func: hello(string: x) = {
}
string: name = {
This is a multi line string
Hello world
}

@ -1,7 +1,11 @@
func: print(number: x) = {
func: print(number: x, string: new) = {
stdout: out = x
stdout: newline = new
}
string: new = {
}
number: test = 5
number: another
another = 5.5
@ -13,10 +17,10 @@ number: sixth = test / another
number: seventh = test % another
number: eighth = 7 % test
number: nineth = 7 + 5
print(third)
print(fourth)
print(fifth)
print(sixth)
print(seventh)
print(eighth)
print(nineth)
print(third, new)
print(fourth, new)
print(fifth, new)
print(sixth, new)
print(seventh, new)
print(eighth, new)
print(nineth, new)

@ -84,7 +84,7 @@ for token in tokens:
params[index]['signifier'] = signifier
for part in function['body']:
if part['type'] == "stdout":
print(parse_expression(params, part['expression'], tokens))
print(parse_expression(params, part['expression'], tokens), end = '')
case _:
pass # print(token)

@ -58,7 +58,7 @@ def coaless_tokens(identifiers, line_number, usefull_tokens, variant) -> list:
def collapse_tokens(uncollapsed_tokens: list) -> list:
usefull_tokens = list()
in_block = False
block = str()
block = ""
block_index = -1
block_lineno = -1
for index in range(0, len(uncollapsed_tokens)):
@ -68,13 +68,20 @@ def collapse_tokens(uncollapsed_tokens: list) -> list:
in_block = True
block_lineno = token['line_number']
if token['variant'] == 'end_block':
in_block = False
compare_lineno = block_lineno + 1
block_lineno = token['line_number']
# Do we need to append new lines
for i in range (compare_lineno, block_lineno):
block = block + "\n"
name = "multiline"
maybe_variable = peek(block_index - 2, uncollapsed_tokens)
if maybe_variable['variant'] == 'signifier':
name = maybe_variable['value']
usefull_token = { "variant": "variable_declaration", "signifier": name, "type": "string", "line_number": maybe_variable['line_number'], "expression": block }
usefull_tokens.append(usefull_token)
# Reset for next multiline
in_block = False
block = str()
block_index = -1
block_lineno = -1
@ -82,22 +89,19 @@ def collapse_tokens(uncollapsed_tokens: list) -> list:
# This is a declaration
if token['variant'] == 'syntax_error':
if in_block:
old_lineno = block_lineno
compare_lineno = block_lineno + 1
block_lineno = token['line_number']
if block:
for i in range (old_lineno, block_lineno -1):
# This is if we don't have a block allready
if block == "":
# Do we need to prepend empty lines?
for i in range (compare_lineno, block_lineno):
block = block + "\n"
block = block + token['value']
block = block + token['value'] + "\n"
else:
if old_lineno +1 != block_lineno:
for i in range (old_lineno, block_lineno -1):
block = block + "\n"
else:
# and if we do
for i in range (compare_lineno, block_lineno):
block = block + "\n"
block = block + token['value']
for i in range (old_lineno, block_lineno -1):
block = block + "\n"
block = block + token['value'] + "\n"
else:
usefull_token = token

Loading…
Cancel
Save