当前位置: 首页>>代码示例>>Python>>正文


Python ast.Const方法代码示例

本文整理汇总了Python中compiler.ast.Const方法的典型用法代码示例。如果您正苦于以下问题:Python ast.Const方法的具体用法?Python ast.Const怎么用?Python ast.Const使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在compiler.ast的用法示例。


在下文中一共展示了ast.Const方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _default_args_handler

# 需要导入模块: from compiler import ast [as 别名]
# 或者: from compiler.ast import Const [as 别名]
def _default_args_handler(self, node, arg_names, current_klass,
                              output=None):
        if len(node.defaults):
            output = output or self.output
            default_pos = len(arg_names) - len(node.defaults)
            if arg_names and arg_names[0] == self.method_self:
                default_pos -= 1
            for default_node in node.defaults:
                if isinstance(default_node, ast.Const):
                    default_value = self._const(default_node)
                elif isinstance(default_node, ast.Name):
                    default_value = self._name(default_node, current_klass)
                elif isinstance(default_node, ast.UnarySub):
                    default_value = self._unarysub(default_node, current_klass)
                else:
                    raise TranslationError("unsupported type (in _method)", default_node)

                default_name = arg_names[default_pos]
                default_pos += 1
                self.printo("    if (typeof %s == 'undefined') %s=%s;" % (default_name, default_name, default_value)) 
开发者ID:thiagoralves,项目名称:OpenPLC_Editor,代码行数:22,代码来源:pyjs.py

示例2: is_constant_false

# 需要导入模块: from compiler import ast [as 别名]
# 或者: from compiler.ast import Const [as 别名]
def is_constant_false(node):
    if isinstance(node, ast.Const):
        if not node.value:
            return 1
    return 0 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:7,代码来源:pycodegen.py

示例3: visitIf

# 需要导入模块: from compiler import ast [as 别名]
# 或者: from compiler.ast import Const [as 别名]
def visitIf(self, node, scope):
        for test, body in node.tests:
            if isinstance(test, ast.Const):
                if type(test.value) in self._const_types:
                    if not test.value:
                        continue
            self.visit(test, scope)
            self.visit(body, scope)
        if node.else_:
            self.visit(node.else_, scope)

    # a yield statement signals a generator 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:14,代码来源:symbols.py

示例4: _Sliceobj

# 需要导入模块: from compiler import ast [as 别名]
# 或者: from compiler.ast import Const [as 别名]
def _Sliceobj(self, t):
        for i, node in enumerate(t.nodes):
            if i != 0:
                self._write(":")
            if not (isinstance(node, Const) and node.value is None):
                self._dispatch(node) 
开发者ID:jakevdp,项目名称:supersmoother,代码行数:8,代码来源:compiler_unparse.py

示例5: CheckNode

# 需要导入模块: from compiler import ast [as 别名]
# 或者: from compiler.ast import Const [as 别名]
def CheckNode(node, keypath):
  if isinstance(node, Dict):
    c = node.getChildren()
    dict = {}
    for n in range(0, len(c), 2):
      assert isinstance(c[n], Const)
      key = c[n].getChildren()[0]
      if key in dict:
        raise GypError("Key '" + key + "' repeated at level " +
              repr(len(keypath) + 1) + " with key path '" +
              '.'.join(keypath) + "'")
      kp = list(keypath)  # Make a copy of the list for descending this node.
      kp.append(key)
      dict[key] = CheckNode(c[n + 1], kp)
    return dict
  elif isinstance(node, List):
    c = node.getChildren()
    children = []
    for index, child in enumerate(c):
      kp = list(keypath)  # Copy list.
      kp.append(repr(index))
      children.append(CheckNode(child, kp))
    return children
  elif isinstance(node, Const):
    return node.getChildren()[0]
  else:
    raise TypeError("Unknown AST node at key path '" + '.'.join(keypath) +
         "': " + repr(node)) 
开发者ID:zhaoolee,项目名称:StarsAndClown,代码行数:30,代码来源:input.py

示例6: CheckNode

# 需要导入模块: from compiler import ast [as 别名]
# 或者: from compiler.ast import Const [as 别名]
def CheckNode(node, keypath):
  if isinstance(node, Dict):
    c = node.getChildren()
    dict = {}
    for n in range(0, len(c), 2):
      assert isinstance(c[n], Const)
      key = c[n].getChildren()[0]
      if key in dict:
        raise GypError("Key '" + key + "' repeated at level " +
              repr(len(keypath) + 1) + " with key path '" +
              '.'.join(keypath) + "'")
      kp = list(keypath)  # Make a copy of the list for descending this node.
      kp.append(key)
      dict[key] = CheckNode(c[n + 1], kp)
    return dict
  elif isinstance(node, List):
    c = node.getChildren()
    children = []
    for index, child in enumerate(c):
      kp = list(keypath)  # Copy list.
      kp.append(repr(index))
      children.append(CheckNode(child, kp))
    return children
  elif isinstance(node, Const):
    return node.getChildren()[0]
  else:
    raise TypeError, "Unknown AST node at key path '" + '.'.join(keypath) + \
         "': " + repr(node) 
开发者ID:kawalpemilu,项目名称:kawalpemilu2014,代码行数:30,代码来源:input.py

示例7: _kwargs_parser

# 需要导入模块: from compiler import ast [as 别名]
# 或者: from compiler.ast import Const [as 别名]
def _kwargs_parser(self, node, function_name, arg_names, current_klass):
        if len(node.defaults) or node.kwargs:
            default_pos = len(arg_names) - len(node.defaults)
            if arg_names and arg_names[0] == self.method_self:
                default_pos -= 1
            self.printo(function_name+'.parse_kwargs = function (', ", ".join(["__kwargs"]+arg_names), ") {")
            for _default_node in node.defaults:
                # default_value = self.expr(default_node, current_klass)
                # if isinstance(default_node, ast.Const):
                #     default_value = self._const(default_node)
                # elif isinstance(default_node, ast.Name):
                #     default_value = self._name(default_node)
                # elif isinstance(default_node, ast.UnarySub):
                #     default_value = self._unarysub(default_node, current_klass)
                # else:
                #     raise TranslationError("unsupported type (in _method)", default_node)

                default_name = arg_names[default_pos]
                self.printo("    if (typeof %s == 'undefined')" % (default_name))
                self.printo("        %s=__kwargs.%s;" % (default_name, default_name))
                default_pos += 1

            # self._default_args_handler(node, arg_names, current_klass)
            if node.kwargs:
                arg_names += ["pyjslib.Dict(__kwargs)"]
            self.printo("    var __r = "+"".join(["[", ", ".join(arg_names), "]"])+";")
            if node.varargs:
                self._varargs_handler(node, "__args", arg_names, current_klass)
                self.printo("    __r.push.apply(__r, __args.getArray())")
            self.printo("    return __r;")
            self.printo("};") 
开发者ID:thiagoralves,项目名称:OpenPLC_Editor,代码行数:33,代码来源:pyjs.py

示例8: _discard

# 需要导入模块: from compiler import ast [as 别名]
# 或者: from compiler.ast import Const [as 别名]
def _discard(self, node, current_klass):

        if isinstance(node.expr, ast.CallFunc):
            debugStmt = self.debug and not self._isNativeFunc(node)
            if debugStmt and isinstance(node.expr.node, ast.Name) and \
               node.expr.node.name == 'import_wait':
                debugStmt = False
            if debugStmt:
                st = self.get_line_trace(node)
                self.printo("sys.addstack('%s');\n" % st)
            if isinstance(node.expr.node, ast.Name) and node.expr.node.name == NATIVE_JS_FUNC_NAME:
                if len(node.expr.args) != 1:
                    raise TranslationError("native javascript function %s must have one arg" % NATIVE_JS_FUNC_NAME, node.expr)
                if not isinstance(node.expr.args[0], ast.Const):
                    raise TranslationError("native javascript function %s must have constant arg" % NATIVE_JS_FUNC_NAME, node.expr)
                raw_js = node.expr.args[0].value
                self.printo(raw_js)
            else:
                expr = self._callfunc(node.expr, current_klass)
                self.printo("    " + expr + ";")

            if debugStmt:
                self.printo("sys.popstack();\n")

        elif isinstance(node.expr, ast.Const):
            if node.expr.value is not None:  # Empty statements generate ignore None
                self.printo(self._const(node.expr))
        else:
            raise TranslationError("unsupported type (in _discard)", node.expr) 
开发者ID:thiagoralves,项目名称:OpenPLC_Editor,代码行数:31,代码来源:pyjs.py

示例9: _mod

# 需要导入模块: from compiler import ast [as 别名]
# 或者: from compiler.ast import Const [as 别名]
def _mod(self, node, current_klass):
        if isinstance(node.left, ast.Const) and isinstance(node.left.value, str):
            self.imported_js.add("sprintf.js")  # Include the sprintf functionality if it is used
            return "sprintf("+self.expr(node.left, current_klass) + ", " + self.expr(node.right, current_klass)+")"
        return self.expr(node.left, current_klass) + " % " + self.expr(node.right, current_klass) 
开发者ID:thiagoralves,项目名称:OpenPLC_Editor,代码行数:7,代码来源:pyjs.py


注:本文中的compiler.ast.Const方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。