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


Python pyparsing.ParserElement方法代码示例

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


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

示例1: _set_matcher_element_attributes

# 需要导入模块: import pyparsing [as 别名]
# 或者: from pyparsing import ParserElement [as 别名]
def _set_matcher_element_attributes(self, element):
        # Set the ParserElement's action.
        element.setParseAction(self._parse_action)

        # Save the element's original postParse function.
        closure = element.postParse

        # Set a new function and use the original function for returning values.
        def postParse(instring, loc, tokenlist):
            if isinstance(tokenlist, pyparsing.ParseResults):
                s = " ".join(tokenlist.asList())
            elif isinstance(tokenlist, list):
                s = "".join(tokenlist)
            elif isinstance(tokenlist, string_types):
                s = tokenlist
            else:
                raise TypeError("postParse received invalid tokenlist %s"
                                % tokenlist)
            self.matching_slice = slice(loc - len(s), loc)
            return closure(instring, loc, tokenlist)

        element.postParse = postParse

        # Return the element.
        return element 
开发者ID:Danesprite,项目名称:pyjsgf,代码行数:27,代码来源:expansions.py

示例2: get_protein_modification_language

# 需要导入模块: import pyparsing [as 别名]
# 或者: from pyparsing import ParserElement [as 别名]
def get_protein_modification_language(concept_qualified: ParserElement) -> ParserElement:
    """Build a protein modification parser."""
    pmod_concept = MatchFirst([
        concept_qualified,
        pmod_default_ns,
        pmod_legacy_ns,
    ])

    return pmod_tag + nest(
        Group(pmod_concept)(CONCEPT)
        + Optional(
            WCW
            + amino_acid(PMOD_CODE)
            + Optional(WCW + ppc.integer(PMOD_POSITION)),
        ),
    ) 
开发者ID:pybel,项目名称:pybel,代码行数:18,代码来源:protein_modification.py

示例3: to_railroad

# 需要导入模块: import pyparsing [as 别名]
# 或者: from pyparsing import ParserElement [as 别名]
def to_railroad(
    element: pyparsing.ParserElement,
    diagram_kwargs: dict = {},
    vertical: Union[int, bool] = 5,
) -> List[NamedDiagram]:
    """
    Convert a pyparsing element tree into a list of diagrams. This is the recommended entrypoint to diagram
    creation if you want to access the Railroad tree before it is converted to HTML
    :param diagram_kwargs: kwargs to pass to the Diagram() constructor
    """
    # Convert the whole tree underneath the root
    lookup = ConverterState(diagram_kwargs=diagram_kwargs)
    _to_diagram_element(element, lookup=lookup, parent=None, vertical=vertical)

    root_id = id(element)
    # Convert the root if it hasn't been already
    if root_id in lookup.first:
        lookup.first[root_id].mark_for_extraction(root_id, lookup, force=True)

    # Now that we're finished, we can convert from intermediate structures into Railroad elements
    resolved = [resolve_partial(partial) for partial in lookup.diagrams.values()]
    return sorted(resolved, key=lambda diag: diag.index) 
开发者ID:pyparsing,项目名称:pyparsing,代码行数:24,代码来源:__init__.py

示例4: __init__

# 需要导入模块: import pyparsing [as 别名]
# 或者: from pyparsing import ParserElement [as 别名]
def __init__(
        self,
        element: pyparsing.ParserElement,
        converted: EditablePartial,
        parent: EditablePartial,
        number: int,
        name: str = None,
        index: Optional[int] = None,
    ):
        #: The pyparsing element that this represents
        self.element = element  # type: pyparsing.ParserElement
        #: The name of the element
        self.name = name  # type: str
        #: The output Railroad element in an unconverted state
        self.converted = converted  # type: EditablePartial
        #: The parent Railroad element, which we store so that we can extract this if it's duplicated
        self.parent = parent  # type: EditablePartial
        #: The order in which we found this element, used for sorting diagrams if this is extracted into a diagram
        self.number = number  # type: int
        #: The index of this inside its parent
        self.parent_index = index  # type: Optional[int]
        #: If true, we should extract this out into a subdiagram
        self.extract = False  # type: bool
        #: If true, all of this element's chilren have been filled out
        self.complete = False  # type: bool 
开发者ID:pyparsing,项目名称:pyparsing,代码行数:27,代码来源:__init__.py

示例5: matcher_element

# 需要导入模块: import pyparsing [as 别名]
# 或者: from pyparsing import ParserElement [as 别名]
def matcher_element(self):
        """
        Lazily initialised `pyparsing` ``ParserElement`` used to match speech to
        expansions. It will also set ``current_match`` values.

        :returns: pyparsing.ParserElement
        """
        if not self._matcher_element:
            element = self._make_matcher_element()
            self._matcher_element = element
        else:
            element = self._matcher_element
        return element 
开发者ID:Danesprite,项目名称:pyjsgf,代码行数:15,代码来源:expansions.py

示例6: __init__

# 需要导入模块: import pyparsing [as 别名]
# 或者: from pyparsing import ParserElement [as 别名]
def __init__(self, language: ParserElement, streamline: bool = False) -> None:
        """Build a parser wrapper using a PyParsing language.

        :param language: The PyParsing language to use
        :param streamline: Should the language be streamlined on instantiation?
        """
        self.language = language

        #: The parser holds an internal state of the current line
        self._line_number = 0

        if streamline:
            self.streamline() 
开发者ID:pybel,项目名称:pybel,代码行数:15,代码来源:baseparser.py

示例7: get_fragment_language

# 需要导入模块: import pyparsing [as 别名]
# 或者: from pyparsing import ParserElement [as 别名]
def get_fragment_language() -> ParserElement:
    """Build a protein fragment parser."""
    _fragment_value_inner = fragment_range | missing_fragment(FRAGMENT_MISSING)
    _fragment_value = _fragment_value_inner | And([Suppress('"'), _fragment_value_inner, Suppress('"')])
    parser_element = fragment_tag + nest(_fragment_value + Optional(WCW + quote(FRAGMENT_DESCRIPTION)))
    return parser_element 
开发者ID:pybel,项目名称:pybel,代码行数:8,代码来源:fragment.py

示例8: get_truncation_language

# 需要导入模块: import pyparsing [as 别名]
# 或者: from pyparsing import ParserElement [as 别名]
def get_truncation_language() -> ParserElement:
    """Build a parser for protein truncations."""
    l1 = truncation_tag + nest(amino_acid(AMINO_ACID) + ppc.integer(TRUNCATION_POSITION))
    l1.setParseAction(_handle_trunc)
    l2 = truncation_tag + nest(ppc.integer(TRUNCATION_POSITION))
    l2.setParseAction(_handle_trunc_legacy)
    return l1 | l2 
开发者ID:pybel,项目名称:pybel,代码行数:9,代码来源:truncation.py

示例9: get_gene_modification_language

# 需要导入模块: import pyparsing [as 别名]
# 或者: from pyparsing import ParserElement [as 别名]
def get_gene_modification_language(concept_qualified: ParserElement) -> ParserElement:
    """Build a gene modification parser."""
    concept = MatchFirst([
        concept_qualified,
        gmod_default_ns,
    ])
    return gmod_tag + nest(Group(concept)(CONCEPT)) 
开发者ID:pybel,项目名称:pybel,代码行数:9,代码来源:gene_modification.py

示例10: get_protein_substitution_language

# 需要导入模块: import pyparsing [as 别名]
# 或者: from pyparsing import ParserElement [as 别名]
def get_protein_substitution_language() -> ParserElement:
    """Build a protein substitution parser."""
    parser_element = psub_tag + nest(
        amino_acid(PSUB_REFERENCE),
        ppc.integer(PSUB_POSITION),
        amino_acid(PSUB_VARIANT),
    )
    parser_element.setParseAction(_handle_psub)
    return parser_element 
开发者ID:pybel,项目名称:pybel,代码行数:11,代码来源:protein_substitution.py

示例11: get_hgvs_language

# 需要导入模块: import pyparsing [as 别名]
# 或者: from pyparsing import ParserElement [as 别名]
def get_hgvs_language() -> ParserElement:
    """Build a HGVS :class:`pyparsing.ParseElement`."""
    hgvs = (variant_characters | quote)(HGVS)
    language = variant_tags + nest(hgvs)
    return language 
开发者ID:pybel,项目名称:pybel,代码行数:7,代码来源:variant.py

示例12: get_location_language

# 需要导入模块: import pyparsing [as 别名]
# 或者: from pyparsing import ParserElement [as 别名]
def get_location_language(identifier: ParserElement) -> ParserElement:
    """Build a location parser."""
    return Group(location_tag + nest(identifier))(LOCATION) 
开发者ID:pybel,项目名称:pybel,代码行数:5,代码来源:location.py

示例13: _worth_extracting

# 需要导入模块: import pyparsing [as 别名]
# 或者: from pyparsing import ParserElement [as 别名]
def _worth_extracting(element: pyparsing.ParserElement) -> bool:
    """
    Returns true if this element is worth having its own sub-diagram. Simply, if any of its children
    themselves have children, then its complex enough to extract
    """
    children = element.recurse()
    return any(
        [hasattr(child, "expr") or hasattr(child, "exprs") for child in children]
    ) 
开发者ID:pyparsing,项目名称:pyparsing,代码行数:11,代码来源:__init__.py

示例14: flatten_pyparsing_exprs

# 需要导入模块: import pyparsing [as 别名]
# 或者: from pyparsing import ParserElement [as 别名]
def flatten_pyparsing_exprs(expr):
    exprs = set()
    for child in expr.exprs:
        if isinstance(child, (Literal, six.string_types)):
            exprs.add(str(child).strip('"'))
        elif isinstance(child, (MatchFirst, ParseExpression, ParserElement)):
            exprs.update(flatten_pyparsing_exprs(child))
    return exprs 
开发者ID:sarugaku,项目名称:requirementslib,代码行数:10,代码来源:strategies.py

示例15: match

# 需要导入模块: import pyparsing [as 别名]
# 或者: from pyparsing import ParserElement [as 别名]
def match(cmp_value, spec):
    """Match a given value to a given spec DSL.

    This uses the grammar defined by make_grammar()

    :param cmp_value: Value to be checked for match.
    :param spec: The comparison specification string, for example ``">= 70"``
                 or ``"s== string_value"``. See ``make_grammar()`` for examples
                 of a specification string.
    :returns: True if cmp_value is a match for spec. False otherwise.
    """
    expr = make_grammar()
    try:
        # As of 2018-01-29 documentation on parseString()
        # https://pythonhosted.org/pyparsing/pyparsing.ParserElement-class.html#parseString
        #
        # parseString() will take our specification string, for example "< 6"
        # and convert it into a list of ['<', "6"]
        tree = expr.parseString(spec)
    except pyparsing.ParseException:
        # If an exception then we will just check if the value matches the spec
        tree = [spec]
    if len(tree) == 1:
        return tree[0] == cmp_value

    # tree[0] will contain a string representation of a comparison operation
    # such as '>=', we then convert that string to a comparison function
    compare_func = op_methods[tree[0]]
    return compare_func(cmp_value, *tree[1:]) 
开发者ID:openstack,项目名称:oslo.utils,代码行数:31,代码来源:specs_matcher.py


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