Ejemplo n.º 1
0
 def visit_neuron(self, node):
     """
     Private method: Used to visit a single neuron and create the corresponding global as well as local scopes.
     :return: a single neuron.
     :rtype: ast_neuron
     """
     # set current processed neuron
     Logger.set_current_neuron(node)
     code, message = Messages.get_start_building_symbol_table()
     Logger.log_message(neuron=node,
                        code=code,
                        error_position=node.get_source_position(),
                        message=message,
                        log_level=LoggingLevel.INFO)
     # before starting the work on the neuron, make everything which was implicit explicit
     # but if we have a model without an equations block, just skip this step
     if node.get_equations_blocks() is not None:
         make_implicit_odes_explicit(node.get_equations_blocks())
     scope = Scope(scope_type=ScopeType.GLOBAL,
                   source_position=node.get_source_position())
     node.update_scope(scope)
     node.get_body().update_scope(scope)
     # now first, we add all predefined elements to the scope
     variables = PredefinedVariables.get_variables()
     functions = PredefinedFunctions.get_function_symbols()
     types = PredefinedTypes.get_types()
     for symbol in variables.keys():
         node.get_scope().add_symbol(variables[symbol])
     for symbol in functions.keys():
         node.get_scope().add_symbol(functions[symbol])
     for symbol in types.keys():
         node.get_scope().add_symbol(types[symbol])
Ejemplo n.º 2
0
 def visit_neuron(self, node):
     """
     Private method: Used to visit a single neuron and create the corresponding global as well as local scopes.
     :return: a single neuron.
     :rtype: ast_neuron
     """
     # set current processed neuron
     Logger.set_current_neuron(node)
     code, message = Messages.get_start_building_symbol_table()
     Logger.log_message(neuron=node, code=code, error_position=node.get_source_position(),
                        message=message, log_level=LoggingLevel.INFO)
     # before starting the work on the neuron, make everything which was implicit explicit
     # but if we have a model without an equations block, just skip this step
     if node.get_equations_blocks() is not None:
         make_implicit_odes_explicit(node.get_equations_blocks())
     scope = Scope(scope_type=ScopeType.GLOBAL, source_position=node.get_source_position())
     node.update_scope(scope)
     node.get_body().update_scope(scope)
     # now first, we add all predefined elements to the scope
     variables = PredefinedVariables.get_variables()
     functions = PredefinedFunctions.get_function_symbols()
     types = PredefinedTypes.get_types()
     for symbol in variables.keys():
         node.get_scope().add_symbol(variables[symbol])
     for symbol in functions.keys():
         node.get_scope().add_symbol(functions[symbol])
     for symbol in types.keys():
         node.get_scope().add_symbol(types[symbol])
Ejemplo n.º 3
0
 def visit_neuron(self, node):
     """
     Private method: Used to visit a single neuron and create the corresponding global as well as local scopes.
     :return: a single neuron.
     :rtype: ast_neuron
     """
     # set current processed neuron
     Logger.set_current_node(node)
     code, message = Messages.get_start_building_symbol_table()
     Logger.log_message(node=node,
                        code=code,
                        error_position=node.get_source_position(),
                        message=message,
                        log_level=LoggingLevel.INFO)
     scope = Scope(scope_type=ScopeType.GLOBAL,
                   source_position=node.get_source_position())
     node.update_scope(scope)
     node.get_body().update_scope(scope)
     # now first, we add all predefined elements to the scope
     variables = PredefinedVariables.get_variables()
     functions = PredefinedFunctions.get_function_symbols()
     types = PredefinedTypes.get_types()
     for symbol in variables.keys():
         node.get_scope().add_symbol(variables[symbol])
     for symbol in functions.keys():
         node.get_scope().add_symbol(functions[symbol])
     for symbol in types.keys():
         node.get_scope().add_symbol(types[symbol])
Ejemplo n.º 4
0
    def color_components(self):
        complete_text_as_lines = self.text.get('1.0',
                                               tk.END + '-1c').splitlines()
        active = False
        for number, line in enumerate(complete_text_as_lines):
            last_start_index = -1
            if '#' in line:
                s_l = number + 1
                s_c = line.index('#')
                e_l = s_l
                e_c = len(line)
                self.color_comment(s_l, s_c, e_l, e_c)
            if '/*' in line and '*/' in line:
                s_l = number + 1
                s_c = line.index('/*')
                e_l = s_l
                e_c = line.index('*/') + 2
                self.color_comment(s_l, s_c, e_l, e_c)
            elif '/*' in line:
                active = True
                s_l = number + 1
                s_c = line.index('/*')
                e_l = s_l
                e_c = len(line)
                self.color_comment(s_l, s_c, e_l, e_c)
            elif '*/' in line:
                active = False
                s_l = number + 1
                s_c = 0
                e_l = s_l
                e_c = line.index('*/') + 2
                self.color_comment(s_l, s_c, e_l, e_c)
            elif active:
                s_l = number + 1
                s_c = 0
                e_l = s_l
                e_c = len(line)
                self.color_comment(s_l, s_c, e_l, e_c)
            cur_line = line
            indices = [(index, word)
                       for (index, word) in enumerate(self.pat.findall(line))]
            for _, word in indices:
                s_l = number + 1
                s_c = cur_line.find(word)
                e_l = s_l
                e_c = s_c + len(word)
                cur_line = cur_line.replace(word, 'X' * len(word), 1)
                # skip it if it is already tagged
                if self.editor.textPad.tag_names('%s.%s' % (s_l, s_c)):
                    continue

                if word in PredefinedTypes.get_types():
                    self.color_type(s_l, s_c, e_l, e_c)
                if word in PredefinedFunctions.get_function_symbols():
                    self.make_italic(s_l, s_c, e_l, e_c)
                if word in keywords:
                    self.make_bold(s_l, s_c, e_l, e_c)