Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

67 lines (57 sloc) 2.357 kb
import re
import os
import sublime
import sublime_plugin
if int(sublime.version()) < 3000:
from sublime_haskell_common import *
import symbols
from SublimeHaskell.sublime_haskell_common import *
import SublimeHaskell.symbols as symbols
def parse_info(name, contents):
Parses result of :i <name> command of ghci and returns derived symbols.Declaration
functionRegex = '{0}\s+::\s+(?P<type>.*?)(\s+--(.*))?$'.format(name)
dataRegex = '(?P<what>(newtype|type|data))\s+((?P<ctx>(.*))=>\s+)?(?P<name>\S+)\s+(?P<args>(\w+\s+)*)=(\s*(?P<def>.*)\s+-- Defined)?'
classRegex = '(?P<what>class)\s+((?P<ctx>(.*))=>\s+)?(?P<name>\S+)\s+(?P<args>(\w+\s+)*)(.*)where$'
if name[0].isupper():
# data, class, type or newtype
matched =, contents, re.MULTILINE) or, contents, re.MULTILINE)
if matched:
what ='what')
args ='args').strip().split(' ') if'args') else []
ctx ='ctx')
definition ='def')
if definition:
if what == 'class':
return symbols.Class(name, ctx, args)
elif what == 'data':
return symbols.Data(name, ctx, args, definition)
elif what == 'type':
return symbols.Type(name, ctx, args, definition)
elif what == 'newtype':
return symbols.Newtype(name, ctx, args, definition)
raise RuntimeError('Unknown type of symbol: {0}'.format(what))
# function
matched =, contents, re.MULTILINE)
if matched:
return symbols.Function(name,'type'))
return None
def ghci_info(module, name, cabal = None):
Returns info for name as symbol
ghci_cmd = [
":m + " + module,
":i " + module + "." + name,
ghc_opts = get_setting_async('ghc_opts')
(exit_code, stdout, stderr) = call_and_wait_with_input(ghci_append_package_db(['ghci'] + ghc_opts, cabal = cabal), "\n".join(ghci_cmd))
stdout = crlf2lf(stdout)
if exit_code == 0:
return parse_info(name, stdout)
return None
Jump to Line
Something went wrong with that request. Please try again.