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


Python lark.Token方法代碼示例

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


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

示例1: _private_method_call_check

# 需要導入模塊: import lark [as 別名]
# 或者: from lark import Token [as 別名]
def _private_method_call_check(parse_tree: Tree) -> List[Problem]:
    problems = []
    for getattr_call in parse_tree.find_data("getattr_call"):
        _getattr = getattr_call.children[0]
        callee_name_token = _getattr.children[-1]
        callee_name = callee_name_token.value
        called = _getattr.children[-3]
        if (
            isinstance(called, Token)
            and called.type == "NAME"
            and called.value == "self"
        ):
            continue
        if not _is_method_private(callee_name):
            continue
        problems.append(
            Problem(
                name="private-method-call",
                description='Private method "{}" has been called'.format(callee_name),
                line=callee_name_token.line,
                column=callee_name_token.column,
            )
        )
    return problems 
開發者ID:Scony,項目名稱:godot-gdscript-toolkit,代碼行數:26,代碼來源:class_checks.py

示例2: scan_resource_conf

# 需要導入模塊: import lark [as 別名]
# 或者: from lark import Token [as 別名]
def scan_resource_conf(self, conf):
        """
            Looks for ACL configuration at aws_s3_bucket and Tag values:
            https://www.terraform.io/docs/providers/aws/r/s3_bucket.html
        :param conf: aws_s3_bucket configuration
        :return: <CheckResult>
        """
        if 'tags' in conf.keys():
            environment_tag = Token("IDENTIFIER", "Scope")
            if environment_tag in conf['tags'][0].keys():
                if conf['tags'][0][environment_tag] == "PCI":
                    if 'acl' in conf.keys():
                        acl_block = conf['acl']
                        if acl_block in [["public-read"], ["public-read-write"], ["website"]]:
                            return CheckResult.FAILED
        return CheckResult.PASSED 
開發者ID:bridgecrewio,項目名稱:checkov,代碼行數:18,代碼來源:S3PCIPrivateACL.py

示例3: fuzzy_string_op_rhs

# 需要導入模塊: import lark [as 別名]
# 或者: from lark import Token [as 別名]
def fuzzy_string_op_rhs(self, arg):
        # fuzzy_string_op_rhs: CONTAINS value | STARTS [ WITH ] value | ENDS [ WITH ] value

        # The WITH keyword may be omitted.
        if isinstance(arg[1], Token) and arg[1].type == "WITH":
            pattern = arg[2]
        else:
            pattern = arg[1]

        # CONTAINS
        if arg[0] == "CONTAINS":
            regex = f"{pattern}"
        elif arg[0] == "STARTS":
            regex = f"^{pattern}"
        elif arg[0] == "ENDS":
            regex = f"{pattern}$"
        return {"$regex": regex} 
開發者ID:Materials-Consortia,項目名稱:optimade-python-tools,代碼行數:19,代碼來源:mongo.py

示例4: is_foldable

# 需要導入模塊: import lark [as 別名]
# 或者: from lark import Token [as 別名]
def is_foldable(expression: Node) -> bool:
    if _is_multiline_string(expression):
        return True
    return not isinstance(expression, Token) and expression.data not in [
        "string",
        "node_path",
        "get_node",
    ] 
開發者ID:Scony,項目名稱:godot-gdscript-toolkit,代碼行數:10,代碼來源:expression_utils.py

示例5: is_expression_forcing_multiple_lines

# 需要導入模塊: import lark [as 別名]
# 或者: from lark import Token [as 別名]
def is_expression_forcing_multiple_lines(expression: Node) -> bool:
    if has_trailing_comma(expression):
        return True
    if _is_multiline_string(expression):
        return True
    if isinstance(expression, Token):
        return False
    for child in expression.children:
        if is_expression_forcing_multiple_lines(child):
            return True
    return False 
開發者ID:Scony,項目名稱:godot-gdscript-toolkit,代碼行數:13,代碼來源:expression_utils.py

示例6: is_any_comma

# 需要導入模塊: import lark [as 別名]
# 或者: from lark import Token [as 別名]
def is_any_comma(expression: Node) -> bool:
    return (isinstance(expression, Tree) and expression.data == "trailing_comma") or (
        isinstance(expression, Token) and expression.type == "COMMA"
    ) 
開發者ID:Scony,項目名稱:godot-gdscript-toolkit,代碼行數:6,代碼來源:expression_utils.py

示例7: is_any_parentheses

# 需要導入模塊: import lark [as 別名]
# 或者: from lark import Token [as 別名]
def is_any_parentheses(expression: Node) -> bool:
    return isinstance(expression, Token) and expression.type in ["LPAR", "RPAR"] 
開發者ID:Scony,項目名稱:godot-gdscript-toolkit,代碼行數:4,代碼來源:expression_utils.py

示例8: _load_name

# 需要導入模塊: import lark [as 別名]
# 或者: from lark import Token [as 別名]
def _load_name(enum_def: Tree) -> Optional[str]:
        if len(enum_def.children[0].children) == 0:
            return None
        node = enum_def.children[0].children[0]
        if isinstance(node, Token) and node.type == "NAME":
            return node.value
        return None 
開發者ID:Scony,項目名稱:godot-gdscript-toolkit,代碼行數:9,代碼來源:enum.py

示例9: _unused_argument_check

# 需要導入模塊: import lark [as 別名]
# 或者: from lark import Token [as 別名]
def _unused_argument_check(parse_tree: Tree) -> List[Problem]:
    problems = []
    for func_def in parse_tree.find_data("func_def"):
        if (
            isinstance(func_def.children[1], Tree)
            and func_def.children[1].data == "func_args"
        ):
            argument_definitions = {}  # type: Dict[str, int]
            argument_tokens = {}
            func_args = func_def.children[1]
            for func_arg in func_args.children:
                arg_name_token = find_name_token_among_children(func_arg)
                arg_name = arg_name_token.value
                argument_definitions[arg_name] = (
                    argument_definitions.get(arg_name, 0) + 1
                )
                argument_tokens[arg_name] = arg_name_token
            name_occurances = {}  # type: Dict[str, int]
            for xnode in func_def.iter_subtrees():
                for node in xnode.children:
                    if isinstance(node, Token) and node.type == "NAME":
                        name = node.value
                        name_occurances[name] = name_occurances.get(name, 0) + 1
            for argument in argument_definitions:
                if argument_definitions[argument] == name_occurances[
                    argument
                ] and not argument.startswith("_"):
                    problems.append(
                        Problem(
                            name="unused-argument",
                            description="unused function argument '{}'".format(
                                argument
                            ),
                            line=argument_tokens[argument].line,
                            column=argument_tokens[argument].column,
                        )
                    )
    return problems 
開發者ID:Scony,項目名稱:godot-gdscript-toolkit,代碼行數:40,代碼來源:basic_checks.py

示例10: find_name_token_among_children

# 需要導入模塊: import lark [as 別名]
# 或者: from lark import Token [as 別名]
def find_name_token_among_children(tree):
    for child in tree.children:
        if isinstance(child, Token) and child.type == "NAME":
            return child
    return None 
開發者ID:Scony,項目名稱:godot-gdscript-toolkit,代碼行數:7,代碼來源:helpers.py

示例11: ignore_errors

# 需要導入模塊: import lark [as 別名]
# 或者: from lark import Token [as 別名]
def ignore_errors(e):
    if e.token.type == 'COMMA':
        # Skip comma
        return True
    elif e.token.type == 'SIGNED_NUMBER':
        # Try to feed a comma and retry the number
        e.puppet.feed_token(Token('COMMA', ','))
        e.puppet.feed_token(e.token)
        return True

    # Unhandled error. Will stop parse and raise exception
    return False 
開發者ID:lark-parser,項目名稱:lark,代碼行數:14,代碼來源:error_puppet.py

示例12: extern_func

# 需要導入模塊: import lark [as 別名]
# 或者: from lark import Token [as 別名]
def extern_func(self, node):
        name, params, returns, newline = self.visit_children(node)
        name = name.value
        if isinstance(params, Token):
            params = self.token_to_val(params)
        if isinstance(returns, Token):
            returns = self.token_to_val(returns)
        from .variables import VarType
        params = [(VarType._init_from_parser(params[i*2]), params[(i*2)+1].value) \
            for i in range(len(params or []) // 2)]
        returns = [VarType._init_from_parser(r) for r in returns or []]
        existing = self.top.lookup_func(name)
        extern = ExternFunction(name, params, returns)
        if existing:
            existing.expect_signature(extern)
            if not existing.finished and \
               not isinstance(existing, ExternFunction):
                # This is a forward-referenced function, replace references
                # with our extern
                mapping = {existing: extern}
                for var in self.top.scope.values():
                    if isinstance(var, IRFunction):
                        var.preamble.apply_mapping(IRFunction, mapping)
                        for block in var.blocks:
                            block.apply_mapping(IRFunction, mapping)
                # Direct replacement
                self.top.scope[name] = extern
        else:
            self.top.store(name, extern) 
開發者ID:simon816,項目名稱:Command-Block-Assembly,代碼行數:31,代碼來源:reader.py

示例13: block

# 需要導入模塊: import lark [as 別名]
# 或者: from lark import Token [as 別名]
def block(self, node):
        if not isinstance(node.children[0], Token):
            # Modifier is first child
            name = node.children[1].value[:-1]
        else:
            name = node.children[0].value[:-1]
        self.curr_seq = self.func.get_or_create_block(name)
        self.visit_children(node)
        self.curr_seq.defined = True
        self.curr_seq = None 
開發者ID:simon816,項目名稱:Command-Block-Assembly,代碼行數:12,代碼來源:reader.py

示例14: operand

# 需要導入模塊: import lark [as 別名]
# 或者: from lark import Token [as 別名]
def operand(self, node):
        token = node.children[0]
        if isinstance(token, Token):
            return self.token_to_val(token)
        # must be tuple
        tup, = self.visit_children(node)
        return tup 
開發者ID:simon816,項目名稱:Command-Block-Assembly,代碼行數:9,代碼來源:reader.py

示例15: expression_to_str

# 需要導入模塊: import lark [as 別名]
# 或者: from lark import Token [as 別名]
def expression_to_str(expression: Node) -> str:
    if isinstance(expression, Token):
        return expression.value
    return {
        "expr": lambda e: standalone_expression_to_str(e.children[0]),
        "assnmnt_expr": _operator_chain_based_expression_to_str,
        "test_expr": _operator_chain_based_expression_to_str,
        "or_test": _operator_chain_based_expression_to_str,
        "and_test": _operator_chain_based_expression_to_str,
        "not_test": lambda e: "{} {}".format(
            expression_to_str(e.children[0]), expression_to_str(e.children[1])
        ),
        "content_test": _operator_chain_based_expression_to_str,
        "comparison": _operator_chain_based_expression_to_str,
        "bitw_or": _operator_chain_based_expression_to_str,
        "bitw_xor": _operator_chain_based_expression_to_str,
        "bitw_and": _operator_chain_based_expression_to_str,
        "shift_expr": _operator_chain_based_expression_to_str,
        "arith_expr": _operator_chain_based_expression_to_str,
        "mdr_expr": _operator_chain_based_expression_to_str,
        "neg_expr": lambda e: "-{}".format(expression_to_str(e.children[1])),
        "bitw_not": lambda e: "~{}".format(expression_to_str(e.children[1])),
        "type_test": _operator_chain_based_expression_to_str,
        "type_cast": _operator_chain_based_expression_to_str,
        "standalone_call": _standalone_call_to_str,
        "getattr_call": _getattr_call_to_str,
        "getattr": lambda e: "".join(map(expression_to_str, e.children)),
        "subscr_expr": _subscription_to_str,
        "par_expr": lambda e: "({})".format(
            standalone_expression_to_str(e.children[0])
        ),
        "array": _array_to_str,
        "dict": _dict_to_str,
        "kv_pair": lambda e: _dict_element_to_str(e.children[0]),
        "c_dict_element": _dict_element_to_str,
        "eq_dict_element": _dict_element_to_str,
        "string": lambda e: e.children[0].value,
        "node_path": lambda e: "@{}".format(expression_to_str(e.children[0])),
        "get_node": lambda e: "${}".format(expression_to_str(e.children[0])),
        "path": lambda e: "/".join([name_token.value for name_token in e.children]),
        # fake expressions:
        "func_arg_regular": lambda e: "{}{}".format(
            e.children[0].value,
            " = {}".format(standalone_expression_to_str(e.children[1]))
            if len(e.children) > 1
            else "",
        ),
        "func_arg_inf": lambda e: "{} := {}".format(
            e.children[0].value, standalone_expression_to_str(e.children[1])
        ),
        "func_arg_typed": lambda e: "{}: {}{}".format(
            e.children[0].value,
            e.children[1].value,
            " = {}".format(standalone_expression_to_str(e.children[2]))
            if len(e.children) > 2
            else "",
        ),
        # patterns (fake expressions):
        "wildcard_pattern": lambda _: "_",
        "attr_pattern": lambda e: ".".join(map(expression_to_str, e.children[::2])),
    }[expression.data](expression) 
開發者ID:Scony,項目名稱:godot-gdscript-toolkit,代碼行數:63,代碼來源:expression_to_str.py


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