Exemple #1
0
 def run(self, *args, **kw):
     if 'cmd_line_args' in kw:
         cmd_args = kw['cmd_line_args']
         filename = cmd_args[0]
         directives = parse_file(filename)
         opts = find_options(directives)
         if opts:
             for gen in get_generators():
                 if gen.can_generate(opts): 
                     # break not needed, you may use more 1 generator
                     gen.generate(directives, filename)
Exemple #2
0
def generate(directives, filename):
    """
    Function, that generates code in Erlang
    """
    print 'Erlang generator [START]'
    options = find_options(directives, ERLANG_MODULE_OPTIONS)
    if not can_generate(options):
        raise ErlangOptionsException("Erlang can't generate template for file %s " % filename)
    e_dir = options.get_option('out_dir')
    if not options.get_option('make_lang_dir').strip().lower() in ['false', 'nil']:
        e_dir = os.path.join(e_dir, 'erlang')

    e_dir = os.path.abspath(e_dir)
    if not os.path.exists(e_dir):
        os.makedirs(e_dir)
    mod_name = ''
    for d in directives:
        if d.directive == 'module':
            if not d.value:
                raise EmptyModuleNameException('module name can\'t be empty [%s]' % filename)

            functions = get_module_functions(d)

            # create hrl file, if needed
            records = get_records(d, e_dir)

            # read module and write it down
            if get_directive_option(d, 'genserver'): # make genserver
                generate_genserver(d, functions=functions, records=records, folder=e_dir)


            elif get_directive_option(d, 'fsmserver'): # make fsm server
                pass
            else:               # just make erlang module
                pass
    print 'Erlang generator [DONE]'