Esempio n. 1
0
 def parse_param_expr(self):
     token = self.token_current()
     e1 = self.parse_expr()
     p1 = ast.Parameter(e1, None)
     token = self.token_current()
     while token.type == scanner.TK_COMMA:
         self.token_accept_any()
         e2 = self.parse_expr()
         p2 = ast.Parameter(e2, None)
         p1 = ast.SequentialParameter(p1, p2)
         token = self.token_current()
     return p1
Esempio n. 2
0
 def parse_toplevel_declaration(self, annots):
   self.expect_word('def')
   subject = None
   is_prefix = False
   name = None
   allow_extra = False
   if self.at_type(Token.IDENTIFIER):
     # def <ident>
     ident = self.current().value
     name = self.expect_type(Token.IDENTIFIER)
     if self.at_punctuation(':='):
       # def <ident> :=
       self.expect_punctuation(':=')
       value = self.parse_expression(True)
       return ast.NamespaceDeclaration(annots, name, value)
     else:
       if self.at_punctuation('('):
         # def <ident> (
         subject = ast.Parameter(name, [data._SUBJECT], ast.Guard.eq(ast.Variable(name.shift_back())))
         is_async = ast.Parameter(None, [data._TRANSPORT], ast.Guard.eq(ast.Literal(data._SYNC)))
         (params, operation, allow_extra, reified) = self.parse_parameters(Parser._SAUSAGES)
         body = self.parse_method_tail(True)
         selector = self.name_as_selector(operation)
         signature = ast.Signature([subject, selector, is_async] + params, allow_extra, reified)
         return ast.FunctionDeclaration(name, ast.Method(signature, body))
       else:
         # def <ident> ...
         subject = ast.Parameter(name, [data._SUBJECT], ast.Guard.any())
   elif self.at_word('type'):
     # def type <atomic> is <atomic>
     self.expect_word('type')
     subtype = self.parse_atomic_expression()
     self.expect_word('is')
     supertype = self.parse_atomic_expression()
     self.expect_statement_delimiter(True)
     return ast.IsDeclaration(subtype, supertype)
   elif self.at_type(Token.OPERATION):
     # def <operation> ...
     (name, is_async) = self.expect_type(Token.OPERATION)
     subject = self.parse_subject()
     is_prefix = True
   else:
     # def (<parameter>)
     subject = self.parse_subject()
   signature = self.parse_functino_signature([subject], is_prefix, name)
   body = self.parse_method_tail(True)
   stage = self.get_subject_stage(subject)
   return ast.MethodDeclaration(stage + 1, annots, ast.Method(signature, body))
Esempio n. 3
0
 def parse_functino_signature(self, subject, is_prefix, default_name=None):
   name = default_name
   is_async = False
   if self.at_punctuation("->"):
     is_async = True
     self.expect_punctuation("->")
   if (not is_prefix) and self.at_type(Token.OPERATION):
     (name, is_async) = self.expect_type(Token.OPERATION)
   if name:
     default_operation = data.Operation.infix(name)
   else:
     default_operation = Parser._SAUSAGES
   (params, param_operation, allow_extra, reified) = self.parse_parameters(default_operation)
   if is_prefix:
     op = data.Operation.prefix(name)
     params = []
   elif params is None:
     params = []
     if name is None:
       op = Parser._SAUSAGES
     else:
       op = data.Operation.infix(name)
   else:
     op = param_operation
   is_async_param = ast.Parameter(None, [data._TRANSPORT], ast.Guard.eq(ast.Literal(data._ASYNC if is_async else data._SYNC)))
   if self.at_punctuation(':='):
     self.expect_punctuation(':=')
     (assign_params, assign_op, allow_extra, reified) = self.parse_parameters(None, start_index=len(params))
     params += assign_params
     op = data.Operation.assign(op)
   if allow_extra and (op.type == data.Operation._CALL):
     selector = self.any_selector()
   else:
     selector = self.name_as_selector(op)
   return ast.Signature(subject + [selector, is_async_param] + params, allow_extra, reified)
Esempio n. 4
0
    def parse_move(self):
        self.indentator.indent('Parsing move')
        self.expect('MOVE')
        coords = self.parse_coord()
        param = ast.Parameter("position", coords)
        self.indentator.dedent()

        return ast.moveOperation(param)
Esempio n. 5
0
    def parse_position(self):
        self.indentator.indent('Parsing Position')
        self.expect('POSITION')
        self.expect('COLON')
        value = self.parse_coord()
        param = ast.Parameter("position", value)
        self.indentator.dedent()

        return param
Esempio n. 6
0
 def parse_signature(self):
   prefix = [
     self.name_as_subject(data.Identifier(0, data.Path(['self']))),
     self.name_as_selector(Parser._SAUSAGES),
     ast.Parameter(None, [data._TRANSPORT], ast.Guard.eq(ast.Literal(data._SYNC)))
   ]
   (params, operation, allow_extra, reified) = self.parse_parameters(None)
   if params is None:
     params = []
   return ast.Signature(prefix + params, allow_extra, reified)
Esempio n. 7
0
    def parse_vitesse(self):
        self.indentator.indent('Parsing Vitesse')
        self.expect('VITESSE')
        self.expect('COLON')
        value = self.show_next().value
        self.expect('INT')
        param = ast.Parameter("vitesse", value)
        self.indentator.dedent()

        return param
Esempio n. 8
0
    def parse_uv(self):
        self.indentator.indent('Parsing Uv')
        self.expect('UV')
        self.expect('COLON')
        value = self.show_next().value
        self.expect('INT')
        param = ast.Parameter("uv", value)
        self.indentator.dedent()

        return param
Esempio n. 9
0
    def parse_duree(self):
        self.indentator.indent('Parsing Duree')
        self.expect('DUREE')
        self.expect('COLON')
        value = self.show_next().value
        self.expect('INT')
        param = ast.Parameter("duree", value)
        self.indentator.dedent()

        return param
Esempio n. 10
0
    def parse_direction(self):
        self.indentator.indent('Parsing Direction')
        self.expect('DIRECTION')
        self.expect('COLON')
        if self.show_next().kind in self.DIR:
            value = self.show_next().value
            self.accept_it()
            param = ast.Parameter("direction", value)
        self.indentator.dedent()

        return param
Esempio n. 11
0
    def parse_intensite(self):
        self.indentator.indent('Parsing Intensite')
        self.expect('INTENSITE')
        self.expect('COLON')
        if self.show_next().kind in self.TYPE_INTENS:
            value = self.show_next().value
            self.accept_it()
            param = ast.Parameter("intensite", value)
        self.indentator.dedent()

        return param
Esempio n. 12
0
    def parse_type_rainfall(self):
        self.indentator.indent('Parsing Type_rainfall')
        self.expect('TYPE_RAIN')
        self.expect('COLON')
        if self.show_next().kind in self.TYPE_RAINFALL:
            value = self.show_next().value
            self.accept_it()
            param = ast.Parameter("typeRain", value)
        self.indentator.dedent()

        return param
Esempio n. 13
0
    def parse_type_cloud(self):
        self.indentator.indent('Parsing Type_could')
        self.expect('TYPE_CLOUD')
        self.expect('COLON')
        if self.show_next().kind in self.TYPE_CLOUD:
            value = self.show_next().value
            self.accept_it()
            param = ast.Parameter("typeCloud", value)
        self.indentator.dedent()

        return param
Esempio n. 14
0
 def parameter(self):
     lead = self.leadComments()
     l = self._peek().location
     ats = self.attribs()
     var = None
     if self._peekTag() is VAR:
         var = self._next().text
     pat = self.simplePattern()
     p = ast.Parameter(ats, var, pat, None, self._location(l))
     self._liftComments(p, None, pat)
     p.comments.before = lead + p.comments.before
     return p
Esempio n. 15
0
    def parse_param(self):
        tk_argident = self.token_current().val
        self.token_accept(scanner.TK_IDENTIFIER)
        self.token_accept(scanner.TK_COLON)
        arg_type = self.parse_typedenoter()
        p1 = ast.Parameter(tk_argident, arg_type)
        token = self.token_current()

        while token.type == scanner.TK_COMMA:
            self.token_accept_any()
            tk_argident = self.token_current().val

            self.token_accept(scanner.TK_IDENTIFIER)

            self.token_accept(scanner.TK_COLON)
            arg_type = self.parse_typedenoter()
            p2 = ast.Parameter(tk_argident, arg_type)
            p1 = ast.SequentialParameter(p1, p2)
            token = self.token_current()

        return p1
Esempio n. 16
0
    def parse_pattern_call(self, end):
        pattern = []

        while not self.cur_is(end):
            tok = self.cur_tok

            if not self.expect_cur_any([token.ID, token.PARAM] +
                                       list(token.keywords.values())):
                return None

            if tok.type == token.ID or tok.type in token.keywords.values():
                pattern.append(ast.Identifier(tok))
            else:
                pattern.append(ast.Parameter(tok, tok.literal))

        return pattern
Esempio n. 17
0
 def parse_parameter(self, default_tag):
   tags = [default_tag]
   if self.at_type(Token.TAG):
     tag = self.expect_type(Token.TAG)
     if type(tag) == int:
       # TODO: This is kind of a hack but how to handle integer tags that
       #     overlap with the default tags? Ban them maybe?
       tags = [tag]
     else:
       tags = [tag, default_tag]
   elif self.at_operation('*'):
     self.expect_operation('*')
     return None
   else:
     tags = [default_tag]
   name = self.expect_type(Token.IDENTIFIER)
   guard = self.parse_guard(default_tag)
   result = ast.Parameter(name, tags, guard)
   return result
Esempio n. 18
0
    def parse_def_stmt(self):
        stmt = ast.FunctionDefinition(self.cur_tok, [], None)

        self.next()

        while not self.cur_is(token.LBRACE):
            tok = self.cur_tok

            if not self.expect_cur_any([token.ID, token.PARAM] +
                                       list(token.keywords.values())):
                return None

            if tok.type == token.ID or tok.type in token.keywords.values():
                stmt.pattern.append(ast.Identifier(tok))
            else:
                stmt.pattern.append(ast.Parameter(tok, tok.literal))

        stmt.body = self.parse_block_statement()

        if len(stmt.pattern) == 0:
            self.err("expected at least one item in a pattern")
            return None

        return stmt
Esempio n. 19
0
 def name_as_selector(self, name):
   assert isinstance(name, data.Operation)
   return ast.Parameter(None, [data._SELECTOR], ast.Guard.eq(ast.Literal(name)))
Esempio n. 20
0
 def any_selector(self):
   return ast.Parameter(None, [data._SELECTOR], ast.Guard.any())
Esempio n. 21
0
 def name_as_subject(self, name):
   return ast.Parameter(name, [data._SUBJECT], ast.Guard.any())