We can now have multiline strings
This commit is contained in:
parent
cf94c84e34
commit
be9e6b9e2b
4 changed files with 65 additions and 5 deletions
10
hello.mn
10
hello.mn
|
@ -2,7 +2,15 @@ func: hello(string: x) = {
|
||||||
stdout: out = x
|
stdout: out = x
|
||||||
}
|
}
|
||||||
|
|
||||||
string: name = Hello world
|
string: name = {
|
||||||
|
|
||||||
|
This is a multi line string
|
||||||
|
|
||||||
|
Hello world
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
hello(name)
|
hello(name)
|
||||||
|
|
|
@ -10,7 +10,8 @@ with open(program, 'r') as json_tokens:
|
||||||
|
|
||||||
def throw(token: dict, message):
|
def throw(token: dict, message):
|
||||||
print("{} on line {} ".format(message, token['line_number']))
|
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)
|
sys.exit(1)
|
||||||
|
|
||||||
def resolve_variabel(tokens, signifier):
|
def resolve_variabel(tokens, signifier):
|
||||||
|
|
13
mixed.mn
Normal file
13
mixed.mn
Normal file
|
@ -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)
|
44
parser.py
44
parser.py
|
@ -57,14 +57,52 @@ 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
|
||||||
|
block = str()
|
||||||
|
block_index = -1
|
||||||
|
block_lineno = -1
|
||||||
for index in range(0, len(uncollapsed_tokens)):
|
for index in range(0, len(uncollapsed_tokens)):
|
||||||
token = uncollapsed_tokens[index]
|
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
|
# This is a declaration
|
||||||
if token['variant'] == 'syntax_error':
|
if token['variant'] == 'syntax_error':
|
||||||
usefull_token = token
|
if in_block:
|
||||||
usefull_token['signifier'] = str(token['line_number']) + "_syntax_error"
|
old_lineno = block_lineno
|
||||||
usefull_tokens.append(usefull_token)
|
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':
|
if token['variant'] == 'type':
|
||||||
maybe_signifier = peek(index + 2, uncollapsed_tokens)
|
maybe_signifier = peek(index + 2, uncollapsed_tokens)
|
||||||
expression = ''
|
expression = ''
|
||||||
|
|
Loading…
Add table
Reference in a new issue