We can now have multiline strings

main
Micke Nordin 3 years ago
parent cf94c84e34
commit be9e6b9e2b
Signed by: micke
GPG Key ID: 0DA0A7A5708FE257

@ -2,7 +2,15 @@ func: hello(string: x) = {
stdout: out = x
}
string: name = Hello world
string: name = {
This is a multi line string
Hello world
}
hello(name)

@ -10,7 +10,8 @@ with open(program, 'r') as json_tokens:
def throw(token: dict, message):
print("{} on line {} ".format(message, token['line_number']))
print("\033[4m" + token['value'] + "\033[0m")
if token['variant'] == 'syntax_error':
print("\033[4m" + token['value'] + "\033[0m")
sys.exit(1)
def resolve_variabel(tokens, signifier):

@ -0,0 +1,13 @@
func: int(number: x) = {
stdout: out = x
}
func: str(string: x) = {
stdout: out = x
}
number: one = 5 + 4
string: str = 5 + 4 =
str(str)
int(one)

@ -57,14 +57,52 @@ 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_index = -1
block_lineno = -1
for index in range(0, len(uncollapsed_tokens)):
token = uncollapsed_tokens[index]
if token['variant'] == 'start_block':
block_index = index
in_block = True
block_lineno = token['line_number']
if token['variant'] == 'end_block':
in_block = False
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)
block = str()
block_index = -1
block_lineno = -1
# This is a declaration
if token['variant'] == 'syntax_error':
usefull_token = token
usefull_token['signifier'] = str(token['line_number']) + "_syntax_error"
usefull_tokens.append(usefull_token)
if in_block:
old_lineno = block_lineno
block_lineno = token['line_number']
if block:
for i in range (old_lineno, block_lineno -1):
block = block + "\n"
block = block + token['value']
else:
if old_lineno +1 != block_lineno:
for i in range (old_lineno, block_lineno -1):
block = block + "\n"
else:
block = block + "\n"
block = block + token['value']
for i in range (old_lineno, block_lineno -1):
block = block + "\n"
else:
usefull_token = token
usefull_token['signifier'] = str(token['line_number']) + "_syntax_error"
usefull_tokens.append(usefull_token)
if token['variant'] == 'type':
maybe_signifier = peek(index + 2, uncollapsed_tokens)
expression = ''

Loading…
Cancel
Save