Skip to content

Commit

Permalink
Merge pull request #36 from jmanuel1/typecheck-circular-imports
Browse files Browse the repository at this point in the history
Untangle some circular imports in concat.typecheck
  • Loading branch information
jmanuel1 authored Oct 20, 2024
2 parents 6214166 + d708579 commit 6bf8007
Show file tree
Hide file tree
Showing 8 changed files with 314 additions and 263 deletions.
22 changes: 11 additions & 11 deletions concat/parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ def __init__(
type_parameters: Iterable[Node] = (),
is_variadic: bool = False,
):
children = list(*bases)
children = list[Node](*bases)
children.extend(type_parameters)
children.extend(map(lambda x: x[1], keyword_args))
children.extend(decorators)
Expand Down Expand Up @@ -465,7 +465,7 @@ def top_level_parser() -> Generator[
parsers['string-word'] = token('STRING').map(StringWordNode)

@concat.parser_combinators.generate
def quote_word_contents() -> Generator:
def quote_word_contents():
if 'stack-effect-type-sequence' in parsers:
input_stack_type_parser = parsers[
'stack-effect-type-sequence'
Expand Down Expand Up @@ -530,7 +530,7 @@ def iterable_word_parser(
delimiter: str, cls: Type[IterableWordNode], desc: str
) -> 'concat.parser_combinators.Parser[Token, IterableWordNode]':
@concat.parser_combinators.generate
def parser() -> Generator:
def parser():
location = (yield token('L' + delimiter)).start
element_words = yield word_list_parser
end_location = (yield token('R' + delimiter)).end
Expand Down Expand Up @@ -599,7 +599,7 @@ def word_list_parser() -> Generator:
# type parameter = NAME, COLON, type ;
# The stack effect syntax is defined within the typecheck module.
@concat.parser_combinators.generate
def funcdef_statement_parser() -> Generator:
def funcdef_statement_parser():
location = (yield token('DEF')).start
name = yield token('NAME')
type_params = (yield type_parameters.optional()) or []
Expand All @@ -619,7 +619,7 @@ def funcdef_statement_parser() -> Generator:
)

@concat.parser_combinators.generate
def type_parameter() -> Generator:
def type_parameter():
name = yield token('NAME')
yield token('COLON')
ty = yield parsers['type']
Expand Down Expand Up @@ -671,7 +671,7 @@ def module():
# relative module = DOT*, module | DOT+ ;

@concat.parser_combinators.generate('import statement')
def import_statement_parser() -> Generator:
def import_statement_parser():
location = (yield token('IMPORT')).start
module_name = yield module
asname_parser = token('NAME').map(operator.attrgetter('value'))
Expand All @@ -689,7 +689,7 @@ def relative_module():
return (yield (dot.many().concat() + module) | dot.at_least(1))

@concat.parser_combinators.generate('from-import statement')
def from_import_statement_parser() -> Generator:
def from_import_statement_parser():
location = (yield token('FROM')).start
module = yield relative_module
name_parser = token('NAME').map(operator.attrgetter('value'))
Expand All @@ -706,7 +706,7 @@ def from_import_statement_parser() -> Generator:
parsers['import-statement'] |= from_import_statement_parser

@concat.parser_combinators.generate('from-import-star statement')
def from_import_star_statement_parser() -> Generator:
def from_import_star_statement_parser():
location = (yield token('FROM')).start
module_name = yield module
yield token('IMPORT')
Expand Down Expand Up @@ -784,7 +784,7 @@ def ellispis_verify(
)

@concat.parser_combinators.generate('internal pragma')
def pragma_parser() -> Generator:
def pragma_parser():
"""This parses a pragma for internal use.
pragma = EXCLAMATIONMARK, @, @, qualified name+
Expand All @@ -805,7 +805,7 @@ def pragma_parser() -> Generator:
parsers['word'] |= parsers.ref_parser('cast-word')

@concat.parser_combinators.generate
def cast_word_parser() -> Generator:
def cast_word_parser():
location = (yield token('CAST')).start
yield token('LPAR')
type_ast = yield parsers['type']
Expand Down Expand Up @@ -852,7 +852,7 @@ def handle_recovery(
) -> Sequence[Node]:
if (
isinstance(x, tuple)
and len(x) > 1
and len(x) == 2
and isinstance(x[1], concat.parser_combinators.Result)
):
return [ParseError(x[1])]
Expand Down
4 changes: 3 additions & 1 deletion concat/tests/typecheck/test_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,9 @@ def test_unroll_equal(self) -> None:

class TestForwardReferences(unittest.TestCase):
env = Environment({'ty': get_object_type()})
ty = ForwardTypeReference(IndividualKind, 'ty', env)
ty = ForwardTypeReference(
IndividualKind, 'ty', lambda: TestForwardReferences.env
)

def test_resolve_supertype(self) -> None:
self.assertEqual(
Expand Down
Loading

0 comments on commit 6bf8007

Please sign in to comment.