コード例 #1
0
 def __init__(self, source, node=None, does_match=None):
     if node is None:
         try:
             node = ast.parse(source)
         except SyntaxError:
             # needed to parse expression containing := operator
             node = ast.parse("(" + source + ")")
     if does_match is None:
         self.does_match = self._simple_does_match
     else:
         self.does_match = does_match
     self._init_using_ast(node, source)
コード例 #2
0
ファイル: server.py プロジェクト: thetonywu/dotfiles
 def check_syntax(self, code):
     try:
         tree = parse(code)
     except (SyntaxError, IndentationError, ValueError) as e:
         return {"lineno": e.lineno, "offset": e.offset, "text": e.text}
     else:
         return Checker(tree).messages
コード例 #3
0
def get_patched_ast(source, sorted_children=False):
    """Adds ``region`` and ``sorted_children`` fields to nodes

    Adds ``sorted_children`` field only if `sorted_children` is True.

    """
    return patch_ast(ast.parse(source), source, sorted_children)
コード例 #4
0
ファイル: server.py プロジェクト: barbak/SublimePythonIDE
 def check_syntax(self, code):
     try:
         tree = parse(code)
     except (SyntaxError, IndentationError, ValueError) as e:
         return {"lineno": e.lineno, "offset": e.offset, "text": e.text}
     else:
         return Checker(tree).messages
コード例 #5
0
ファイル: evaluate.py プロジェクト: nbzhaosq/myEmacsDir
def eval_str2(holding_scope, name):
    try:
        # parenthesizing for handling cases like 'a_var.\nattr'
        node = ast.parse("(%s)" % name)
    except SyntaxError:
        raise BadIdentifierError("Not a resolvable python identifier selected.")
    return eval_node2(holding_scope, node)
コード例 #6
0
def eval_str2(holding_scope, name):
    try:
        # parenthesizing for handling cases like 'a_var.\nattr'
        node = ast.parse('(%s)' % name)
    except SyntaxError:
        raise BadIdentifierError('Not a resolvable python identifier selected.')
    return eval_node2(holding_scope, node)
コード例 #7
0
ファイル: evaluate.py プロジェクト: FredSanders/emacs.d
def get_primary_and_pyname_in_scope(holding_scope, name):
    try:
        # parenthesizing for handling cases like 'a_var.\nattr'
        node = ast.parse('(%s)' % name)
    except SyntaxError:
        raise BadIdentifierError('Not a resolvable python identifier selected.')
    return get_primary_and_result(holding_scope, node)
コード例 #8
0
ファイル: patchedast.py プロジェクト: Kha/rope
def get_patched_ast(source, sorted_children=False):
    """Adds ``region`` and ``sorted_children`` fields to nodes

    Adds ``sorted_children`` field only if `sorted_children` is True.

    """
    return patch_ast(ast.parse(source), source, sorted_children)
コード例 #9
0
ファイル: notes.py プロジェクト: brucexin/bruce-s-profiles
 def warnings(self, source):
     result = []
     try:
         node = ast.parse(source)
     except SyntaxError:
         return []
     except SyntaxWarning, e:
         result.append((e.lineno, e.msg))
コード例 #10
0
ファイル: pyobjectsdef.py プロジェクト: python-rope/rope
 def __init__(self, pycore, resource=None, force_errors=False):
     self.resource = resource
     init_dot_py = self._get_init_dot_py()
     if init_dot_py is not None:
         ast_node = pycore.project.get_pymodule(init_dot_py, force_errors=force_errors).get_ast()
     else:
         ast_node = ast.parse("\n")
     super(PyPackage, self).__init__(pycore, ast_node, resource)
コード例 #11
0
ファイル: similarfinder.py プロジェクト: Kha/rope
 def __init__(self, source, node=None, does_match=None):
     if node is None:
         node = ast.parse(source)
     if does_match is None:
         self.does_match = self._simple_does_match
     else:
         self.does_match = does_match
     self._init_using_ast(node, source)
コード例 #12
0
 def __init__(self, source, node=None, does_match=None):
     if node is None:
         node = ast.parse(source)
     if does_match is None:
         self.does_match = self._simple_does_match
     else:
         self.does_match = does_match
     self._init_using_ast(node, source)
コード例 #13
0
    def run(self):
        errors = []

        try:
            tree = parse(self.code, filename=self.filename)
        except (SyntaxError, IndentationError, ValueError), e:
            self.syntax_error = e
            sublime.set_timeout(self.handle_syntax_error, 0)
            return
コード例 #14
0
ファイル: sublime_rope.py プロジェクト: Burekas/sublimeconf
    def run(self):
        errors = []

        try:
            tree = parse(self.code, filename=self.filename)
        except (SyntaxError, IndentationError, ValueError), e:
            self.syntax_error = e
            sublime.set_timeout(self.handle_syntax_error, 0)
            return
コード例 #15
0
 def __init__(self, pycore, resource=None, force_errors=False):
     self.resource = resource
     init_dot_py = self._get_init_dot_py()
     if init_dot_py is not None:
         ast_node = pycore.project.get_pymodule(
             init_dot_py, force_errors=force_errors).get_ast()
     else:
         ast_node = ast.parse('\n')
     super(PyPackage, self).__init__(pycore, ast_node, resource)
コード例 #16
0
 def _create_pattern(self, expression):
     expression = self._replace_wildcards(expression)
     node = ast.parse(expression)
     # Getting Module.Stmt.nodes
     nodes = node.body
     if len(nodes) == 1 and isinstance(nodes[0], ast.Expr):
         # Getting Discard.expr
         wanted = nodes[0].value
     else:
         wanted = nodes
     return wanted
コード例 #17
0
ファイル: similarfinder.py プロジェクト: Kha/rope
 def _create_pattern(self, expression):
     expression = self._replace_wildcards(expression)
     node = ast.parse(expression)
     # Getting Module.Stmt.nodes
     nodes = node.body
     if len(nodes) == 1 and isinstance(nodes[0], ast.Expr):
         # Getting Discard.expr
         wanted = nodes[0].value
     else:
         wanted = nodes
     return wanted
コード例 #18
0
ファイル: pyobjectsdef.py プロジェクト: kssd/bootstraps
 def __init__(self, pycore, source=None, resource=None, force_errors=False):
     ignore = pycore.project.prefs.get("ignore_syntax_errors", False)
     syntax_errors = force_errors or not ignore
     try:
         source, node = self._init_source(pycore, source, resource)
     except exceptions.ModuleSyntaxError:
         if syntax_errors:
             raise
         else:
             source = "\n"
             node = ast.parse("\n")
     self.source_code = source
     self.star_imports = []
     self.visitor_class = _GlobalVisitor
     self.coding = fscommands.read_str_coding(self.source_code)
     super(PyModule, self).__init__(pycore, node, resource)
コード例 #19
0
ファイル: pyobjectsdef.py プロジェクト: GunioRobot/emacs-3
 def __init__(self, pycore, source=None,
              resource=None, force_errors=False):
     ignore = pycore.project.prefs.get('ignore_syntax_errors', False)
     syntax_errors = force_errors or not ignore
     try:
         source, node = self._init_source(pycore, source, resource)
     except exceptions.ModuleSyntaxError:
         if syntax_errors:
             raise
         else:
             source = '\n'
             node = ast.parse('\n')
     self.source_code = source
     self.star_imports = []
     self.visitor_class = _GlobalVisitor
     super(PyModule, self).__init__(pycore, node, resource)
コード例 #20
0
ファイル: pyobjectsdef.py プロジェクト: GunioRobot/emacs-3
 def _init_source(self, pycore, source_code, resource):
     filename = 'string'
     if resource:
         filename = resource.path
     try:
         if source_code is None:
             source_bytes = resource.read_bytes()
             source_code = fscommands.file_data_to_unicode(source_bytes)
         else:
             if isinstance(source_code, unicode):
                 source_bytes = fscommands.unicode_to_file_data(source_code)
             else:
                 source_bytes = source_code
         ast_node = ast.parse(source_bytes, filename=filename)
     except SyntaxError, e:
         raise exceptions.ModuleSyntaxError(filename, e.lineno, e.msg)
コード例 #21
0
 def _init_source(self, pycore, source_code, resource):
     filename = 'string'
     if resource:
         filename = resource.path
     try:
         if source_code is None:
             source_bytes = resource.read_bytes()
             source_code = fscommands.file_data_to_unicode(source_bytes)
         else:
             if isinstance(source_code, unicode):
                 source_bytes = fscommands.unicode_to_file_data(source_code)
             else:
                 source_bytes = source_code
         ast_node = ast.parse(source_bytes, filename=filename)
     except SyntaxError, e:
         raise exceptions.ModuleSyntaxError(filename, e.lineno, e.msg)
コード例 #22
0
 def __init__(self, pycore, source=None, resource=None, force_errors=False):
     ignore = pycore.project.prefs.get('ignore_syntax_errors', False)
     syntax_errors = force_errors or not ignore
     try:
         source, node = self._init_source(pycore, source, resource)
     except exceptions.ModuleSyntaxError:
         if syntax_errors:
             raise
         else:
             source = '\n'
             node = ast.parse('\n')
     self.source_code = source
     self.star_imports = []
     self.visitor_class = _GlobalVisitor
     self.coding = fscommands.read_str_coding(self.source_code)
     super(PyModule, self).__init__(pycore, node, resource)
コード例 #23
0
ファイル: suitestest.py プロジェクト: hkdb/sysconfig
def source_suite_tree(source):
    return suites.ast_suite_tree(ast.parse(source))
コード例 #24
0
def _parse_text(body):
    body = sourceutils.fix_indentation(body, 0)
    node = ast.parse(body)
    return node
コード例 #25
0
ファイル: evaluate.py プロジェクト: FredSanders/emacs.d
def get_string_result(scope, string):
    """use `get_pyname_in_scope` instead"""
    evaluator = StatementEvaluator(scope)
    node = ast.parse(string)
    ast.walk(node, evaluator)
    return evaluator.result
コード例 #26
0
ファイル: outline.py プロジェクト: brucexin/bruce-s-profiles
 def get_root_nodes(self, source_code):
     if isinstance(source_code, unicode):
         source_code = source_code.encode('utf-8')
     ast_node = ast.parse(source_code)
     return _get_ast_children(ast_node)
コード例 #27
0
ファイル: suitestest.py プロジェクト: emacsway/rope
def source_suite_tree(source):
    return suites.ast_suite_tree(ast.parse(source))
コード例 #28
0
ファイル: notes.py プロジェクト: brucexin/bruce-s-profiles
 def errors(self, source):
     try:
         ast.parse(source)
     except SyntaxError, e:
         return [(e.lineno, e.msg)]