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


Python Group.setResultsName方法代码示例

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


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

示例1: getLogLineBNF

# 需要导入模块: from pyparsing import Group [as 别名]
# 或者: from pyparsing.Group import setResultsName [as 别名]
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,代码行数:27,代码来源:httpServerLogParser.py

示例2: define_identifier

# 需要导入模块: from pyparsing import Group [as 别名]
# 或者: from pyparsing.Group 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

示例3: parseEqun

# 需要导入模块: from pyparsing import Group [as 别名]
# 或者: from pyparsing.Group import setResultsName [as 别名]
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,代码行数:32,代码来源:improvedParseEqun.py

示例4: build_select_grammar

# 需要导入模块: from pyparsing import Group [as 别名]
# 或者: from pyparsing.Group import setResultsName [as 别名]
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,代码行数:32,代码来源:sql_parser.py

示例5: _create_filter_parser

# 需要导入模块: from pyparsing import Group [as 别名]
# 或者: from pyparsing.Group import setResultsName [as 别名]
def _create_filter_parser():
    and_kw = Keyword('AND')
    or_kw = Keyword('OR')
    variable = Literal('?') + Word(alphanums + '_').leaveWhitespace()
    uri_term = NotAny(Literal('"')) + Word(printables, excludeChars='>*')
    uri_part = Keyword('*') ^ uri_term ^ variable
    literal_term = QuotedString(quoteChar='"', escChar='\\')
    triple = Group(Literal('<').suppress() + uri_part.setResultsName('subj')
                   + uri_part.setResultsName('pred')
                   + (Group(uri_part).setResultsName('obj')
                      ^ Group(literal_term).setResultsName('objlit'))
                   + Literal('>').suppress())
    expr = Forward()
    atom = (triple.setResultsName('triple')
            | Literal('(').suppress() + expr + Literal(')').suppress())
    and_group = Group(atom + ZeroOrMore(and_kw.suppress() + atom))
    or_group = Group(atom + ZeroOrMore(or_kw.suppress() + atom))
    expr << (and_group.setResultsName('and') ^ or_group.setResultsName('or'))
    return expr
开发者ID:jfisteus,项目名称:ztreamy,代码行数:21,代码来源:filters.py

示例6: get_parser

# 需要导入模块: from pyparsing import Group [as 别名]
# 或者: from pyparsing.Group import setResultsName [as 别名]
    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,代码行数:13,代码来源:lyrics.py

示例7: parse

# 需要导入模块: from pyparsing import Group [as 别名]
# 或者: from pyparsing.Group import setResultsName [as 别名]
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,代码行数:56,代码来源:sqlparse.py

示例8: parser

# 需要导入模块: from pyparsing import Group [as 别名]
# 或者: from pyparsing.Group import setResultsName [as 别名]
def parser(text):
    """
    str := \w+
    str := '\w+'
    exp := Var=str
    exp := exp & exp
    exp := exp ^ exp
    """
    
    # grammar
    #g_string = "'"+Word(alphas)+"'" | Word(alphas)
    g_quote = Literal("'").suppress()
    g_text = Regex("[\w\s\:\#\.]+").setResultsName("text")
    g_string = Optional(g_quote) + g_text + Optional(g_quote)
    g_equ =  Literal("!=").setResultsName("connector") | Literal("=").setResultsName("connector")
    g_amp = Literal("&").setResultsName("connector")
    g_hat = Literal("^").setResultsName("connector")
    g_or = Literal("|").suppress()
    g_seq = Literal("->").setResultsName("connector")
    g_hash = Literal("#").setResultsName("hash")

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

    
    g_vals = Forward()
    g_vals << g_string + ZeroOrMore(Group(g_or + g_vals).setResultsName("or_group"))

    # working
    """
    exp_basic = Group(Optional(g_hash) + g_string).setResultsName("left") + g_equ + Group(g_vals).setResultsName("right")
    exp = Group(exp_basic)
    exp = exp.setResultsName("left") + g_amp + exp.setResultsName("right") | \
            g_left_brack + exp.setResultsName("left") + g_hat + exp.setResultsName("right") + g_right_brack | \
            g_left_brack + exp.setResultsName("left") + g_seq + exp.setResultsName("right") + g_right_brack | \
            exp_basic
    """

    # recursion
    simpleq = Forward()
    complexq = Forward()

    exp = (simpleq | complexq).setResultsName("exp")
    exp_basic = Group(Group(Optional(g_hash) + g_string).setResultsName("left") + g_equ + Group(g_vals).setResultsName("right"))
    simpleq << (Group(exp_basic.setResultsName("left") + g_amp + simpleq.setResultsName("right")) | exp_basic)
    complexq << ( Group(g_left_brack + exp.setResultsName("left") + g_hat + exp.setResultsName("right") + g_right_brack) | \
                  Group(g_left_brack + exp.setResultsName("left") + g_seq + exp.setResultsName("right") + g_right_brack) )
    
    
    
    return exp.parseString(text)
开发者ID:incognybble,项目名称:toSPARQL,代码行数:53,代码来源:emu_parser.py

示例9: build_insert_grammar

# 需要导入模块: from pyparsing import Group [as 别名]
# 或者: from pyparsing.Group import setResultsName [as 别名]
def build_insert_grammar():
    insert_grammar = Forward()

    insert_into_keyword_token = Keyword("insert into", caseless=True)
    values_token = Keyword("values", caseless=True)

    columns = Optional(Group(delimitedList(identifier_token, ",")))
    values_list_token = Group(delimitedList(Word(alphanums + " "), ","))

    insert_grammar << insert_into_keyword_token + table_name_token.setResultsName("table_name") \
                      + Literal("(") + columns.setResultsName("columns") + Literal(")") + \
                      values_token + Literal("(") + values_list_token.setResultsName("values_list") + Literal(")")

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

示例10: fromString

# 需要导入模块: from pyparsing import Group [as 别名]
# 或者: from pyparsing.Group import setResultsName [as 别名]
	def fromString(inputText, verbose=False):
		if verbose: print 'Verbose:', verbose
		text = nestedExpr("/*", "*/").suppress().transformString(inputText) 

		semicolon = Suppress(Word(";"))
		quote     = Suppress(Word("\""))
		op        = Suppress(Word("{"))
		cl        = Suppress(Word("}"))
		opp       = Suppress(Word("("))
		clp       = Suppress(Word(")"))
		
		identifier = Word( alphas+"_", alphanums+"_" )
		commIdentifier = Group(identifier.setResultsName('identifier') + Optional(opp + (CaselessLiteral("ice")|CaselessLiteral("ros")).setResultsName("type") + clp))

		# Imports
		idslImport  = Suppress(CaselessLiteral("import")) + quote +  CharsNotIn("\";").setResultsName('path') + quote + semicolon
		idslImports = ZeroOrMore(idslImport)
		# Communications
		implementsList = Group(CaselessLiteral('implements')    + identifier + ZeroOrMore(Suppress(Word(',')) + identifier) + semicolon)
		requiresList   = Group(CaselessLiteral('requires')      + identifier + ZeroOrMore(Suppress(Word(',')) + identifier) + semicolon)
		subscribesList = Group(CaselessLiteral('subscribesTo')  + commIdentifier + ZeroOrMore(Suppress(Word(',')) + commIdentifier) + semicolon)
		publishesList  = Group(CaselessLiteral('publishes')     + identifier + ZeroOrMore(Suppress(Word(',')) + identifier) + semicolon)
		communicationList = implementsList | requiresList | subscribesList | publishesList
		communications = Group( Suppress(CaselessLiteral("communications")) + op + ZeroOrMore(communicationList) + cl + semicolon)
		
		# Language
		language = Suppress(CaselessLiteral("language")) + (CaselessLiteral("cpp")|CaselessLiteral("python")) + semicolon
		# GUI
		gui = Group(Optional(Suppress(CaselessLiteral("gui")) + CaselessLiteral("Qt") + opp + identifier + clp + semicolon ))
		# additional options
		options = Group(Optional(Suppress(CaselessLiteral("options")) + identifier + ZeroOrMore(Suppress(Word(',')) + identifier) + semicolon))
		
		componentContents = communications.setResultsName('communications') & language.setResultsName('language') & gui.setResultsName('gui') & options.setResultsName('options')
		component = Suppress(CaselessLiteral("component")) + identifier.setResultsName("name") + op + componentContents.setResultsName("properties") + cl + semicolon

		CDSL = idslImports.setResultsName("imports") + component.setResultsName("component")
		CDSL.ignore( cppStyleComment )
		tree = CDSL.parseString(text)
		return CDSLParsing.component(tree)
开发者ID:soura97,项目名称:robocomp,代码行数:41,代码来源:parseCDSL.py

示例11: create_where

# 需要导入模块: from pyparsing import Group [as 别名]
# 或者: from pyparsing.Group import setResultsName [as 别名]
def create_where():
    """ Create the grammar for a 'where' clause """
    where_exp = Group(constraint +
                      ZeroOrMore(Suppress(and_) + constraint))
    return where_ + where_exp.setResultsName('where')
开发者ID:cce,项目名称:dql,代码行数:7,代码来源:query.py

示例12: Group

# 需要导入模块: from pyparsing import Group [as 别名]
# 或者: from pyparsing.Group import setResultsName [as 别名]
channels = Group(OneOrMore(channel))
rotationOrder = Word("XYZ", exact=3)
begin = Suppress(Keyword("begin"))
end = Suppress(Keyword("end"))
bonename = Combine(~end + Word(alphanums+"_-")).setWhitespaceChars(' ')

version = Keyword(":version") + Literal("1.10")
skeletonName = Keyword(":name") + bonename.setResultsName('name')
unitDefinition = Group(Word(alphas) + (floatValue | intValue | Word(alphas)))
unitSection = Keyword(":units") + \
        Dict(ZeroOrMore(unitDefinition)).setResultsName('units')
documentationSection = Keyword(':documentation') + \
        SkipTo(":").setResultsName('documentation')
rootSection = Group(Keyword(":root") &
        (Keyword("order") +
        channels.setResultsName('channels')) &
        (Keyword("position") +
        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") +
开发者ID:JonFountain,项目名称:imusim,代码行数:33,代码来源:asf_amc.py

示例13: Word

# 需要导入模块: from pyparsing import Group [as 别名]
# 或者: from pyparsing.Group import setResultsName [as 别名]
| min   |   7  |  43  |   7  |  15  |  82  |  98  |   1  |  37  |
| max   |  11  |  52  |  10  |  17  |  85  | 112  |   4  |  39  |
| ave   |   9  |  47  |   8  |  16  |  84  | 106  |   3  |  38  |
| sdev  |   1  |   3  |   1  |   1  |   1  |   3  |   1  |   1  |
+-------+------+------+------+------+------+------+------+------+
"""

# define grammar for datatable
underline = Word("-=")
number = Word(nums).setParseAction(lambda s, l, t: (l, [int(t[0])]))
vert = Literal("|").suppress()

rowDelim = ("+" + ZeroOrMore(underline + "+")).suppress()
columnHeader = Group(vert + vert + delimitedList(Word(alphas + nums), "|") + vert)

heading = rowDelim + columnHeader.setResultsName("columns") + rowDelim
rowData = Group(vert + Word(alphas) + vert + delimitedList(number, "|") + vert)
trailing = rowDelim

datatable = heading + Dict(ZeroOrMore(rowData)) + trailing

# now parse data and print results
data = datatable.parseString(testData)
print data
print data.asXML()
pprint.pprint(data.asList())
print "data keys=", data.keys()
print "data['min']=", data["min"]
print "sum(data['min']) =", sum(data["min"])
print "data.max =", data.max
print "sum(data.max) =", sum(data.max)
开发者ID:BackupTheBerlios,项目名称:shekina-svn,代码行数:33,代码来源:dictExample2.py

示例14: Combine

# 需要导入模块: from pyparsing import Group [as 别名]
# 或者: from pyparsing.Group import setResultsName [as 别名]
    + Combine(ident).setResultsName('name')
    + as_kw
    + select_stmt
)

#
# Define asql index grammar.
#
index_source = delimitedList(source_ident, '.', combine=True)
index_kw = Keyword('index', caseless=True)
_index_stmt = Forward()
_index_stmt << (
    Optional(create_kw)
    + index_kw
    + index_source.setResultsName('source')
    + '(' + column_name_list.setResultsName('columns') + ')')

# Examples:
# index = index_stmt.parseString('INDEX partition1 (col1, col2, col3);')
# print(index.source)
# 'partition1'
# print(index.columns)
# ['col1', 'col2', 'col3']

# define Oracle comment format, and ignore them
oracle_sql_comment = '--' + restOfLine
_view_stmt.ignore(oracle_sql_comment)
_index_stmt.ignore(oracle_sql_comment)


def substitute_vids(library, statement):
开发者ID:CivicKnowledge,项目名称:ambry,代码行数:33,代码来源:asql_parser.py

示例15: Forward

# 需要导入模块: from pyparsing import Group [as 别名]
# 或者: from pyparsing.Group import setResultsName [as 别名]
havingExpression = Forward()

whereColumn = (( caseStart + SkipTo(caseEnd, include=True)) |
               ( Optional("(") + colIdent + Optional("(") + ZeroOrMore(arithop + Optional("(") + colIdent + Optional(")")) + Optional(")") )
              )

columnRval = realNum | intNum | quotedString | whereColumn # need to add support for alg expressions

condition = Group(
  ( whereColumn + binop + columnRval ) |
  ( whereColumn + Optional(not_) + in_ + "(" + delimitedList( columnRval ) + ")" ) |
  ( whereColumn + is_ + Optional(not_) + null ) |
  ( whereColumn + between_ + columnRval + and_ + columnRval) |
  ( "(" + whereExpression + ")" )
  )
whereExpression << condition.setResultsName("where", listAllMatches=True) + ZeroOrMore( ( and_ | or_ ) + whereExpression )
havingExpression << condition.setResultsName("having", listAllMatches=True) + ZeroOrMore( ( and_ | or_ ) + havingExpression )

groupByList = delimitedList( columnName.setResultsName("groupby", listAllMatches=True) )

# define the grammar
selectStmt << ( selectToken +
  ( Optional(distinct_) + columnNameList ) +
  fromToken +
  ( tableName.setResultsName("tables", listAllMatches=True )  | ("(" + selectStmt + Optional(")")) ) +
  ZeroOrMore( SkipTo(joinToken, include=True, failOn=whereToken) +
  			(("(" + selectStmt + Optional(")")) | tableName.setResultsName("tables", listAllMatches=True)) ) +
  Optional(SkipTo(whereToken, include=True, failOn=")") + whereExpression) +
  Optional(SkipTo(groupToken, include=True, failOn=")") + groupByList) + 
  Optional(SkipTo(havingToken, include=True, failOn=")") + havingExpression))
开发者ID:ehfeng,项目名称:Spire,代码行数:32,代码来源:queryparser.py


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