def testCompletePastIncludesWhenFileChangesAndCachingDisabled(self): includable = ["before = 1;"] def load_from_var(base, rel, env=None): return gcl.loads(includable[0], env=env) source = """ inc = include 'inc.gcl'; bar = inc.| """.strip() source, line, col = find_cursor(source) tree = gcl.reads(source, filename='input.gcl', allow_errors=True, loader=load_from_var) with framework.DisableCaching(): completions = ast_util.find_completions_at_cursor( tree, 'input.gcl', line, col) self.assertTrue('before' in completions) includable[0] = "after = 2;" with framework.DisableCaching(): completions = ast_util.find_completions_at_cursor( tree, 'input.gcl', line, col) self.assertTrue('after' in completions)
def readAndAutocomplete(source, root_env=gcl.Environment({})): source, line, col = find_cursor(source) tree = gcl.reads(source, filename='input.gcl', allow_errors=True) return ast_util.find_completions_at_cursor(tree, 'input.gcl', line, col, root_env=root_env)
def error_parse(self): try: if self._error_parse is None: self._error_parse = gcl.reads(self.text, filename=self.url.path, allow_errors=True, loader=self.loader) return self._error_parse except gcl.ParseError as e: import traceback traceback.print_exc(file=sys.stderr) sys.stderr.write('Unexpected parse error, please raise a bug report\n') raise
def parse_ast(s, implicit_tuple=False): return gcl.reads(s, implicit_tuple=implicit_tuple)
def parse(s, env=None, implicit_tuple=False): return (gcl.reads(s, implicit_tuple=implicit_tuple).eval( gcl.default_env.extend(env)))
def parse(s, env=None, implicit_tuple=False, loader=None): return (gcl.reads(s, implicit_tuple=implicit_tuple, loader=loader) .eval(gcl.default_env.extend(env)))
def testIncludeDefaultBuiltins(self): tree = gcl.reads('henk = 5', filename='input.gcl') rootpath = tree.find_tokens(gcl.SourceQuery('input.gcl', 1, 1)) return ast_util.enumerate_scope(rootpath, include_default_builtins=True) assert '+' in scope
def readAndFindValue(source): source, line, col = find_cursor(source) tree = gcl.reads(source, filename='input.gcl', allow_errors=True) return ast_util.find_value_at_cursor(tree, 'input.gcl', line, col)
def readAndQueryScope(source, **kwargs): source, line, col = find_cursor(source) tree = gcl.reads(source, filename='input.gcl', **kwargs) rootpath = tree.find_tokens(gcl.SourceQuery('input.gcl', line, col)) return ast_util.enumerate_scope(rootpath)
def testMinus(self): x = gcl.reads('3 - 2', implicit_tuple=False) self.assertEquals(1, parse('3 - 2'))
def normal_parse(self): if self._normal_parse is None: self._normal_parse = gcl.reads(self.text, filename=self.url.path, loader=self.loader) return self._normal_parse