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


Python Regex.setResultsName方法代码示例

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


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

示例1: define_identifier

# 需要导入模块: from pyparsing import Regex [as 别名]
# 或者: from pyparsing.Regex import setResultsName [as 别名]
 def define_identifier(self):
     """
     Return the syntax definition for an identifier.
     
     """
     # --- Defining the individual identifiers:
     # Getting all the Unicode numbers in a single string:
     unicode_numbers = "".join([unichr(n) for n in xrange(0x10000)
                                if unichr(n).isdigit()])
     unicode_number_expr = Regex("[%s]" % unicode_numbers, re.UNICODE)
     space_char = re.escape(self._grammar.get_token("identifier_spacing"))
     identifier0 = Regex("[\w%s]+" % space_char, re.UNICODE)
     # Identifiers cannot start with a number:
     identifier0 = Combine(~unicode_number_expr + identifier0)
     identifier0.setName("individual_identifier")
     
     # --- Defining the namespaces:
     namespace_sep = Suppress(self._grammar.get_token("namespace_separator"))
     namespace = Group(ZeroOrMore(identifier0 + namespace_sep))
     namespace.setName("namespace")
     
     # --- The full identifier, which could have a namespace:
     identifier = Combine(namespace.setResultsName("namespace_parts") +
                          identifier0.setResultsName("identifier"))
     identifier.setName("full_identifier")
     
     return identifier
开发者ID:aipub,项目名称:booleano,代码行数:29,代码来源:parsers.py

示例2: nexus_iter

# 需要导入模块: from pyparsing import Regex [as 别名]
# 或者: from pyparsing.Regex import setResultsName [as 别名]
def nexus_iter(infile):
    import pyparsing
    pyparsing.ParserElement.enablePackrat()
    from pyparsing import Word, Literal, QuotedString, CaselessKeyword, \
         OneOrMore, Group, Optional, Suppress, Regex, Dict
    ## beginblock = Suppress(CaselessKeyword("begin") +
    ##                       CaselessKeyword("trees") + ";")
    ## endblock = Suppress((CaselessKeyword("end") |
    ##                      CaselessKeyword("endblock")) + ";")
    comment = Optional(Suppress("[&") + Regex(r'[^]]+') + Suppress("]"))
    ## translate = CaselessKeyword("translate").suppress()
    name = Word(string.letters+string.digits+"_.") | QuotedString("'")
    ## ttrec = Group(Word(string.digits).setResultsName("number") +
    ##               name.setResultsName("name") +
    ##               Optional(",").suppress())
    ## ttable = Group(translate + OneOrMore(ttrec) + Suppress(";"))
    newick = Regex(r'[^;]+;')
    tree = (CaselessKeyword("tree").suppress() +
            Optional("*").suppress() +
            name.setResultsName("tree_name") +
            comment.setResultsName("tree_comment") +
            Suppress("=") +
            comment.setResultsName("root_comment") +
            newick.setResultsName("newick"))
    ## treesblock = Group(beginblock +
    ##                    Optional(ttable.setResultsName("ttable")) +
    ##                    Group(OneOrMore(tree)) +
    ##                    endblock)

    def not_begin(s): return s.strip().lower() != "begin trees;"
    def not_end(s): return s.strip().lower() not in ("end;", "endblock;")
    def parse_ttable(f):
        ttable = {}
        while True:
            s = f.next().strip()
            if not s: continue
            if s.lower() == ";": break
            if s[-1] == ",": s = s[:-1]
            k, v = s.split()
            ttable[k] = v
            if s[-1] == ";": break
        return ttable
            
    # read lines between "begin trees;" and "end;"
    f = itertools.takewhile(not_end, itertools.dropwhile(not_begin, infile))
    s = f.next().strip().lower()
    if s != "begin trees;":
        print sys.stderr, "Expecting 'begin trees;', got %s" % s
        raise StopIteration
    ttable = {}
    while True:
        try: s = f.next().strip()
        except StopIteration: break
        if not s: continue
        if s.lower() == "translate":
            ttable = parse_ttable(f)
            print "ttable: %s" % len(ttable)
        elif s.split()[0].lower()=='tree':
            match = tree.parseString(s)
            yield nexus.Newick(match, ttable)
开发者ID:ChriZiegler,项目名称:cython-experiments-1,代码行数:62,代码来源:newick.py

示例3: parse_treesblock

# 需要导入模块: from pyparsing import Regex [as 别名]
# 或者: from pyparsing.Regex import setResultsName [as 别名]
def parse_treesblock(infile):
    import string
    from pyparsing import Optional, Word, Regex, CaselessKeyword, Suppress
    from pyparsing import QuotedString
    comment = Optional(Suppress("[&") + Regex(r'[^]]+') + Suppress("]"))
    name = Word(alphanums+"_") | QuotedString("'")
    newick = Regex(r'[^;]+;')
    tree = (CaselessKeyword("tree").suppress() +
            Optional("*").suppress() +
            name.setResultsName("tree_name") +
            comment.setResultsName("tree_comment") +
            Suppress("=") +
            comment.setResultsName("root_comment") +
            newick.setResultsName("newick"))
    ## treesblock = Group(beginblock +
    ##                    Optional(ttable.setResultsName("ttable")) +
    ##                    Group(OneOrMore(tree)) +
    ##                    endblock)

    def parse_ttable(f):
        ttable = {}
        while True:
            s = f.next().strip()
            if s.lower() == ";":
                break
            if s[-1] in ",;":
                s = s[:-1]
            k, v = s.split()
            ttable[k] = v
            if s[-1] == ";":
                break
        return ttable

    ttable = {}
    while True:
        try:
            s = infile.next().strip()
        except StopIteration:
            break
        if s.lower() == "translate":
            ttable = parse_ttable(infile)
            # print("ttable: %s" % len(ttable))
        else:
            match = tree.parseString(s)
            yield Newick(match, ttable)
开发者ID:rhr,项目名称:ivy,代码行数:47,代码来源:nexus.py

示例4: either

# 需要导入模块: from pyparsing import Regex [as 别名]
# 或者: from pyparsing.Regex import setResultsName [as 别名]
# either (see tests/bibs). Cite keys can start with a digit
not_digname = Regex('[^\d\s"#%\'(),={}][^\s"#%\'(),={}]*')

# Comment comments out to end of line
comment = (AT + CaselessLiteral('comment') +
           Regex("[\s{(].*").leaveWhitespace())

# The name types with their digiteyness
not_dig_lower = not_digname.copy().setParseAction(
    lambda t: t[0].lower())
macro_def = not_dig_lower.copy()
macro_ref = not_dig_lower.copy().setParseAction(lambda t : Macro(t[0].lower()))
field_name = not_dig_lower.copy()
# Spaces in names mean they cannot clash with field names
entry_type = not_dig_lower.setResultsName('entry type')
cite_key = any_name.setResultsName('cite key')
# Number has to be before macro name
string = (number | macro_ref | quoted_string |
          curly_string)

# There can be hash concatenation
field_value = string + ZeroOrMore(HASH + string)
field_def = Group(field_name + EQUALS + field_value)
entry_contents = Dict(ZeroOrMore(field_def + COMMA) + Optional(field_def))

# Entry is surrounded either by parentheses or curlies
entry = (AT + entry_type +
         bracketed(cite_key + COMMA + entry_contents))

# Preamble is a macro-like thing with no name
preamble = AT + CaselessLiteral('preamble') + bracketed(field_value)
开发者ID:SYNchroACK,项目名称:crits_dependencies,代码行数:33,代码来源:btpyparse.py

示例5: delimitedList

# 需要导入模块: from pyparsing import Regex [as 别名]
# 或者: from pyparsing.Regex import setResultsName [as 别名]
normalized_port_range = (port ^ port_range).setParseAction(to_port_range)

ports  = delimitedList(normalized_port_range)('ports')

# IP addresses, name of another group, or sg-*
security_group = Regex("sg-[\w\d]+")
group_name = Regex("[\w\d\-]+")

mask = Word("/") + Word(nums).setParseAction(to_int)('mask')
ip= (Combine(Word(nums) + ('.' + Word(nums))*3)('ip') + Optional(mask)('mask')).setParseAction(normalize_ip)

parser = Optional(protocol)('protocol') + \
         Optional(port_) + \
         ports + \
         (ip.setResultsName('ip_and_mask') ^ security_group.setResultsName('security_group') ^ group_name('group_name'))


class Rule(object):

    def __init__(self, protocol, from_port, to_port, address=None, group=None, group_name=None):
        """constructs a new rule
        :param protocol tcp or udp
        :param from_port
        :param to_port
        :param address
        :param group sg-style (should almost never be used)
        :param group_name
        """
        self.protocol = protocol or "tcp"
        self.from_port = from_port
开发者ID:pombredanne,项目名称:roadhouse,代码行数:32,代码来源:groups.py

示例6: Group

# 需要导入模块: from pyparsing import Regex [as 别名]
# 或者: from pyparsing.Regex import setResultsName [as 别名]
        floatVector.setResultsName('position')) &
        (Keyword("axis") +
        rotationOrder.setResultsName("axisRotationOrder")) &
        (Keyword("orientation") +
        floatVector.setResultsName("axis"))
        ).setResultsName('root')
bone = Group(
        begin +
        Keyword("id") +
        intValue +
        Keyword("name") +
        bonename.setResultsName("name") +
        Keyword("direction") +
        floatVector.setResultsName("direction") +
        Keyword("length") +
        floatValue.setResultsName("length") +
        Keyword("axis") +
        floatVector.setResultsName("axis") +
        rotationOrder.setResultsName("axisRotationOrder") +
        Optional(
            Keyword("dof") +
            channels.setResultsName("channels") +
            Keyword("limits") +
            limits.setResultsName("limits")
            ) +
        end
        )

bonedataSection = (
        Keyword(":bonedata") +
        Group(ZeroOrMore(bone)).setResultsName("bones")
开发者ID:JonFountain,项目名称:imusim,代码行数:33,代码来源:asf_amc.py

示例7: map

# 需要导入模块: from pyparsing import Regex [as 别名]
# 或者: from pyparsing.Regex import setResultsName [as 别名]
            INTO|VALUES|DELETE|UPDATE|SET|CREATE|INDEX|USING|BTREE|HASH|
            ON|INTEGER|FLOAT|DATETIME|DATE|VARCHAR|CHAR|TABLE|DATABASE|
            DROP|ORDER|BY|ASC|DESC)

# Define basic symbols
LPAR, RPAR = map(Suppress, '()')
dot = Literal(".").suppress()
comma = Literal(",").suppress()
semi_colon  = Literal(";").suppress()

# Basic identifier used to define vars, tables, columns
identifier = ~keywords + Word(alphas, alphanums + '_')

# Literal Values
integer_literal = Regex(r"([+-]?[1-9][0-9]*|0)")
integer_literal = integer_literal.setResultsName('integer_literal')
float_literal = Regex(r"([+-]?[1-9][0-9]*|0)\.[0-9]+")
float_literal = float_literal.setResultsName('float_literal')
numeric_literal = float_literal | integer_literal
string_literal = QuotedString("'").setResultsName('string_literal')
literal_value = (numeric_literal|string_literal|NULL)

# SQL-Type-names
INTEGER = INTEGER.setResultsName('type_name')
FLOAT = FLOAT.setResultsName('type_name')
DATETIME = DATETIME.setResultsName('type_name')
DATE = DATE.setResultsName('type_name')
VARCHAR = VARCHAR.setResultsName('type_name')
CHAR = CHAR.setResultsName('type_name')

# SQL-Data-types
开发者ID:harold-valdivia-garcia,项目名称:pysilisk,代码行数:33,代码来源:sqlgrammar.py

示例8: Group

# 需要导入模块: from pyparsing import Regex [as 别名]
# 或者: from pyparsing.Regex import setResultsName [as 别名]
# quoted string is either just stuff within quotes, or stuff within quotes, within
# which there is nested curliness
quotedItem = Group(curlyString) | charsNoQuotecurly
quotedString = QUOTE + ZeroOrMore(quotedItem) + QUOTE

number = Regex("[0-9]+")
# Basis characters (by exclusion) for variable / field names.  The following
# list of characters is from the btparse documentation
anyName = Regex("[^\s\"#%'(),={}]+")

# btparse says, and the test bibs show by experiment, that macro and field names
# cannot start with a digit.  In fact entry type names cannot start with a digit
# either (see tests/bibs). Cite keys can start with a digit
notDigname = Regex("[^\d\s\"#%'(),={}][^\s\"#%'(),={}]*")

comment = AT + CaselessLiteral("comment") + LCURLY + charsNoCurly.setResultsName("comment") + RCURLY
comment.setParseAction(Comment.fromParseResult)

# The name types with their digiteyness
notDigLower = notDigname.copy().setParseAction(lambda t: t[0].lower())

macroDef = notDigLower.copy()

macroRef = notDigLower.copy().setParseAction(MacroReference.fromParseResult)
fieldName = notDigLower.copy()
entryType = notDigLower.setResultsName("entry type")
citeKey = anyName.setResultsName("cite key")
string = number | macroRef | quotedString | curlyString

# There can be hash concatenation
fieldValue = string + ZeroOrMore(HASH + string)
开发者ID:supermihi,项目名称:bibtexvcs,代码行数:33,代码来源:parser.py

示例9: either

# 需要导入模块: from pyparsing import Regex [as 别名]
# 或者: from pyparsing.Regex import setResultsName [as 别名]
# btparse says, and the test bibs show by experiment, that macro and field names
# cannot start with a digit.  In fact entry type names cannot start with a digit
# either (see tests/bibs). Cite keys can start with a digit
not_digname = Regex("[^\d\s\"#%'(),={}][^\s\"#%'(),={}]*")

# Comment comments out to end of line
comment = AT + CaselessLiteral("comment") + Regex("[\s{(].*").leaveWhitespace()

# The name types with their digiteyness
not_dig_lower = not_digname.copy().setParseAction(lambda t: t[0].lower())
macro_def = not_dig_lower.copy()
macro_ref = not_dig_lower.copy().setParseAction(lambda t: Macro(t[0].lower()))
field_name = not_dig_lower.copy()
# Spaces in names mean they cannot clash with field names
entry_type = not_dig_lower.setResultsName("entry type")
cite_key = any_name.setResultsName("cite key")
# Number has to be before macro name
string = number | macro_ref | quoted_string | curly_string

# There can be hash concatenation
field_value = string + ZeroOrMore(HASH + string)
field_def = Group(field_name + EQUALS + field_value)
entry_contents = Dict(ZeroOrMore(field_def + COMMA) + Optional(field_def))

# Entry is surrounded either by parentheses or curlies
entry = AT + entry_type + bracketed(cite_key + COMMA + entry_contents)

# Preamble is a macro-like thing with no name
preamble = AT + CaselessLiteral("preamble") + bracketed(field_value)

# Macros (aka strings)
开发者ID:susutou,项目名称:DBLPIntegration,代码行数:33,代码来源:btpyparse.py

示例10: Regex

# 需要导入模块: from pyparsing import Regex [as 别名]
# 或者: from pyparsing.Regex import setResultsName [as 别名]
# Version 1
element = Regex("A[cglmrstu]|B[aehikr]?|C[adeflmorsu]?|D[bsy]|"
                "E[rsu]|F[emr]?|G[ade]|H[efgos]?|I[nr]?|Kr?|L[airu]|"
                "M[dgnot]|N[abdeiop]?|Os?|P[abdmortu]?|R[abefghnu]|"
                "S[bcegimnr]?|T[abcehilm]|Uu[bhopqst]|U|V|W|Xe|Yb?|Z[nr]")
elementRef = Group( element + Optional( Word( digits ), default="1" ) )
formula = OneOrMore( elementRef )

fn = lambda elemList : sum( [ atomicWeight[elem]*int(qty) for elem,qty in elemList ] )
test( formula, "H2O", fn )
test( formula, "C6H5OH", fn )
test( formula, "NaCl", fn )
print

# Version 2 - access parsed items by field name
elementRef = Group( element.setResultsName("symbol") + \
                Optional( Word( digits ), default="1" ).setResultsName("qty") )
formula = OneOrMore( elementRef )

fn = lambda elemList : sum( [ atomicWeight[elem.symbol]*int(elem.qty) for elem in elemList ] )
test( formula, "H2O", fn )
test( formula, "C6H5OH", fn )
test( formula, "NaCl", fn )
print

# Version 3 - convert integers during parsing process
integer = Word( digits ).setParseAction(lambda t:int(t[0]))
elementRef = Group( element.setResultsName("symbol") + \
                Optional( integer, default=1 ).setResultsName("qty") )
formula = OneOrMore( elementRef )
开发者ID:AmlaanKar96,项目名称:ArchC,代码行数:32,代码来源:chemicalFormulas.py

示例11: parser

# 需要导入模块: from pyparsing import Regex [as 别名]
# 或者: from pyparsing.Regex import setResultsName [as 别名]
def parser(text):
    var_any = Literal("_")
    p = Regex("[\w:]+").setResultsName("text")
    var_any = Regex("_") #handled by p anyway
    attribute = Literal("@").suppress()
    eq = Literal("=").suppress()
    closure = (Literal("?") | Literal("*") | Literal("+")).setResultsName("closure")

    test = Literal("^").setResultsName("modifier") + p | p + Literal("$").setResultsName("modifier") | p #| var_any
    axis = (Literal("\\\\*") | \
            Literal("\\\\") | \
            Literal("\\") | \
            Literal(".") | \
            Literal("//*") | \
            Literal("//") | \
            Literal("/") | \
            Literal("-->") | \
            Literal("<--") | \
            Literal("->") | \
            Literal("<-") | \
            Literal("==>") | \
            Literal("<==") | \
            Literal("=>") | \
            Literal("<=")).setResultsName("connector")

    g_left_brack = Literal("[").suppress()
    g_right_brack = Literal("]").suppress()

    # working
    """
    abspath = Forward()
    locstep = Forward()
    
    node = test.setResultsName("node")
    attr_test = Group(attribute.suppress() + node.setResultsName("attr") + eq.suppress() + node.setResultsName("attr_val")).setResultsName("attr_test")
    predicate = (Group(Literal("[").suppress() + attr_test + Literal("]").suppress()).setResultsName("predicate") |\
                 Group(Literal("[").suppress() + abspath + Literal("]").suppress()).setResultsName("predicate"))
    locstep << Group(axis.setResultsName("axis") + node + \
              Optional(predicate + Optional(closure).setResultsName("closure"))).setResultsName("locstep")

    abs2 = abspath
    abspath << ( Group(locstep.setResultsName("left_step") + abs2).setResultsName("abspath") | \
                 locstep.setResultsName("right_step") )

    # TODO
    locpath = abspath
    fexpr = locpath.setResultsName("exp")
    """

    # clean
    locpath = Forward()
    steps = Forward()

    fexpr = locpath.setResultsName("exp")

    attr_test = Group(attribute + p.setResultsName("attr") + eq + p.setResultsName("attr_val"))
    pred_opt = (fexpr.setResultsName("predicate") | attr_test.setResultsName("attr_test"))

    # connector order handling is the same as EmuQL, but the root lacks a left, as it refers to context node
    nodetest = Group(test + Optional(g_left_brack + pred_opt + g_right_brack + Optional(closure)))
    steps << ( Group(nodetest("left") + axis + steps("right")) | \
               Group(test + Optional(g_left_brack + pred_opt + g_right_brack + Optional(closure))))

    locpath << Group(axis + steps.setResultsName("right"))
    
    return fexpr.parseString(text)
开发者ID:incognybble,项目名称:toSPARQL,代码行数:68,代码来源:lpath_parser.py

示例12: iter_trees

# 需要导入模块: from pyparsing import Regex [as 别名]
# 或者: from pyparsing.Regex import setResultsName [as 别名]
def iter_trees(infile):
    import pyparsing
    pyparsing.ParserElement.enablePackrat()
    from pyparsing import (
        Word, Literal, QuotedString, CaselessKeyword, CharsNotIn,
        OneOrMore, Group, Optional, Suppress, Regex, Dict, ZeroOrMore,
        alphanums, nums)
    comment = Optional(Suppress("[&") + Regex(r'[^]]+') + Suppress("]"))
    name = Word(alphanums+"_.") | QuotedString("'")
    newick = Regex(r'[^;]+;')
    tree = (CaselessKeyword("tree").suppress() +
            Optional("*").suppress() +
            name.setResultsName("tree_name") +
            comment.setResultsName("tree_comment") +
            Suppress("=") +
            comment.setResultsName("root_comment") +
            newick.setResultsName("newick"))

    def not_begin(s):
        # print('not_begin', s)
        return s.strip().lower() != "begin trees;"
    def not_end(s):
        # print('not_end', s)
        return s.strip().lower() not in ("end;", "endblock;")
    def parse_ttable(f):
        ttable = {}
        # com = Suppress('[') + ZeroOrMore(CharsNotIn(']')) + Suppress(']')
        com = Suppress('[' + ZeroOrMore(CharsNotIn(']') + ']'))
        while True:
            s = next(f).strip()
            if not s:
                continue
            s = com.transformString(s).strip()
            if s.lower() == ";":
                break
            b = False
            if s[-1] in ",;":
                if s[-1] == ';':
                    b = True
                s = s[:-1]
            # print(s)
            k, v = s.split()
            ttable[k] = v
            if b:
                break
        return ttable

    # read lines between "begin trees;" and "end;"
    f = itertools.takewhile(not_end, itertools.dropwhile(not_begin, infile))
    s = next(f).strip().lower()
    if s != "begin trees;":
        print("Expecting 'begin trees;', got %s" % s, file=sys.stderr)
        raise StopIteration
    ttable = {}
    while True:
        try:
            s = next(f).strip()
        except StopIteration:
            break
        if not s:
            continue
        if s.lower() == "translate":
            ttable = parse_ttable(f)
            # print "ttable: %s" % len(ttable)
        elif s.split()[0].lower()=='tree':
            match = tree.parseString(s)
            yield Newick(match, ttable)
开发者ID:rhr,项目名称:ivy,代码行数:69,代码来源:nexus.py


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