def load_visualizer(name, at_reload=False): global visualizer, visualizer_mtime try: path = os.path.join(script_directory, name + '.macron') mtime = os.path.getmtime(path) if visualizer_mtime == mtime: return False visualizer_mtime = mtime program = load_file(path) ret, module = macron.run(program, glob) def visualizer_bind(struct): try: obj = module['visualizer'](struct) if isinstance(obj, layout.Box): return obj else: return default_visualizer(struct) except Exception, exception: print "visualizer bad:", exception return default_visualizer(struct) visualizer = visualizer_bind return True
~~~~~~ Small language used by the editor. """ import os from schema.base import Constant, StructType, Struct from schema.flatfile import load_file from schema.language import Synthetizer def ugly_print(*args): print ','.join( map(repr, args) ) def in_module(path): return os.path.join(os.path.dirname(__file__), path) language = load_file(in_module("scripts/macron.language")) syn = Synthetizer(language) class Scope(object): def __init__(self, parent): self.parent = parent self.local = {} def __getitem__(self, key): return self.local[key] if key in self.local else self.parent[key] def __setitem__(self, key, value): self.local[key] = value def ist(obj, name): if isinstance(obj, Struct):
gray_style = default.inherit(color = gray) list_style = default.inherit(background = bracket2, background_color = rgba(255, 255, 255, 0x40), spacing = 2, padding=(6, 6, 6, 6)) struct_style = default.inherit(background = box2, background_color = rgba(255, 255, 255, 0x80), spacing = 8, padding=(4,4,4,4)) # document known_languages = { u"language": lambda: language } script_directory = in_module('scripts') for filename in os.listdir(script_directory): if not os.path.isdir(filename) and filename.endswith('.language'): name, ext = os.path.splitext(filename) path = os.path.join(script_directory, filename) known_languages[name] = lambda: load_file(path) filename = sys.argv[1] langtype = os.path.splitext(filename)[1][1:] current_language = known_languages[langtype]() syn = Synthetizer(current_language) ndef = analyzer.normalize(current_language) inv = analyzer.partial_inversion(ndef) chains = analyzer.build_all_chains(ndef, inv) for name, argv in ndef.items(): print 'TDEF:', name, ', '.join(map(repr, argv))