Exemple #1
0
    def _parse_module(self):
        """
        module = 'module' NAME '{' use* type* '}'
        """
        if not self._at_keyword('module'):
            raise ASDLSyntaxError(
                'Expected "module" (found {})'.format(self.cur_token.value),
                self.cur_token.lineno)
        self._advance()
        name = self._match(self._id_kinds)
        self._match(TokenKind.LBrace)

        uses = []
        while self._at_keyword('use'):
            uses.append(self._parse_use())

        defs = []
        while self.cur_token.kind == TokenKind.TypeId:
            typename = self._advance()
            self._match(TokenKind.Equals)
            type = self._parse_type()
            defs.append(Type(typename, type))

        self._match(TokenKind.RBrace)
        return Module(name, uses, defs)
Exemple #2
0
 def _parse_definitions(self):
     defs = []
     while self.cur_token.kind == TokenKind.TypeId:
         typename = self._advance()
         self._match(TokenKind.Equals)
         type = self._parse_type()
         defs.append(Type(typename, type))
     return defs