Skip core types when parsing .tl files

This avoids the need to comment then every time the file changes.
This commit is contained in:
Lonami Exo 2018-12-15 12:38:56 +01:00
parent 5018879f84
commit da5c171346
2 changed files with 13 additions and 9 deletions

View File

@ -1,11 +1,3 @@
from .tlarg import TLArg
from .tlobject import TLObject
from .parser import parse_tl, find_layer
CORE_TYPES = (
0xbc799737, # boolFalse#bc799737 = Bool;
0x997275b5, # boolTrue#997275b5 = Bool;
0x3fedd339, # true#3fedd339 = True;
0x1cb5c415, # vector#1cb5c415 {t:Type} # [ t ] = Vector t;
)

View File

@ -6,6 +6,15 @@ from .tlobject import TLObject
from ..methods import Usability
CORE_TYPES = {
0xbc799737, # boolFalse#bc799737 = Bool;
0x997275b5, # boolTrue#997275b5 = Bool;
0x3fedd339, # true#3fedd339 = True;
0xc4b9f9bb, # error#c4b9f9bb code:int text:string = Error;
0x56730bcc # null#56730bcc = Null;
}
def _from_line(line, is_function, method_info, layer):
match = re.match(
r'^([\w.]+)' # 'name'
@ -46,7 +55,7 @@ def _from_line(line, is_function, method_info, layer):
)
def parse_tl(file_path, layer, methods=None):
def parse_tl(file_path, layer, methods=None, ignored_ids=CORE_TYPES):
"""
This method yields TLObjects from a given .tl file.
@ -78,6 +87,9 @@ def parse_tl(file_path, layer, methods=None):
result = _from_line(
line, is_function, method_info, layer=layer)
if result.id in ignored_ids:
continue
obj_all.append(result)
if not result.is_function:
obj_by_name[result.fullname] = result