• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python pyparsing.Group类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: build_select_grammar

def build_select_grammar():
    select_grammar = Forward()

    select_keyword_token = Keyword("select", caseless=True)
    from_keyword_token = Keyword("from", caseless=True)
    limit_keyword_token = Keyword("limit", caseless=True)
    order_by_keyword_token = Keyword("order by", caseless=True)
    where_keyword_token = Keyword("where", caseless=True)
    operators_tokens = oneOf("= != < > >= <=")

    column_name_tokens = Group(delimitedList(identifier_token, ","))
    order_by_token = order_by_keyword_token + column_name_tokens.setResultsName("order_by_cols")\
                     + Optional(
                        (Keyword("asc", caseless=True).setResultsName("order_by_type") |
                         Keyword("desc", caseless=True).setResultsName("order_by_type"))
                    )

    limit_token = limit_keyword_token + Optional(Word(nums).setResultsName("offset") + Literal(",")) \
                  + Word(nums).setResultsName("rows_limit")

    where_expression = where_keyword_token + identifier_token.setResultsName("operand_left") \
                       + operators_tokens.setResultsName("operator") + Word(alphanums).setResultsName("operand_right")

    select_grammar << select_keyword_token + ('*' | column_name_tokens).setResultsName("columns")\
                     + from_keyword_token + table_name_token.setResultsName("table")\
                     + Optional(where_expression).setResultsName("where")\
                     + Optional(order_by_token).setResultsName("order")\
                     + Optional(limit_token).setResultsName("limit")

    return select_grammar
开发者ID:GedRap,项目名称:sql2py,代码行数:30,代码来源:sql_parser.py


示例2: define_identifier

 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,代码行数:27,代码来源:parsers.py


示例3: parse_connection_str

def parse_connection_str(connstr):
    ## Grammar for connection syntax
    digits="0123456789"
    othervalid="[email protected]"
    identifier= Word(alphas+digits+othervalid)
    nodename=identifier.setResultsName('nodename')

    outputnames = delimitedList( identifier ).setResultsName('outputnames')
    inputnames  = delimitedList( identifier ).setResultsName('inputnames')

    # middle nodes have both inputs and outputs
    middlenode= Group( nodename + Suppress('(') + inputnames
                       + Optional( "|" + outputnames)
                       + Suppress(")") ).setResultsName('middlenode')
    # first node has only outputs
    headnode = (nodename + Suppress("(") + outputnames
                + Suppress(")")).setResultsName('headnode')
    # last node has only inputs
    tailnode = (nodename + Suppress("(") + inputnames
                + Suppress(")")).setResultsName('tailnode')

    # connect head -> [middle ->] tail
    connect= Group( headnode
                    + Group(ZeroOrMore(Suppress("->") \
                        + middlenode + FollowedBy("->") )).setResultsName('middlenodes')
                    + Suppress("->")+tailnode).setResultsName('nodes')

    connectlist = Group( connect + ZeroOrMore( Suppress(";")\
                        + connect )).setResultsName('connects')

    parsed=connectlist.parseString(connstr)
    check_numconnections(parsed)
    return parsed
开发者ID:ihrke,项目名称:nipype_connect_str,代码行数:33,代码来源:nipype_connect_str.py


示例4: _read_solution

def _read_solution(scenario,log,task_to_id,id_to_resource) :
	
	S = scenario

	# parse output 
	from pyparsing import Keyword,Literal,Word,alphas,nums,printables,OneOrMore,ZeroOrMore,dblQuotedString,Group
	INT = Word( nums )
	int_row = Group( INT + Literal(",").suppress() + \
                         INT + Literal(",").suppress() + \
			 INT + Literal(";").suppress() )
	plan = Group( Group( ZeroOrMore(int_row) ) )

	start_str, end_str = '##START_SOLUTION##', '##END_SOLUTION##'
	start_i, end_i = log.index(start_str)+len(start_str), log.index(end_str)
	opl_plan = plan.parseString(log[start_i:end_i])
	int_plan = opl_plan[0][0]

	# get starts and resource assignments
	starts = dict()
	assign = dict()
	for row in int_plan :
		task_id = int(row[0])
		starts[task_id] = int(row[2])
		if task_id not in assign :
			assign[task_id] = list()
		assign[task_id].append(int(row[1]))

	# add to scenario
	for T in S.tasks() :
		T.start = starts[task_to_id[T]] #second column is start
		if T.resources is None :
			T.resources = list()
		T.resources += [ id_to_resource[j] for j in assign[task_to_id[T]] ]
开发者ID:Zulko,项目名称:pyschedule,代码行数:33,代码来源:cpoptimizer.py


示例5: ifParser

def ifParser():
	
	comma = Literal(",").suppress()
	hash = Literal("#").suppress()
	equal = Literal("=").suppress()

	# Rules and labels
	rulename = Word (alphanums + "_")
	rulecategory = oneOf("Protocol_Rules Invariant_Rules Decomposition_Rules Intruder_Rules Init Goal")
	label = hash + Literal("lb") + equal + rulename + comma + Literal("type") + equal + rulecategory
	labeledrule = Group(label) + Group(ruleParser())

	def labeledruleAction(s,l,t):
		if t[0][3] == "Protocol_Rules":
			print "-----------------"
			print "- Detected rule -"
			print "-----------------"

			print t[0]
			print t[1]
			print

	labeledrule.setParseAction(labeledruleAction)

	# A complete file
	parser = OneOrMore(labeledrule)
	parser.ignore("##" + restOfLine)

	return parser
开发者ID:cascremers,项目名称:scyther,代码行数:29,代码来源:parser.py


示例6: _define_context_component

 def _define_context_component (self, cluster, base_feature_set):
     placeholder = Literal(SOURCE_PLACEHOLDER)
     placeholder.setParseAction(self._handle_placeholder)
     context_component = Group(ZeroOrMore(cluster ^ base_feature_set) + \
         placeholder + ZeroOrMore(cluster ^ base_feature_set)).setResultsName('context_component')
     context_component.setParseAction(self._handle_context_component)
     return context_component
开发者ID:ajenhl,项目名称:zounds,代码行数:7,代码来源:ruleset_parser.py


示例7: parse_showhdinfo

def parse_showhdinfo(stdout, stderr):
    """
    """
    uuid_prefix = Suppress(Word('UUID:'))
    id_uuid = Word(alphanums + '-').setResultsName('uuid')
    accessible_prefix = Suppress(Word('Accessible:'))
    id_accessible = Word(alphas).setResultsName('accessible')
    logical_size_prefix = Suppress(Word('Logical size:'))
    id_logical_size = Word(alphanums + ' ').setResultsName('logical_size')
    current_size_prefix = Suppress(Word('Current size on disk:'))
    id_current_size = Word(alphanums + ' ').setResultsName('current_size')
    type_prefix = Suppress(Word('Type:'))
    id_type = Word(alphas + ' ()').setResultsName('type')
    prefix_storage_format = Suppress(Word('Storage format:'))
    id_storage_format = Word(alphas).setResultsName('storage_format')
    prefix_format_variant = Suppress(Word('Format variant:'))
    id_format_variant = Word(alphanums + ' ').setResultsName('format_variant')
    prefix_location = Suppress(Word('Location:'))
    id_location = Word(alphanums + ' /.').setResultsName('location')

    hd_info = Group(uuid_prefix + id_uuid + EOL + accessible_prefix +
            id_accessible + EOL + logical_size_prefix + id_logical_size + EOL +
            current_size_prefix + id_current_size + EOL + type_prefix +
            id_type + EOL + prefix_storage_format + id_storage_format + EOL +
            prefix_format_variant + id_format_variant + EOL + prefix_location +
            id_location + EOL)
    out = hd_info.parseString(stdout)[0]

    return {'uuid': out.uuid, 'accessible': out.accessible,
            'logical_size': out.logical_size, 'current_size': out.current_size,
            'type': out.type, 'storage_format': out.storage_format,
            'format_variant': out.storage_variant, 'location': out.location}
开发者ID:splaice,项目名称:Virtbox,代码行数:32,代码来源:parsers.py


示例8: parseEqun

def parseEqun(equation):
    cForm = Word(ascii_uppercase, ascii_uppercase + ascii_lowercase + digits)
    equnExpr = Group(ZeroOrMore(cForm + Suppress('+')) + cForm)
    lhs = equnExpr.setResultsName('lhs')
    rhs = equnExpr.setResultsName('rhs')
    chemicalEqun = lhs + "->" + rhs
    parsedEqun = chemicalEqun.parseString(equation)

    LHS = parsedEqun['lhs'].asList()
    RHS = parsedEqun['rhs'].asList()

    lhsDict = {}
    rhsDict = {}

    element = Word(ascii_uppercase, ascii_lowercase)
    integer = Word(digits).setParseAction(lambda x: int(x[0]))
    elementRef = Group(element + Optional(integer, default=1))
    chemicalFormula = OneOrMore(elementRef)

    for chemical in LHS:
        lhsDict[chemical] = Counter()
        for element, count in chemicalFormula.parseString(chemical):
            lhsDict[chemical][element] += count

    for chemical in RHS:
        rhsDict[chemical] = Counter()
        for element, count in chemicalFormula.parseString(chemical):
            rhsDict[chemical][element] += count

    return lhsDict, rhsDict
开发者ID:alanhdu,项目名称:python-equation-balancing,代码行数:30,代码来源:improvedParseEqun.py


示例9: parseReactions

def parseReactions(reaction):
    
    grammar = Group(Word(alphanums) + Suppress('()') + Optional(Suppress('+') + Word(alphanums) 
    + Suppress("()"))) + Suppress("->") + Group(Word(alphanums) + Suppress("()") + Optional(Suppress('+') 
    + Word(alphanums) + Suppress("()"))) + Suppress(Word(alphanums + "()")) 
   
    return grammar.parseString(reaction).asList()
开发者ID:jmuhlich,项目名称:bionetgen,代码行数:7,代码来源:sbml2bngl.py


示例10: list_dict

def list_dict(word=word_free):
    """
    Return the pyparsing lexical element, that parses a string either as a list
    or as a dictionary.

    Parameters
    ----------
    word : lexical element
        A custom lexical element for word.

    Returns
    -------
    ld : lexical element
        The returned lexical element parses a string in the form
        ``..., ..., ...`` or ``key1:..., key2=..., key3: ...``
        where ``...`` is a ``list_item`` from :func:`get_standard_type_defs()`
        and interprets it as a list or a dictionary.
    """
    defs = get_standard_type_defs(word)
    i = defs['list_item']
    arg = i.copy()
    arg.setParseAction(lambda t: (t[0],))
    narg = word_strict + (colon | equal_sign) + i
    narg.setParseAction(lambda t: (t[0], t[1]))

    ld = Group(list_of(narg | arg))
    ld.setParseAction(lambda t: ([x[0] for x in t[0] if len(x) == 1],
                                 dict([x for x in t[0] if len(x) > 1]))
                      )
    return ld
开发者ID:clazaro,项目名称:sfepy,代码行数:30,代码来源:parse_conf.py


示例11: getLogLineBNF

def getLogLineBNF():
    global logLineBNF
    
    if logLineBNF is None:
        integer = Word( nums )
        ipAddress = delimitedList( integer, ".", combine=True )
        
        timeZoneOffset = Word("+-",nums)
        month = Word(string.uppercase, string.lowercase, exact=3)
        serverDateTime = Group( Suppress("[") + 
                                Combine( integer + "/" + month + "/" + integer +
                                        ":" + integer + ":" + integer + ":" + integer ) +
                                timeZoneOffset + 
                                Suppress("]") )
                         
        logLineBNF = ( ipAddress.setResultsName("ipAddr") + 
                       Suppress("-") +
                       ("-" | Word( alphas+nums+"@._" )).setResultsName("auth") +
                       serverDateTime.setResultsName("timestamp") + 
                       dblQuotedString.setResultsName("cmd").setParseAction(getCmdFields) +
                       (integer | "-").setResultsName("statusCode") + 
                       (integer | "-").setResultsName("numBytesSent")  + 
                       dblQuotedString.setResultsName("referrer").setParseAction(removeQuotes) +
                       dblQuotedString.setResultsName("clientSfw").setParseAction(removeQuotes) )
    return logLineBNF
开发者ID:AmlaanKar96,项目名称:ArchC,代码行数:25,代码来源:httpServerLogParser.py


示例12: parse

    def parse(self, filename):
        model = None
        alpha = None
        lnl = None
        freq = None
        rates = None

        with open(filename) as fl:
            s = fl.read()

        try:
            model, lnl, alpha = self.common.parseString(s).asList()

        except ParseException as err:
            logger.error(err)

        if model == 'JC69':
            freq = [0.25, 0.25, 0.25, 0.25]
            rates = [1.0, 1.0, 1.0, 1.0, 1.0, 1.0]

        elif model == 'K80':
            freq = [0.25, 0.25, 0.25, 0.25]
            try:
                tstv = self.tstv.parseString(s).asList()
            except ParseException as err:
                logger.error(err)
            
            rates = [1.0, tstv[0], 1.0, 1.0, tstv[0], 1.0]

        elif model == 'F81':
            try:
                freq = self.freq.parseString(s).asList()
            except ParseException as err:
                logger.error(err)
            rates = [1.0, 1.0, 1.0, 1.0, 1.0, 1.0]

        elif model == 'F84' or model == 'HKY85' or model == 'TN93':
            parser = Group(self.tstv) + Group(self.freq)
            try:
                tstv, freq = parser.parseString(s).asList()
            except ParseException as err:
                logger.error(err)
            if model == 'TN93':
                rates = [1.0, tstv[0], 1.0, 1.0, tstv[1], 1.0]
            else:
                rates = [1.0, tstv[0], 1.0, 1.0, tstv[0], 1.0]

        elif model == 'GTR':
            parser = Group(self.freq) + Group(self.rates)
            try:
                freq, rates = parser.parseString(s).asList()
            except ParseException as err:
                logger.error(err)

        return model, alpha, lnl, freq, rates
开发者ID:kgori,项目名称:treeCl,代码行数:55,代码来源:parsers.py


示例13: split_chemical_formula

def split_chemical_formula(formula):
    def is_number(s):
        try:
            float(s)
            return True
        except ValueError:
            return False

    def replace_things(stringg, listt, replacement):
        for x in listt:
            stringg = stringg.replace(x, replacement)
        return stringg

    bad_chars = ["(", ")", "-", "."]
    formula = replace_things(formula, bad_chars, "|")

    if is_number(formula):
        return [["", 0]]

    if len(formula) == 0:
        return [["", 0]]

        # define some strings to use later, when describing valid lists
        # of characters for chemical symbols and numbers
    caps = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
    lowers = caps.lower()
    digits = "0123456789"

    # Version 1

    # Version 2 - Auto-convert integers, and add results names
    def convertIntegers(tokens):
        return int(tokens[0])

    element = Word(caps, lowers)
    integer = Word(digits).setParseAction(convertIntegers)
    elementRef = Group(element("symbol") + Optional(integer, default=1)("qty"))
    # pre-1.4.7, use this:
    # elementRef = Group( element.setResultsName("symbol") + Optional( integer, default=1 ).setResultsName("qty") )
    chemicalFormula = OneOrMore(elementRef)

    # Version 3 - Compute partial molecular weight per element, simplifying
    # summing
    # No need to redefine grammar, just define parse action function, and
    # attach to elementRef
    def computeElementWeight(tokens):
        element = tokens[0]
        element["weight"] = atomicWeight[element.symbol] * element.qty

    elementRef.setParseAction(computeElementWeight)

    formulaData = chemicalFormula.parseString(formula)
    mw = sum([element.weight for element in formulaData])
    return formulaData
开发者ID:MartinsMednis,项目名称:ModeRator,代码行数:54,代码来源:chemicalFormulas.py


示例14: parse

def parse(str):
    tokens = ''
    # define SQL tokens
    selectStmt = Forward()
    selectToken = Keyword("select", caseless=True)
    fromToken   = Keyword("from", caseless=True)
    
    ident          = Word( alphas, alphanums + "_$" ).setName("identifier")
    columnName     = Upcase( delimitedList( ident, ".", combine=True ) )
    columnNameList = Group( delimitedList( columnName ) )
    tableName      = Upcase( delimitedList( ident, ".", combine=True ) )
    tableNameList  = Group( delimitedList( tableName ) )
    
    whereExpression = Forward()
    and_ = Keyword("and", caseless=True)
    or_ = Keyword("or", caseless=True)
    in_ = Keyword("in", caseless=True)
    
    E = CaselessLiteral("E")
    binop = oneOf("= != < > >= <= eq ne lt le gt ge", caseless=True)
    arithSign = Word("+-",exact=1)
    realNum = Combine( Optional(arithSign) + ( Word( nums ) + "." + Optional( Word(nums) )  |
                                                             ( "." + Word(nums) ) ) + 
                Optional( E + Optional(arithSign) + Word(nums) ) )
    intNum = Combine( Optional(arithSign) + Word( nums ) + 
                Optional( E + Optional("+") + Word(nums) ) )
    
    columnRval = realNum | intNum | quotedString | columnName # need to add support for alg expressions
    whereCondition = Group(
        ( columnName + binop + columnRval ) |
        ( columnName + in_ + "(" + delimitedList( columnRval ) + ")" ) |
        ( columnName + in_ + "(" + selectStmt + ")" ) |
        ( "(" + whereExpression + ")" )
        )
    whereExpression << whereCondition + ZeroOrMore( ( and_ | or_ ) + whereExpression ) 
    
    # define the grammar
    selectStmt      << ( selectToken + 
                       ( '*' | columnNameList ).setResultsName( "columns" ) + 
                       fromToken + 
                       tableNameList.setResultsName( "tables" ) + 
                       Optional( Group( CaselessLiteral("where") + whereExpression ), "" ).setResultsName("where") )
    
    simpleSQL = selectStmt
    
    # define Oracle comment format, and ignore them
    oracleSqlComment = "--" + restOfLine
    simpleSQL.ignore( oracleSqlComment )
    
    try:
        tokens = simpleSQL.parseString( str )
    except ParseException, err:
        print " "*err.loc + "^\n" + err.msg
        print err
开发者ID:umidev,项目名称:mapnik-utils,代码行数:54,代码来源:sqlparse.py


示例15: get_parser

    def get_parser():
        """Return a lyrics file parser. @see grammar.md for the whole grammar."""
        if Lyrics._parser is None:
            # Parser not yet defined. Defining it.
            comment_line = COMMENT_SIGN + WORDS + EOL
            comments = Group(ZeroOrMore(comment_line))
            section = Section.get_parser()
            sections = section + ZeroOrMore(EOL + section)
            Lyrics._parser = comments.setResultsName("comments") + sections.setResultsName("sections")

        return Lyrics._parser
开发者ID:yapper-git,项目名称:liblyrics,代码行数:11,代码来源:lyrics.py


示例16: _getPattern

    def _getPattern(self):
        arith_expr = Forward()
        comp_expr = Forward()
        logic_expr = Forward()
        LPAR, RPAR, SEMI = map(Suppress, "();")
        identifier = Word(alphas+"_", alphanums+"_")
        multop = oneOf('* /')
        plusop = oneOf('+ -')
        expop = Literal( "^" )
        compop = oneOf('> < >= <= != ==')
        andop = Literal("AND")
        orop = Literal("OR")
        current_value = Literal( "." )
        assign = Literal( "=" )
        # notop = Literal('NOT')
        function = oneOf(' '.join(self.FUNCTIONS))
        function_call = Group(function.setResultsName('fn') + LPAR + Optional(delimitedList(arith_expr)) + RPAR)
        aggregate_column = QuotedString(quoteChar='{', endQuoteChar='}')
        single_column = QuotedString(quoteChar='[', endQuoteChar=']')
        integer = Regex(r"-?\d+")
        real = Regex(r"-?\d+\.\d*")

        # quotedString enables strings without quotes to pass

        operand = \
            function_call.setParseAction(self.__evalFunction) | \
            aggregate_column.setParseAction(self.__evalAggregateColumn) | \
            single_column.setParseAction(self.__evalSingleColumn) | \
            ((real | integer).setParseAction(self.__evalConstant)) | \
            quotedString.setParseAction(self.__evalString).addParseAction(removeQuotes) | \
            current_value.setParseAction(self.__evalCurrentValue) | \
            identifier.setParseAction(self.__evalString)

        arith_expr << operatorPrecedence(operand,
            [
             (expop, 2, opAssoc.LEFT, self.__expOp),
             (multop, 2, opAssoc.LEFT, self.__multOp),
             (plusop, 2, opAssoc.LEFT, self.__addOp),
            ])

        # comp_expr = Group(arith_expr + compop + arith_expr)
        comp_expr << operatorPrecedence(arith_expr,
            [
                (compop, 2, opAssoc.LEFT, self.__evalComparisonOp),
            ])

        logic_expr << operatorPrecedence(comp_expr,
            [
                (andop, 2, opAssoc.LEFT, self.__evalLogicOp),
                (orop, 2, opAssoc.LEFT, self.__evalLogicOp)
            ])

        pattern = logic_expr + StringEnd()
        return pattern
开发者ID:ArnoldOchieng,项目名称:echo-sense,代码行数:54,代码来源:expressionParser.py


示例17: read_tgf

def read_tgf(path):
    """Generates an alias.ArgumentationFramework from a Trivial Graph Format (.tgf) file.

    Trivial Graph Format (TGF) is a simple text-based file format for describing graphs. \
    It consists of a list of node definitions, which map node IDs to labels, followed by \
    a list of edges, which specify node pairs and an optional edge label. \
    Node IDs can be arbitrary identifiers, whereas labels for both nodes and edges are plain strings.

    Parameters
    ----------
    path : file or string
        File, directory or filename to be read.

    Returns
    -------
    framework : alias ArgumentationFramework

    Examples
    --------

    References
    ----------
    http://en.wikipedia.org/wiki/Trivial_Graph_Format 
    """

    try:
        from pyparsing import Word, alphanums, ZeroOrMore, White, Suppress, Group, ParseException, Optional
    except ImportError:
        raise ImportError("read_tgf requires pyparsing")

    if not isinstance(path, str):
        return

    # Define tgf grammar
    s = White(" ")
    tag = Word(alphanums)
    arg = Word(alphanums)
    att = Group(arg + Suppress(s) + arg + Optional(Suppress(s) + tag))
    nl = Suppress(White("\n"))

    graph = Group(ZeroOrMore(arg + nl)) + Suppress("#") + nl + Group(ZeroOrMore(att + nl) + ZeroOrMore(att))
    
    
    f = open(path, 'r')
    f = f.read()

    head, tail = ntpath.split(path)
    framework = al.ArgumentationFramework(tail)

    try:
        parsed = graph.parseString(f)
    except ParseException, e:
        raise al.ParsingException(e)
开发者ID:alias-org,项目名称:alias,代码行数:53,代码来源:tgf.py


示例18: parseReactions

def parseReactions(reaction):
    components = (Word(alphanums + "_") + Optional(Group('~' + Word(alphanums+"_")))
    + Optional(Group('!' + Word(alphanums+'+?'))))
    molecule = (Word(alphanums + "_")
    + Optional(Suppress('(') + Group(components) + ZeroOrMore(Suppress(',') + Group(components))    
    +Suppress(')')))
    
    species = Group(molecule) + ZeroOrMore(Suppress('.') + Group(molecule))

    result = species.parseString(reaction).asList()
    
    return result
开发者ID:jjtapia,项目名称:SBMLparser,代码行数:12,代码来源:smallStructures.py


示例19: build_message

def build_message():
    global message
    message = Group(Optional(Suppress(Literal(':')) + prefix + space)) + \
              Group(command) + \
              Group(Optional(params))
    if config.getboolean('parser', 'trailing_spaces'):
        message += ZeroOrMore(space)
    if config.getboolean('parser', 'soft_eol'):
        message += cr ^ lf ^ crlf
    else:
        message += crlf
    message.leaveWhitespace()
开发者ID:Slach,项目名称:python-ircd,代码行数:12,代码来源:abnf.py


示例20: SearchSyntax

def SearchSyntax():
    printables_without_colon = ''.join(letter for letter in printables if letter != ':')
    Colon = Literal(":").suppress()
    
    Filter = Group(Word(printables_without_colon) + Colon + Word(printables_without_colon) + Optional(Colon + (QuotedString('"', "\\") | Word(printables)))).setResultsName('filters')
    Filter.modalResults = False
    
    TextTerm = (QuotedString('"', "\\", unquoteResults=False) | Word(printables)).setResultsName('text_terms')
    TextTerm.modalResults = False

    Term = Filter | TextTerm
    Query = ZeroOrMore(Term)
    return Query
开发者ID:apendleton,项目名称:sparerib,代码行数:13,代码来源:query_parse.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python pyparsing.Keyword类代码示例发布时间:2022-05-27
下一篇:
Python pyparsing.Forward类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap