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 = { string: name = {
This is a multi line string This is a multi line string
Hello world Hello world
} }

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

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

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

Loading…
Cancel
Save