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


Python OneOrMore.setResultsName方法代码示例

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


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

示例1: get_parser

# 需要导入模块: from pyparsing import OneOrMore [as 别名]
# 或者: from pyparsing.OneOrMore import setResultsName [as 别名]
 def get_parser():
     """Return a section parser. @see grammar.md for the whole grammar."""
     if Section._parser is None:
         # Parser not yet defined. Defining it.
         head_type       = Literal("V") | Literal("C") | Literal("@")
         head            = OPEN_HEAD \
                 + head_type.setResultsName("type") \
                 + INTEGER.setResultsName("id") \
                 + CLOSE_HEAD + EOL
         content_line    = WORDS + EOL
         content         = OneOrMore(content_line)
         Section._parser = Group(head + content.setResultsName("content"))
     return Section._parser
开发者ID:yapper-git,项目名称:liblyrics,代码行数:15,代码来源:section.py

示例2: fromString

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

		# Imports
		idslImport  = Suppress(CaselessLiteral("import")) + quote +  CharsNotIn("\";").setResultsName('path') + quote + semicolon
		idslImports = OneOrMore(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')  + identifier + ZeroOrMore(Suppress(Word(',')) + identifier) + 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:krips89,项目名称:robocomp,代码行数:39,代码来源:parseCDSL.py

示例3: delimitedList

# 需要导入模块: from pyparsing import OneOrMore [as 别名]
# 或者: from pyparsing.OneOrMore import setResultsName [as 别名]
basisFormat = delimitedList(Word(nums), '/')

contraction = Suppress(parenthesis + slash + brackets) + openBra + basisFormat + closeBra

basisHeader = natural + restOfLine

parseContr = pound + Suppress(Word(alphas, max=2)) + contraction

parseCoeff = Suppress(basisHeader) + OneOrMore(floatNumber)

parseBasisData = OneOrMore(Group(parseCoeff.setResultsName("contractions")))

parseBasis = (star + parseKey +
              parseContr.setResultsName("format") + star +
              parseBasisData.setResultsName("coeffs"))

topParseB = Suppress(header) + OneOrMore(Group(parseBasis))

# ==================> MOs <==================
headerMO = Suppress(SkipTo(Literal("[MO]")) + restOfLine)

sym = Literal("Sym") + restOfLine

spin = Literal("Spin") + restOfLine

occ = Literal("Occ") + restOfLine

numEntry = Suppress(natural + natural + Word(alphas) + natural + Word(alphanums)) + floatNumberDot

eigenValue = Suppress(sym + Literal("Ene=")) + floatNumberDot + Suppress(spin + occ)
开发者ID:SCM-NV,项目名称:qmworks,代码行数:32,代码来源:turbomoleParser.py

示例4: print

# 需要导入模块: from pyparsing import OneOrMore [as 别名]
# 或者: from pyparsing.OneOrMore import setResultsName [as 别名]
join_stmt = (
    join_op + source.setResultsName('source') + on_op.setResultsName('join_cols')).setParseAction(_build_join)

# Example
# join = join_stmt.parseString('join jtable1 as jt1')
# print(join.source.name, join.source.alias)
# (jtable1, jt1)

# define the select grammar
#
select_stmt = Forward()

select_stmt << (
    select_kw
    + (Keyword('*').setResultsName('columns') | select_column_list.setResultsName('columns'))
    + from_kw
    + many_sources.setResultsName('sources')
    + ZeroOrMore(Group(join_stmt)).setResultsName('joins'))

# Examples:
# select = select_stmt.parseString(
#     '''SELECT t1.col AS t1_c, t2.col AS t2_c, t3.col AS t3_c
#     FROM table1 AS t1
#     JOIN table2 AS t2
#     JOIN table3 AS t3;''')
# print(select.columns[0].name, select.columns[0].alias)
# ('t1.col', 't1_c')
# print(select.columns[1].name, select.columns[1].alias)
# ('t2.col', 't2_c')
# print(select.columns[2].name, select.columns[2].alias)
开发者ID:CivicKnowledge,项目名称:ambry,代码行数:32,代码来源:asql_parser.py

示例5: all

# 需要导入模块: from pyparsing import OneOrMore [as 别名]
# 或者: from pyparsing.OneOrMore import setResultsName [as 别名]
        self.mayIndexError = False
        if not all(len(s) == len(suffixes[0]) for s in suffixes[1:]):
            raise ValueError('Suffixes do not all share the same length')

    def parseImpl( self, instring, loc, doActions=True ):
        suffixes = self.suffixes
        suffixLength = len(list(self.suffixes)[0])
        maxlen = len(instring)
        if instring[loc:loc+suffixLength] in self.suffixes:
            raise ParseException(instring, loc, 'StopOnSuffix early stop : token starts with suffix', self)
        start = loc
        loc += 1
        while loc < maxlen and (instring[loc:loc+suffixLength] not in suffixes):
            loc += 1
        return loc, instring[start:loc]

StyledText = Forward()
BoldText = (Bold + StyledText + Bold)('is_bold')
ItalicText = (Italic + StyledText + Italic)('is_italic')
StyledText << (BoldText | ItalicText | StopOnSuffix(['**', '__']))
StyledText.resultsName = 'text'
StyledText.saveAsList = True  # must be done at this point, not before
TextGrammar = StyledText | Text.setResultsName('text', listAllMatches=True)

test('**a text**')
test('**__a text__**')
test('__**a text**__')
test('__**a text__**')
test('a **text**') # crashes because pyparsing raise when parseAll=True on StyledText matching only 2 chars, whereas Text would have matched :(

开发者ID:Lucas-C,项目名称:linux_configuration,代码行数:31,代码来源:pyparsing_StopOnSuffix.py

示例6: funCoefficients

# 需要导入模块: from pyparsing import OneOrMore [as 别名]
# 或者: from pyparsing.OneOrMore import setResultsName [as 别名]
def funCoefficients(x):
    """Parser Coeffcients"""
    fun = OneOrMore(Suppress(orbInfo) + floatNumber * x)
    return fun.setResultsName("coeffs")
开发者ID:SCM-NV,项目名称:qmworks,代码行数:6,代码来源:cp2KParser.py

示例7: Literal

# 需要导入模块: from pyparsing import OneOrMore [as 别名]
# 或者: from pyparsing.OneOrMore import setResultsName [as 别名]
comment = Literal("#") + restOfLine

parseAtomLabel = (Word(srange("[A-Z]"), max=1) +
                  Optional(Word(srange("[a-z]"), max=1)))

parserBasisName = Word(alphanums + "-") + Suppress(restOfLine)

parserFormat = OneOrMore(natural + NotAny(FollowedBy(point)))

parserKey = parseAtomLabel.setResultsName("atom") + \
    parserBasisName.setResultsName("basisName") + \
    Suppress(Literal("1"))

parserBasisData = OneOrMore(floatNumber)

parserBasis = parserKey + parserFormat.setResultsName("format") + \
    parserBasisData.setResultsName("coeffs")


topParseBasis = OneOrMore(Suppress(comment)) + \
    OneOrMore(Group(parserBasis + Suppress(Optional(OneOrMore(comment)))))


# ===============================<>====================================
# Parsing From File

def read_mos_data_input(path_input):
    """
    Try to read the added_mos parameter and the range of printed MOs
    """
    properties = ["ADDED_MOS", "MO_INDEX_RANGE"]
开发者ID:SCM-NV,项目名称:qmworks,代码行数:33,代码来源:cp2KParser.py

示例8: Word

# 需要导入模块: from pyparsing import OneOrMore [as 别名]
# 或者: from pyparsing.OneOrMore import setResultsName [as 别名]
num = Word(nums)
date = Combine(num + "/" + num + "/" + num)


def validateDateString(tokens):
    try:
        time.strptime(tokens[0], "%m/%d/%Y")
    except ValueError:
     raise ParseException("Invalid date string (%s)" % tokens[0])

date.setParseAction(validateDateString)
schoolName = OneOrMore(Word(alphas))
schoolName.setParseAction(lambda tokens: " ".join(tokens))
score = Word(nums).setParseAction(lambda tokens: int(tokens[0]))
schoolAndScore = Group(schoolName.setResultsName("school") + \
                       score.setResultsName("score"))
gameResult = date.setResultsName("date") + schoolAndScore.setResultsName("team1") + \
             schoolAndScore.setResultsName("team2")
tests = """\
09/04/2004 Virginia 44 Temple 14
09/04/2004 LSU 22 Oregon State 21
09/09/2004 Troy State 24 Missouri 14
01/02/2003 Florida State 103 University of Miami 2""".splitlines()
for test in tests:
    stats = gameResult.parseString(test)
    if stats.team1.score != stats.team2.score:
        if stats.team1.score > stats.team2.score:
            result = "won by " + stats.team1.school
        else:
            result = "won by " + stats.team2.school
开发者ID:goldbike,项目名称:edutalk,代码行数:32,代码来源:testPyParsing.py

示例9: Word

# 需要导入模块: from pyparsing import OneOrMore [as 别名]
# 或者: from pyparsing.OneOrMore import setResultsName [as 别名]
# coding: utf-8
from pyparsing import Word, Literal, alphas, alphanums, OneOrMore, ZeroOrMore, infixNotation, opAssoc, oneOf


node_name = Word(alphanums + '_')

node_path = OneOrMore(node_name | Literal('/') | Literal('.') | Literal('..'))

operator = Literal("==")

status = Literal('complete') | Literal('aborted')

logical_operator = Literal('and') | Literal('or')

single_trigger_expr = node_path.setResultsName("node_path").setParseAction(lambda t: ''.join(t)) \
               + operator.setResultsName("operator") \
               + status.setResultsName("status")

trigger_expr = infixNotation(
    single_trigger_expr.setResultsName("single_expr"),
    [(oneOf("and", "AND"), 2, opAssoc.LEFT),
    (oneOf("or", "OR"), 2, opAssoc.RIGHT)]
).setResultsName("complex_filter")


def parse_trigger(trigger):
    return single_trigger_expr.parseString(trigger)
开发者ID:perillaroc,项目名称:takler,代码行数:29,代码来源:trigger_parser.py


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