當前位置: 首頁>>代碼示例>>Python>>正文


Python parser.expr方法代碼示例

本文整理匯總了Python中parser.expr方法的典型用法代碼示例。如果您正苦於以下問題:Python parser.expr方法的具體用法?Python parser.expr怎麽用?Python parser.expr使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在parser的用法示例。


在下文中一共展示了parser.expr方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: decorator

# 需要導入模塊: import parser [as 別名]
# 或者: from parser import expr [as 別名]
def decorator(self, nodelist):
        # '@' dotted_name [ '(' [arglist] ')' ]
        assert len(nodelist) in (3, 5, 6)
        assert nodelist[0][0] == token.AT
        assert nodelist[-1][0] == token.NEWLINE

        assert nodelist[1][0] == symbol.dotted_name
        funcname = self.decorator_name(nodelist[1][1:])

        if len(nodelist) > 3:
            assert nodelist[2][0] == token.LPAR
            expr = self.com_call_function(funcname, nodelist[3])
        else:
            expr = funcname

        return expr 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:18,代碼來源:transformer.py

示例2: build_atom

# 需要導入模塊: import parser [as 別名]
# 或者: from parser import expr [as 別名]
def build_atom(expr_string):
    """ Build an ast for an atom from the given expr string.

        If expr_string is not a string, it is converted to a string
        before parsing to an ast_tuple.
    """
    # the [1][1] indexing below starts atoms at the third level
    # deep in the resulting parse tree.  parser.expr will return
    # a tree rooted with eval_input -> test_list -> test ...
    # I'm considering test to be the root of atom symbols.
    # It might be a better idea to move down a little in the
    # parse tree. Any benefits? Right now, this works fine.
    if isinstance(expr_string, str):
        ast = parser.expr(expr_string).totuple()[1][1]
    else:
        ast = parser.expr(repr(expr_string)).totuple()[1][1]
    return ast 
開發者ID:ktraunmueller,項目名稱:Computable,代碼行數:19,代碼來源:ast_tools.py

示例3: __new__

# 需要導入模塊: import parser [as 別名]
# 或者: from parser import expr [as 別名]
def __new__(cls,
                name,
                expr,
                replace = False):
        # code
        efound = expr in [Variable.variables[key].expr for key in Variable.variables]
        if efound:
            key = [key for key in Variable.variables if expr in Variable.variables[key].expr]
            logger.info("Expression '%s' already exists for key %s", expr, key)
            return
        else:
            if replace or not name in Variable.variables:
                if not valid_name(name):
                    logger.info("Invalid variable key: %s", name)
                    return
                try:
                    result = parser.expr(expr)
                except:
                    logger.info("Invalid expression: %s", expr)
                    return
                return super(Variable, cls).__new__(cls)
            else:
                logger.info("Key %s already exists", name)

    # function __init__ 
開發者ID:ScottfreeLLC,項目名稱:AlphaPy,代碼行數:27,代碼來源:variables.py

示例4: eval_string_and_vars

# 需要導入模塊: import parser [as 別名]
# 或者: from parser import expr [as 別名]
def eval_string_and_vars(eq_string, vars_in):
    for var in vars_in:
        eq_string = eq_string.replace(var, str(vars_in[var]))
    eq = parser.expr(eq_string).compile()
    return eval(eq) 
開發者ID:nimaid,項目名稱:LPHK,代碼行數:7,代碼來源:parse.py

示例5: evaluate_marker

# 需要導入模塊: import parser [as 別名]
# 或者: from parser import expr [as 別名]
def evaluate_marker(cls, text, extra=None):
        """
        Evaluate a PEP 426 environment marker on CPython 2.4+.
        Return a boolean indicating the marker result in this environment.
        Raise SyntaxError if marker is invalid.

        This implementation uses the 'parser' module, which is not implemented
        on
        Jython and has been superseded by the 'ast' module in Python 2.6 and
        later.
        """
        return cls.interpret(parser.expr(text).totuple(1)[1]) 
開發者ID:jpush,項目名稱:jbox,代碼行數:14,代碼來源:__init__.py

示例6: check_expr

# 需要導入模塊: import parser [as 別名]
# 或者: from parser import expr [as 別名]
def check_expr(self, s):
        self.roundtrip(parser.expr, s) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:4,代碼來源:test_parser.py

示例7: test_compile_expr

# 需要導入模塊: import parser [as 別名]
# 或者: from parser import expr [as 別名]
def test_compile_expr(self):
        st = parser.expr('2 + 3')
        code = parser.compilest(st)
        self.assertEqual(eval(code), 5) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:6,代碼來源:test_parser.py

示例8: test_issue_9011

# 需要導入模塊: import parser [as 別名]
# 或者: from parser import expr [as 別名]
def test_issue_9011(self):
        # Issue 9011: compilation of an unary minus expression changed
        # the meaning of the ST, so that a second compilation produced
        # incorrect results.
        st = parser.expr('-3')
        code1 = parser.compilest(st)
        self.assertEqual(eval(code1), -3)
        code2 = parser.compilest(st)
        self.assertEqual(eval(code2), -3) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:11,代碼來源:test_parser.py

示例9: test_deeply_nested_list

# 需要導入模塊: import parser [as 別名]
# 或者: from parser import expr [as 別名]
def test_deeply_nested_list(self):
        e = self._nested_expression(99)
        st = parser.expr(e)
        st.compile() 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:6,代碼來源:test_parser.py

示例10: test_copy_pickle

# 需要導入模塊: import parser [as 別名]
# 或者: from parser import expr [as 別名]
def test_copy_pickle(self):
        sts = [
            parser.expr('2 + 3'),
            parser.suite('x = 2; y = x + 3'),
            parser.expr('list(x**3 for x in range(20))')
        ]
        for st in sts:
            st_copy = copy.copy(st)
            self.assertEqual(st_copy.totuple(), st.totuple())
            st_copy = copy.deepcopy(st)
            self.assertEqual(st_copy.totuple(), st.totuple())
            for proto in range(pickle.HIGHEST_PROTOCOL+1):
                st_copy = pickle.loads(pickle.dumps(st, proto))
                self.assertEqual(st_copy.totuple(), st.totuple()) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:16,代碼來源:test_parser.py

示例11: parseexpr

# 需要導入模塊: import parser [as 別名]
# 或者: from parser import expr [as 別名]
def parseexpr(self, text):
        """Return a modified parse tree for the given expression text."""
        return self.transform(parser.expr(text)) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:5,代碼來源:transformer.py

示例12: yield_stmt

# 需要導入模塊: import parser [as 別名]
# 或者: from parser import expr [as 別名]
def yield_stmt(self, nodelist):
        expr = self.com_node(nodelist[0])
        return Discard(expr, lineno=expr.lineno) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:5,代碼來源:transformer.py

示例13: exec_stmt

# 需要導入模塊: import parser [as 別名]
# 或者: from parser import expr [as 別名]
def exec_stmt(self, nodelist):
        # exec_stmt: 'exec' expr ['in' expr [',' expr]]
        expr1 = self.com_node(nodelist[1])
        if len(nodelist) >= 4:
            expr2 = self.com_node(nodelist[3])
            if len(nodelist) >= 6:
                expr3 = self.com_node(nodelist[5])
            else:
                expr3 = None
        else:
            expr2 = expr3 = None

        return Exec(expr1, expr2, expr3, lineno=nodelist[0][2]) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:15,代碼來源:transformer.py

示例14: testlist

# 需要導入模塊: import parser [as 別名]
# 或者: from parser import expr [as 別名]
def testlist(self, nodelist):
        # testlist: expr (',' expr)* [',']
        # testlist_safe: test [(',' test)+ [',']]
        # exprlist: expr (',' expr)* [',']
        return self.com_binary(Tuple, nodelist) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:7,代碼來源:transformer.py

示例15: expr

# 需要導入模塊: import parser [as 別名]
# 或者: from parser import expr [as 別名]
def expr(self, nodelist):
        # xor_expr ('|' xor_expr)*
        return self.com_binary(Bitor, nodelist) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:5,代碼來源:transformer.py


注:本文中的parser.expr方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。