def parse_module(mod): if mod is None: return None return symbols.Module(mod['name'], mod.get('exports'), [parse_import(i) for i in mod['imports']] if 'imports' in mod else [], dict((decl['name'], parse_declaration(decl)) for decl in mod['declarations']) \ if 'declarations' in mod else {}, parse_location(mod.get('location')))
def module(self, project_name, lookup='', search_type='prefix', project=None, file=None, module=None, deps=None, sandbox=None, cabal=False, symdb=None, package=None, source=False, standalone=False, **backend_args): modsyms = None if search_type == 'exact' and re.match(r'\w+(\.\w+)+', lookup): backend = self.project_backends.get(project_name) modinfo = backend.command_backend('browse -d -o ' + lookup) if backend is not None else [] if Settings.COMPONENT_DEBUG.recv_messages or Settings.COMPONENT_DEBUG.all_messages: print('ghc-mod modules: resp =\n{0}'.format(pprint.pformat(modinfo))) impinfo = [symbols.Module(lookup)] moddecls = dict([(decl.name, decl) for decl in [self.parse_syminfo(mdecl, impinfo) for mdecl in modinfo]]) if Settings.COMPONENT_DEBUG.recv_messages or Settings.COMPONENT_DEBUG.all_messages: print('ghc-mod modules: moddecls =\n{0}'.format(pprint.pformat(moddecls))) modsyms = symbols.Module(lookup, [], [], moddecls, symbols.PackageDb(global_db=True)) return self.dispatch_callbacks([modsyms] if modsyms else [], None, **backend_args)
def module(self, project_name, lookup='', search_type='prefix', project=None, file=None, module=None, deps=None, sandbox=None, cabal=False, symdb=None, package=None, source=False, standalone=False, **backend_args): modsyms = None if search_type == 'exact' and re.match(r'\w+(\.\w+)+', lookup): backend = self.project_backends.get(project_name) modinfo, err = backend.command_backend( 'browse -d -o ' + lookup) if backend is not None else [] if Settings.COMPONENT_DEBUG.recv_messages or Settings.COMPONENT_DEBUG.all_messages: print('ghc-mod modules: resp =\n{0}'.format( pprint.pformat(modinfo))) if not err or 'EXCEPTION' not in ' '.join(err): moddecls = {} for mdecl in modinfo: decl = None name, declinfo = self.get_name_decl(mdecl) if declinfo.startswith('class '): ctx, args = self.split_context_args(name, declinfo[5:]) decl = symbols.Class(name, ctx, args) elif declinfo.startswith('data '): ctx, args = self.split_context_args(name, declinfo[5:]) decl = symbols.Data(name, ctx, args) elif declinfo.startswith('newtype '): ctx, args = self.split_context_args(name, declinfo[8:]) decl = symbols.Newtype(name, ctx, args) elif declinfo.startswith('type '): ctx, args = self.split_context_args(name, declinfo[5:]) decl = symbols.Type(name, ctx, args) else: # Default to function decl = symbols.Function(name, declinfo) if decl is not None: moddecls[name] = decl if Settings.COMPONENT_DEBUG.recv_messages or Settings.COMPONENT_DEBUG.all_messages: print('ghc-mod modules: moddecls =\n{0}'.format( pprint.pformat(moddecls))) modsyms = symbols.Module(lookup, [], [], moddecls, symbols.PackageDb(global_db=True)) return self.dispatch_callbacks([modsyms] if modsyms else [], **backend_args)
def parse_module(mod): if not mod: return None mid = parse_module_id(mod['id']) return symbols.Module( mid.name, mid.location, exports=parse_symbols(mod.get('exports')), imports=parse_imports(mod.get('imports')), )
def ghcmod_browse_module(module_name, cabal=None): """ Returns symbols.Module with all declarations """ contents = GHCIMod.call_ghcmod_and_wait(['browse', '-d', module_name], cabal=cabal).splitlines() if not contents: return None mod_decls = symbols.Module(module_name) function_regex = r'(?P<name>\w+)\s+::\s+(?P<type>.*)' type_regex = r'(?P<what>(class|type|data|newtype))\s+(?P<name>\w+)(\s+(?P<args>\w+(\s+\w+)*))?' def to_decl(line): matched = re.search(function_regex, line) if matched: return symbols.Function(matched.group('name'), matched.group('type')) else: matched = re.search(type_regex, line) if matched: decl_type = matched.group('what') decl_name = matched.group('name') decl_args = matched.group('args') decl_args = decl_args.split() if decl_args else [] if decl_type == 'class': return symbols.Class(decl_name, None, decl_args) elif decl_type == 'data': return symbols.Data(decl_name, None, decl_args) elif decl_type == 'type': return symbols.Type(decl_name, None, decl_args) elif decl_type == 'newtype': return symbols.Newtype(decl_name, None, decl_args) else: return symbols.Declaration(line) for decl in map(to_decl, contents): mod_decls.add_declaration(decl) return mod_decls
def scope_modules(self, project_name, _filename, lookup='', search_type='prefix', **backend_args): def make_pkg(pkg): pkg_info = pkg.split('-', 2) pkg_name = pkg_info[0] if pkg_info: pkg_ver = pkg_info[1] else: pkg_ver = '<no version>' return symbols.Package(pkg_name, pkg_ver) backend = self.project_backends.get(project_name) modules, err = backend.command_backend( 'list -d') if backend is not None else ([], []) if Settings.COMPONENT_DEBUG.recv_messages or Settings.COMPONENT_DEBUG.all_messages: print('ghc-mod scope_modules: resp =\n{0}'.format(modules)) if not err: filtered_mods = [ symbols.Module( mod[1], [], [], {}, symbols.InstalledLocation( make_pkg(mod[0]), symbols.PackageDb(global_db=True))) for mod in (m.split() for m in modules if self.lookup_match(m[1], lookup, search_type)) ] if Settings.COMPONENT_DEBUG.recv_messages or Settings.COMPONENT_DEBUG.all_messages: print('ghc-mod scope_modules: filtered_mods\n{0}'.format( pprint.pformat(filtered_mods))) return self.dispatch_callbacks(filtered_mods, err, **backend_args)
def parse_module_id(mod): return symbols.Module(mod['name'], [], [], {}, parse_location(mod.get('location'))) if mod else None
def parse_module_id(mod): if mod is None: return None return symbols.Module(mod['name'], [], [], {}, parse_location(mod.get('location')))