Moved structs into separate function
This commit is contained in:
parent
cccd80bec7
commit
07a5fef918
|
@ -704,27 +704,10 @@ def _literal_map(literal: (
|
||||||
elif isinstance(literal, lexer.StringLiteral):
|
elif isinstance(literal, lexer.StringLiteral):
|
||||||
return StringLiteral(literal.value)
|
return StringLiteral(literal.value)
|
||||||
|
|
||||||
def enumeration_syntactical_analyzer(tokens: list[lexer.Token]) -> EnumBlock:
|
def struct_syntactical_analyzer(
|
||||||
pass
|
tokens: list[lexer.Token],
|
||||||
|
public: bool,
|
||||||
def function_syntactical_analyzer(tokens: list[lexer.Token]) -> FunctionBlock:
|
) -> StructBlock:
|
||||||
pass
|
|
||||||
|
|
||||||
def struct_syntactical_analyzer(tokens: list[lexer.Token]) -> StructBlock:
|
|
||||||
pass
|
|
||||||
|
|
||||||
def file_syntactical_analyzer(tokens: list[lexer.Token]) -> File:
|
|
||||||
children: list[Directive | StructBlock | FunctionBlock | EnumBlock] = []
|
|
||||||
|
|
||||||
while tokens:
|
|
||||||
token = tokens.pop(0)
|
|
||||||
if isinstance(token, lexer.Directive):
|
|
||||||
children.append(Directive(token.value))
|
|
||||||
elif isinstance(token, lexer.Keyword):
|
|
||||||
while True:
|
|
||||||
match token.value:
|
|
||||||
case 'pub': pass
|
|
||||||
case 'struct':
|
|
||||||
identifier = tokens.pop()
|
identifier = tokens.pop()
|
||||||
_assert_token(ExpectedIdentifier, identifier)
|
_assert_token(ExpectedIdentifier, identifier)
|
||||||
temp = tokens.pop()
|
temp = tokens.pop()
|
||||||
|
@ -752,10 +735,7 @@ def file_syntactical_analyzer(tokens: list[lexer.Token]) -> File:
|
||||||
_assert_token(ExpectedPunctuation, temp, '*')
|
_assert_token(ExpectedPunctuation, temp, '*')
|
||||||
pointer = True
|
pointer = True
|
||||||
temp = tokens.pop()
|
temp = tokens.pop()
|
||||||
_assert_token_mult(temp, (
|
_assert_token_mult(temp, (lexer.Keyword, lexer.Identifier))
|
||||||
lexer.Keyword,
|
|
||||||
lexer.Identifier,
|
|
||||||
))
|
|
||||||
else:
|
else:
|
||||||
pointer = False
|
pointer = False
|
||||||
if isinstance(temp, lexer.Keyword):
|
if isinstance(temp, lexer.Keyword):
|
||||||
|
@ -770,28 +750,39 @@ def file_syntactical_analyzer(tokens: list[lexer.Token]) -> File:
|
||||||
temp = tokens.pop()
|
temp = tokens.pop()
|
||||||
_assert_token(ExpectedPunctuation, temp)
|
_assert_token(ExpectedPunctuation, temp)
|
||||||
if temp.value not in [',', '=']:
|
if temp.value not in [',', '=']:
|
||||||
raise UnexpectedPunctuation(
|
raise UnexpectedPunctuation(temp, [',', '='])
|
||||||
temp,
|
|
||||||
[',', '='],
|
|
||||||
)
|
|
||||||
elif temp.value == '=':
|
elif temp.value == '=':
|
||||||
temp = tokens.pop()
|
temp = tokens.pop()
|
||||||
_assert_token_literal(temp)
|
_assert_token_literal(temp)
|
||||||
literal = _literal_map(temp) # type: ignore
|
literal = _literal_map(temp) # type: ignore
|
||||||
temp = tokens.pop()
|
temp = tokens.pop()
|
||||||
else: literal = None
|
else: literal = None
|
||||||
members.append(StructureMember(
|
members.append(
|
||||||
member_id,
|
StructureMember(member_id, data_type, pointer, static, literal))
|
||||||
data_type,
|
|
||||||
pointer,
|
|
||||||
static,
|
|
||||||
literal,
|
|
||||||
))
|
|
||||||
else:
|
else:
|
||||||
raise UnexpectedToken(
|
raise UnexpectedToken(temp, ["Keyword", "Identifier"])
|
||||||
temp, ["Keyword", "Identifier"])
|
return StructBlock(Identifier(identifier.value), public, members)
|
||||||
children.append(StructBlock(
|
|
||||||
Identifier(identifier.value), False, members))
|
def enumeration_syntactical_analyzer(tokens: list[lexer.Token]) -> EnumBlock:
|
||||||
|
pass
|
||||||
|
|
||||||
|
def function_syntactical_analyzer(tokens: list[lexer.Token]) -> FunctionBlock:
|
||||||
|
pass
|
||||||
|
|
||||||
|
def file_syntactical_analyzer(tokens: list[lexer.Token]) -> File:
|
||||||
|
children: list[Directive | StructBlock | FunctionBlock | EnumBlock] = []
|
||||||
|
|
||||||
|
while tokens:
|
||||||
|
token = tokens.pop(0)
|
||||||
|
if isinstance(token, lexer.Directive):
|
||||||
|
children.append(Directive(token.value))
|
||||||
|
elif isinstance(token, lexer.Keyword):
|
||||||
|
while True:
|
||||||
|
match token.value:
|
||||||
|
case 'pub': pass
|
||||||
|
case 'struct':
|
||||||
|
children.append(
|
||||||
|
struct_syntactical_analyzer(tokens, False))
|
||||||
break
|
break
|
||||||
|
|
||||||
return File(children)
|
return File(children)
|
||||||
|
|
Loading…
Reference in New Issue