Beispiel #1
0
    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)
Beispiel #2
0
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)
Beispiel #3
0
 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
Beispiel #4
0
def parse_ast(s, implicit_tuple=False):
    return gcl.reads(s, implicit_tuple=implicit_tuple)
Beispiel #5
0
def parse(s, env=None, implicit_tuple=False):
    return (gcl.reads(s, implicit_tuple=implicit_tuple).eval(
        gcl.default_env.extend(env)))
Beispiel #6
0
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)))
Beispiel #7
0
def parse_ast(s, implicit_tuple=False):
  return gcl.reads(s, implicit_tuple=implicit_tuple)
Beispiel #8
0
 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
Beispiel #9
0
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)
Beispiel #10
0
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)
Beispiel #11
0
 def testMinus(self):
   x = gcl.reads('3 - 2', implicit_tuple=False)
   self.assertEquals(1, parse('3 - 2'))
Beispiel #12
0
 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