added return type to function
This commit is contained in:
@@ -2,9 +2,9 @@ from Interpreter.Repo import Repo
|
||||
from Interpreter.Utils import Utils
|
||||
from Models.Interpreter.Error import Error
|
||||
from Models.Interpreter.Token import Token
|
||||
from Models.Language.AST.Class import Class
|
||||
from Models.Language.AST.Func import Func
|
||||
from Models.Language.AST.Lib import Lib
|
||||
from Models.Language.Class import Class
|
||||
from Models.Language.Func import Func
|
||||
from Models.Language.Lib import Lib
|
||||
|
||||
|
||||
class Parser:
|
||||
@@ -49,7 +49,7 @@ class Parser:
|
||||
for a_class in a_lib.ast:
|
||||
print(a_class.name, a_class.access)
|
||||
for a_funcs in a_class.ast:
|
||||
print(a_funcs.name, a_funcs.access)
|
||||
print(a_funcs.name, a_funcs.return_type, a_funcs.access)
|
||||
|
||||
print('___')
|
||||
# print(self.__repo.ast, '\n')
|
||||
@@ -85,7 +85,7 @@ class Parser:
|
||||
if not self.__is_scope_started() and tok.type == 'keyword':
|
||||
self.__check_keyword(tok)
|
||||
|
||||
elif not self.__is_scope_started() and tok.type == 'type' or tok.type in self.__repo.types:
|
||||
elif tok.type == 'type' or tok.type in self.__repo.types:
|
||||
pass
|
||||
|
||||
elif not self.__is_scope_started() and tok.type in self.__repo.var_types:
|
||||
@@ -128,12 +128,15 @@ class Parser:
|
||||
|
||||
def __check_format_char(self, tok: Token) -> None:
|
||||
if tok.value == '{':
|
||||
# token in storage must be name!
|
||||
if len(self.__token_storage) > 0 and self.__token_storage[0].type == 'name':
|
||||
# lib
|
||||
if self.__is_start_lib and not self.__is_start_class and not self.__is_start_func:
|
||||
self.__lib = Lib(self.__token_storage[0].value)
|
||||
self.__token_storage = []
|
||||
self.__is_start_lib = False
|
||||
|
||||
# class
|
||||
elif not self.__is_start_lib and self.__is_start_class and not self.__is_start_func:
|
||||
access = ''
|
||||
if self.__is_public:
|
||||
@@ -144,15 +147,20 @@ class Parser:
|
||||
self.__token_storage = []
|
||||
self.__is_start_class = False
|
||||
|
||||
# func
|
||||
elif not self.__is_start_lib and not self.__is_start_class and self.__is_start_func:
|
||||
access = ''
|
||||
if self.__is_public:
|
||||
access = 'public'
|
||||
self.__is_public = False
|
||||
|
||||
self.__func = Func(self.__token_storage[0].value, access=access)
|
||||
self.__token_storage = []
|
||||
self.__is_start_func = False
|
||||
if len(self.__token_storage) > 1 and self.__token_storage[1].type == 'type':
|
||||
if self.__is_public:
|
||||
access = 'public'
|
||||
self.__is_public = False
|
||||
|
||||
self.__func = Func(self.__token_storage[0].value, self.__token_storage[1].value, access=access)
|
||||
self.__token_storage = []
|
||||
self.__is_start_func = False
|
||||
else:
|
||||
self.__utils.error(Error(3.7))
|
||||
|
||||
else:
|
||||
self.__utils.error(Error(2.9, f'{tok.type}: {tok.value}'))
|
||||
@@ -179,6 +187,14 @@ class Parser:
|
||||
elif not self.__is_scope_started() and tok.value in self.__repo.format_chars:
|
||||
pass
|
||||
|
||||
elif tok.value == ':':
|
||||
if self.__is_only_func_started():
|
||||
next = self.__get_next_token()
|
||||
if next.type == 'type':
|
||||
self.__token_storage.append(next)
|
||||
else:
|
||||
self.__utils.error(Error(3.7))
|
||||
|
||||
else:
|
||||
self.__utils.error(Error(2.9, f'{tok.type}: {tok.value}'))
|
||||
|
||||
|
@@ -9,6 +9,7 @@ class Repo:
|
||||
'lib',
|
||||
'class',
|
||||
'func',
|
||||
'var',
|
||||
# builtin functions
|
||||
'output',
|
||||
'input',
|
||||
|
Reference in New Issue
Block a user