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


Python Literal.setResultsName方法代码示例

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


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

示例1: get_parser

# 需要导入模块: from pyparsing import Literal [as 别名]
# 或者: from pyparsing.Literal 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 Literal [as 别名]
# 或者: from pyparsing.Literal 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(")"))
		lt       = Suppress(Word("<"))
		gt       = Suppress(Word(">"))
		identifier     = Word(alphas+"_",alphanums+"_")
		typeIdentifier = Word(alphas+"_",alphanums+"_:")


		## Imports
		idslImport  = Suppress(Word("import")) + quote +  CharsNotIn("\";").setResultsName('path') + quote + semicolon
		idslImports = ZeroOrMore(idslImport)


		dictionaryDef = Word("dictionary") + lt + CharsNotIn("<>;") + gt + identifier.setResultsName('name') + semicolon
		sequenceDef   = Word("sequence")   + lt + CharsNotIn("<>;") + gt + identifier.setResultsName('name') + semicolon
		enumDef       = Word("enum")       + identifier.setResultsName('name') + op + CharsNotIn("{}") + cl + semicolon
		structDef     = Word("struct")     + identifier.setResultsName('name') + op + CharsNotIn("{}") + cl + semicolon
		exceptionDef  = Word("exception")  + identifier.setResultsName('name') + op + CharsNotIn("{}") + cl + semicolon

		raiseDef       = Suppress(Word("throws")) + typeIdentifier + ZeroOrMore( Literal(',') + typeIdentifier )
		decoratorDef    = Literal('idempotent') | Literal('out')
		retValDef       = typeIdentifier.setResultsName('ret')

		firstParam    = Group( Optional(decoratorDef.setResultsName('decorator')) + typeIdentifier.setResultsName('type') + identifier.setResultsName('name'))
		nextParam     = Suppress(Word(',')) + firstParam
		params        = firstParam + ZeroOrMore(nextParam)


		remoteMethodDef  = Group(Optional(decoratorDef) + retValDef + typeIdentifier.setResultsName('name') + opp + Optional(          params).setResultsName('params') + clp + Optional(raiseDef) + semicolon )
		interfaceDef    = Word("interface")  + typeIdentifier.setResultsName('name') + op + Group(ZeroOrMore(remoteMethodDef)) + cl + semicolon

		moduleContent = Group(structDef | enumDef | exceptionDef | dictionaryDef | sequenceDef | interfaceDef)
		module = Suppress(Word("module")) + identifier.setResultsName("name") + op + ZeroOrMore(moduleContent).setResultsName("contents") + cl + semicolon

		IDSL = idslImports.setResultsName("imports") + module.setResultsName("module")
		IDSL.ignore( cppStyleComment )
		tree = IDSL.parseString(text)
		return IDSLParsing.module(tree)
开发者ID:BasilMVarghese,项目名称:robocomp,代码行数:48,代码来源:parseIDSL.py

示例3: Optional

# 需要导入模块: from pyparsing import Literal [as 别名]
# 或者: from pyparsing.Literal import setResultsName [as 别名]
                               tok_sql_literal_by + \
                               tok_sql_cols.setResultsName("order_list")
                           ) + \
                  Optional(tok_sql_literal_limit + \
                               tok_sql_identifier) + \
                  Optional(tok_sql_literal_semicol))


sql_delete = tok_sql_literal_delete.setResultsName("op") + restOfLine
sql_update = tok_sql_literal_update.setResultsName("op") + restOfLine
sql_begin = tok_sql_literal_begin.setResultsName("op") + restOfLine
sql_use = tok_sql_literal_use.setResultsName("op") + restOfLine
sql_set = tok_sql_literal_set.setResultsName("op") + restOfLine
sql_commit = tok_sql_literal_commit.setResultsName("op") + restOfLine
sql_rollback = tok_sql_literal_rollback.setResultsName("op") + restOfLine
sql_comment = tok_sql_comment.setResultsName("op") + restOfLine

statements = [sql_insert, sql_update, sql_delete, sql_begin, sql_use,
              sql_commit, sql_rollback, sql_comment, sql_set, sql_select]
sql_statement = Or(statements)

def parse(sql):
    try:
        return sql_statement.parseString(sql)
    except ParseException:
        raise ValueError

# test function adapted from simpleSQL.py : Copyright (c) 2003, Paul McGuire
def test( str, op=sql_insert ):
    print str,"->"
    try:
开发者ID:gburns,项目名称:mysql_pyparsing,代码行数:33,代码来源:sqlparser.py

示例4: __init__

# 需要导入模块: from pyparsing import Literal [as 别名]
# 或者: from pyparsing.Literal import setResultsName [as 别名]
    def __init__(self, network):
        self.network = network
        self.g_business_relationship = nx.DiGraph()
        self.user_defined_sets = {}
        self.user_library_calls = []
        self.user_defined_functions = {}

        # Grammars
#TODO: tidy this up
        attribute_unnamed = Word(alphanums+'_'+".")
        attribute = attribute_unnamed.setResultsName("attribute")
        self.attribute = attribute

        lt = Literal("<").setResultsName("<")
        le = Literal("<=").setResultsName("<=")
        eq = Literal("=").setResultsName("=")
        ne = Literal("!=").setResultsName("!=")
        ge = Literal(">=").setResultsName(">=")
        gt = Literal(">").setResultsName(">")
        wildcard = Literal("*").setResultsName("wildcard")
        self.wildcard = wildcard

        self.prefix_lists = {}
        self.tags_to_allocate = set()
        self.allocated_tags = {}

        self._opn = {
                '<': operator.lt,
                '<=': operator.le,
                '=': operator.eq,
                '!=': operator.ne,
                '>=': operator.ge,
                '>': operator.gt,
                '&': set.intersection,
                '|': set.union,
                }

        # map alphanum chars to alphanum equivalents for use in tags
        self._opn_to_tag = {
                '<': "lt",
                '<=': "le",
                '=': "eq",
                '!=': "ne",
                '>=': "ge",
                '>': "gt",
                '&': "and",
                '|': "or",
                }

# Both are of comparison to access in same manner when evaluating
        comparison = (lt | le | eq | ne | ge | gt).setResultsName("comparison")
        stringComparison = (eq | ne).setResultsName("comparison")
#
#quoted string is already present
        float_string = Word(nums).setResultsName("value").setParseAction(lambda t: float(t[0]))
        integer_string = Word(nums).setResultsName("value").setParseAction(lambda t: int(t[0]))
#TODO: use numString, and make integer if fiull stop

#TODO: allow parentheses? - should be ok as pass to the python parser
        ipField = Word(nums, max=3)
        ipAddress = Combine( ipField + "." + ipField + "." + ipField + "." + ipField ).setResultsName("ipAddress")

        boolean_and = Literal("&").setResultsName("&")
        boolean_or = Literal("|").setResultsName("|")
        boolean = (boolean_and | boolean_or).setResultsName("boolean")
        self._boolean = boolean # need to use in checking

#TODO fix this matching 2a.ab when that should match a string
        numericQuery = Group(attribute + comparison + float_string).setResultsName( "numericQuery")


        stringValues = (attribute_unnamed | quotedString.setParseAction(removeQuotes)
                ).setResultsName("value")

        stringQuery =  Group(attribute + stringComparison + stringValues).setResultsName( "stringQuery")
        wildcardQuery = wildcard.setResultsName("wildcardQuery")

        singleQuery = numericQuery | stringQuery | wildcardQuery
        singleQuery.setFailAction(parse_fail_action)
        self.nodeQuery = singleQuery + ZeroOrMore(boolean + singleQuery)

        self.u_egress = Literal("egress->").setResultsName("u_egress") 
        self.v_ingress = Literal("->ingress").setResultsName("v_ingress")
        self.u_ingress = Literal("ingress<-").setResultsName("u_ingress")
        self.v_egress = Literal("<-egress").setResultsName("v_egress") 
        edgeType = ( self.u_egress | self.u_ingress | self.v_egress
                | self.v_ingress).setResultsName("edgeType").setFailAction(parse_fail_action)
        self.edgeQuery = ("(" + self.nodeQuery.setResultsName("query_a") + ")"
                + edgeType
                + "(" + self.nodeQuery.setResultsName("query_b")
                + ")").setFailAction(parse_fail_action)

#start of BGP queries
        originQuery = (Literal("Origin").setResultsName("attribute") + 
                #this is a workaround for the match, comparison, value 3-tuple in processing
                Literal("(").setResultsName("comparison") +  
                Group(self.nodeQuery).setResultsName("value") + Suppress(")")).setResultsName("originQuery")
        transitQuery = (Literal("Transit").setResultsName("attribute") +
                #this is a workaround for the match, comparison, value 3-tuple in processing
                Literal("(").setResultsName("comparison") +  
#.........这里部分代码省略.........
开发者ID:coaj,项目名称:autonetkit,代码行数:103,代码来源:bgp_policy.py

示例5: Roman

# 需要导入模块: from pyparsing import Literal [as 别名]
# 或者: from pyparsing.Literal import setResultsName [as 别名]
1 modern Courier New 02070309020205020404
2 roman Symbol 05050102010706020507
3 roman Times New Roman (Hebrew) 0
"""
from pyparsing import Optional, Literal, Word, Group, White
from pyparsing import Suppress, Combine, replaceWith
from pyparsing import alphas, nums, printables, alphanums
from pyparsing import restOfLine, oneOf, OneOrMore, ZeroOrMore
from pyparsing import ParseException

separator = Literal(';')
space = Literal(' ')
white = White()
leftBracket = Literal('{')
rightBracket = Literal('}')
bracket = leftBracket | rightBracket.setResultsName('bracket')

# basic RTF control codes, ie. "\labelname3434"
controlLabel = Combine(Word(alphas + "'") + Optional(Word(nums)))
controlValue = Optional(space) + Optional(Word(alphanums + '-'))
baseControl = Combine(Literal('\\') + controlLabel + controlValue
                      ).setResultsName('baseControl')

# in some cases (color and font table declarations), control has ';'
# suffix
rtfControl = Combine(baseControl + Optional(separator)
                     ).setResultsName('control')

rtfGroup = leftBracket + OneOrMore(rtfControl) + rightBracket

# opening controls
开发者ID:brew,项目名称:pyrtf-ng,代码行数:33,代码来源:grammar.py

示例6: Group

# 需要导入模块: from pyparsing import Literal [as 别名]
# 或者: from pyparsing.Literal import setResultsName [as 别名]
NOUN = Group(OneOrMore(NNPS|NNP|NNS|NN))
#PROPER_NOUN = Group(OneOrMore(NNP|NNPS))
VERB = OneOrMore(VDB|VBG|VBN|VBP|VBZ|VB)
ADJECTIVE = OneOrMore(JJ)
ADVERB = OneOrMore(RB)

ARTICLE_NOUN = Group(DT + NOUN)
ADJECTIVE_NOUN = Group(ADJECTIVE + NOUN)
VERB_NOUN = Group(VERB + NOUN)
POS_NOUN = Group((ARTICLE_NOUN | NOUN) + POS + (ADJECTIVE_NOUN | VERB_NOUN | NOUN)) 
ARTICLE_ADJECTIVE_NOUN = Group(DT + ADJECTIVE_NOUN)
NOUN_AND_NOUN = Group((NOUN | ARTICLE_NOUN) + AND + (POS_NOUN | ARTICLE_NOUN | NOUN))
NOUN_OF_NOUN = Group((NOUN_AND_NOUN | ARTICLE_NOUN | NOUN) + OF + (NOUN_AND_NOUN | ARTICLE_NOUN | NOUN))

#TODO
DT.setResultsName('article')
NOUN.setResultsName('noun')

#TODO
expr = Forward()
expr << (NOUN_OF_NOUN | 
		NOUN_AND_NOUN | 
		ARTICLE_ADJECTIVE_NOUN | 
		ADJECTIVE_NOUN | 
		POS_NOUN |
		ARTICLE_NOUN |  
		NOUN)

def read_in_file():
	"""Returns read in csv file(s)."""
	title_list = []
开发者ID:mdth,项目名称:MA,代码行数:33,代码来源:test_pyparsing.py

示例7: __init__

# 需要导入模块: from pyparsing import Literal [as 别名]
# 或者: from pyparsing.Literal import setResultsName [as 别名]
class RpkiSetsParser:
    """Parser class"""
    def __init__(self, network):
        self.network = network
#        self.user_defined_sets = {}

        attribute_unnamed = Word(alphanums+'_'+".")
        attribute = attribute_unnamed.setResultsName("attribute")
        self.attribute = attribute
        integer_string = Word(nums).setResultsName("value").setParseAction(lambda t: int(t[0]))
	
	self.nodeQuery = attribute.setResultsName("nodeQuery").setFailAction(parse_fail_action)

        self.children = Literal("children").setResultsName("children") 
        self.relation = self.children.setResultsName("relation").setFailAction(parse_fail_action)

        set_values = Suppress("{") + delimitedList( attribute, delim=',').setResultsName("set_values") + Suppress("}")
        empty_set = Literal("{}").setResultsName("set_values").setParseAction(lambda x: set())

	self.set_definition = ("(" + self.nodeQuery + ")" + self.relation + (empty_set | set_values))
        self.rpkiSetsLine = (self.set_definition.setResultsName("set_definition"))
	self.path = {}


    def apply_rpki_sets(self, qstring):
        LOG.debug("Applying RPKI sets %s" % qstring)
        result = self.rpkiSetsLine.parseString(qstring)
	self.network.g_rpki.add_node(result.nodeQuery)
        if 'set_definition' in result:
            LOG.debug("Storing set definition %s" % result.set_name)
	    for n in result.set_values:
	        self.network.g_rpki.add_node(n)
    	        self.network.g_rpki.add_edge(result.nodeQuery, n, relation = result.relation)

            return


    def apply_rpki_file(self, rpki_in_file):
        """Applies a BGP policy file to the network"""
        LOG.debug("Applying policy file %s" % rpki_in_file)
        rpki_lines = []
        rpki_path = os.path.split(rpki_in_file)[0]
        with open( rpki_in_file, 'r') as f_rpki:
            for line in f_rpki.readlines():
                line = line.strip()
                if line.startswith("#"):
                    LOG.debug("Skipping commented line %s", line)
                    continue
                if line == "":
                    continue
                rpki_lines.append(line)

        for line in rpki_lines:
            line = line.strip()
            if line.startswith("#"):
                LOG.debug("Skipping commented line %s", line)
                continue
            if line == "":
                continue
            try:
                self.apply_rpki_sets(line)
            except pyparsing.ParseFatalException as e:
                LOG.warn("Unable to parse query line %s" % line)
开发者ID:coaj,项目名称:autonetkit,代码行数:65,代码来源:rpki.py

示例8: use

# 需要导入模块: from pyparsing import Literal [as 别名]
# 或者: from pyparsing.Literal import setResultsName [as 别名]
We use token.setResultsName("key") to make the key value dictionary for easily
fishing results out later, much better thean indexing a list, which might
change size if we change things later. Dictionary is not sensitive to that.

We also use () for long lines not \ because apparently it's better.
"""

""" checkout - standard format grammar definition
OUT product version pool# user host "isv_def" count cur_use cur_resuse \
    server_handle share_handle process_id "project" "requested product" \
    "requested version" mm/dd hh:mm:ss
example:
OUT imarisbase 6.0 9 heisenberg_lab my-workstation-72 "" 1 1 0 26e 26e 410 "" "" "" 06/16 10:57:52
"""
rlmRlogCheckoutEntry_std = (Literal("OUT").setResultsName("checkedOut") +
    product.setResultsName("product") +
    version.setResultsName("version") +
    poolNum +
    user.setResultsName("user") +
    host.setResultsName("host") +
    isvDef.setResultsName("isDef") +
    count.setResultsName("count") +
    curUse +
    curReuse +
    serverHandle.setResultsName("serverHandle") +
    shareHandle +
    processId +
    project +
    requestedProduct +
    requestedVersion +
    date.setResultsName("date") +
开发者ID:imcf,项目名称:rlm_logparser,代码行数:33,代码来源:rlm_rlog_data_extractor.py

示例9: Optional

# 需要导入模块: from pyparsing import Literal [as 别名]
# 或者: from pyparsing.Literal import setResultsName [as 别名]
    gSpace + gName + gSpaces + gParameters).setResultsName("usage")
gEmptyLine = gSpaces + gEOL
gShortText = Optional(
    Word(srange("[A-Z]") + srange("[a-z]")) + restOfLine) + gEOL_keep
#gText = OneOrMore(gShortText)
#gIntroduction = Optional(
    #Group(Word(srange("[A-Z]") + srange("[a-z]")) + Regex(".*:$"))
    #.setResultsName("introduction"))
gOptionDescriptionText = \
    Optional(gRepetition + Literal(':')) + \
    OneOrMore(
        Optional(Regex("\n")) + gSpaces + Optional(Literal('(')) +
        Word(alphas, alphanums + '_') + restOfLine)\
    .setResultsName("description")
gOptionDescriptionOption = gSpaces + \
    gRawOption.setResultsName("first_option") + Optional(gParameter) + \
    ZeroOrMore(
        Group(
            Literal(",").suppress() + gSpace.suppress() +
            gRawOption.setResultsName("option") + Optional(gParameter)))\
    .setResultsName("other_options")
gOptionDescriptionSwitch = Or([
    gOptionDescriptionOption,
    gInnerParameter,
    gStdin])
gOptionDescription = (gOptionDescriptionSwitch + gOptionDescriptionText)\
    .setResultsName("option_description")
#gBidule = gIntroduction + gOptionDescription
#gSubNext = Or([gBidule, gShortText.setResultsName("short_text")])
#gNext = Dict(ZeroOrMore(Group(gSubNext))).setResultsName("next")
gRest = Regex("(.*\n?)*").setResultsName("rest")
开发者ID:dchilot,项目名称:viscum,代码行数:33,代码来源:laxum.py

示例10: operator

# 需要导入模块: from pyparsing import Literal [as 别名]
# 或者: from pyparsing.Literal import setResultsName [as 别名]
def operator():
    token = Literal("+") | Literal("-") | Literal("/") | Literal("*")
    token.setName("operator")
    token.setResultsName("operator")
    return token
开发者ID:zroot,项目名称:dice-python,代码行数:7,代码来源:grammar.py

示例11: Optional

# 需要导入模块: from pyparsing import Literal [as 别名]
# 或者: from pyparsing.Literal import setResultsName [as 别名]
join_header = Optional(Literal("left") | Literal("right")) + (Literal("join") | Literal("inner join") |
                                                              Literal("outer join"))

join_tail = Group(identifier.setResultsName("table") + Suppress("on") +
                  Group(column + Suppress("=") + column).setResultsName("join_link"))

columns = Group(star | (ZeroOrMore(column + comma) + column))

join = Group(join_header.setResultsName("join_type") + join_tail)

whr_column = Group(column + oneOf([">", "<", ">=", "<=", "=", "!="]) + (values | column))

whrs = whr + Group(ZeroOrMore(whr_column + oneOf(["and", "or"]))+ whr_column)

cds = cd.setResultsName("db_cmd") + identifier.setResultsName("db_name")
dds = dd.setResultsName("db_cmd") + identifier.setResultsName("db_name")
uds = ud.setResultsName("db_cmd") + identifier.setResultsName("db_name")

cts = ct.setResultsName("db_cmd") + identifier.setResultsName("table_name")
dts = dt.setResultsName("db_cmd") + identifier.setResultsName("table_name")

cfs = cf.setResultsName("db_cmd") + identifier.setResultsName("fragment_name") + \
      location.setResultsName("location") + Suppress("on") + identifier.setResultsName("table_name") + \
      opening_bracket + columns.setResultsName("columns") + closing_bracket

dfs = df.setResultsName("db_cmd") + identifier.setResultsName("fragment_name") + Suppress("on") + \
      identifier.setResultsName("table_name")

sds = sd.setResultsName("db_cmd")
sts = st.setResultsName("db_cmd")
开发者ID:kmwenja,项目名称:siafu,代码行数:32,代码来源:grammar.py

示例12: use

# 需要导入模块: from pyparsing import Literal [as 别名]
# 或者: from pyparsing.Literal import setResultsName [as 别名]
a valid out is
OUT imarisbase 6.0 9 heisenberg_lab heisenberg-8-434 "" 1 1 0 26e 26e 410 "" "" "" 06/16 10:57:52
OUT product version pool# user host "isv_def" count cur_use cur_resuse server_handle share_handle process_id "project" "requested product" "requested version" mm/dd hh:mm:ss 

deny is
DENY product version user host "isv_def" count why last_attempt mm/dd hh:mm

We use token.setResultsName("key") to make the key value dictionary for easily fishing results out later, 
much better thean indexing a list, which might change size if we change things later. 
Dictionary is not sensetive to that.  

We also use ( ) for long lines not \ because apparently it's better. 
"""

rlmRlogCheckoutEntry = ( Literal("OUT").setResultsName("checkedOut") + product.setResultsName("product") + 
    version.setResultsName("version") + 
    poolNum + user.setResultsName("user") + host.setResultsName("host") + 
    isvDef.setResultsName("isDef") + 
    count.setResultsName("count") + curUse + curReuse + serverHandle.setResultsName("serverHandle") + 
    shareHandle + processId + project + 
    requestedProduct + requestedVersion + 
    date.setResultsName("date") + timeHHMMSS.setResultsName("time") 
    )

rlmRlogCheckinEntry = ( Literal("IN").setResultsName("checkedIn") + whyIn + product.setResultsName("product") + 
    version.setResultsName("version") + 
    user.setResultsName("user") + host.setResultsName("host") + 
    isvDef.setResultsName("isDef") + 
    count.setResultsName("count") + curUse + curReuse + serverHandle.setResultsName("serverHandle") + 
    date.setResultsName("date") + timeHHMMSS.setResultsName("time")
开发者ID:chalkie666,项目名称:rlm_rlog_data_extractor,代码行数:32,代码来源:rlm_rlog_data_extractor.py

示例13: _ungroup

# 需要导入模块: from pyparsing import Literal [as 别名]
# 或者: from pyparsing.Literal import setResultsName [as 别名]
_p_lease_hardware_ethernet = _ungroup(
    Keyword("hardware").suppress()
    + Keyword("ethernet").suppress()
    + _p_mac
    )

_p_lease_junk = (
    Word(alphas)
    # if we include { } ; here, they become greedy and eat the closing
    # brace or semicolon
    + CharsNotIn('{};')
    ).suppress()

_p_lease_decl = (
    _p_lease_deleted.setResultsName('deleted')
    | _p_lease_hardware_ethernet.setResultsName('mac')
    | _p_lease_junk
    ) + Literal(';').suppress()

_p_lease = (
    Keyword("lease").suppress()
    + _p_ip_address.setResultsName('ip')
    + _ungroup(
        nestedExpr(
            opener='{',
            closer='}',
            content=_p_lease_decl,
            ignoreExpr=quotedString,
            ),
        )
开发者ID:AsherBond,项目名称:propernoun,代码行数:32,代码来源:parser.py

示例14: Combine

# 需要导入模块: from pyparsing import Literal [as 别名]
# 或者: from pyparsing.Literal import setResultsName [as 别名]
# variables, arrays, functions, etc...
safe_variable = Combine("_" + Word(ac_chars) + "=" + opQuotedString(Word(ac_chars.replace(";", ""))))
var_array = "(" + OneOrMore(opQuotedString(Word(ac_chars + " ="))) + ")"
bad_variable = Combine(Word(ac_chars) + "=" + (var_array | opQuotedString(Word(ac_chars))))

generic_function = function_head(Word(alphas + "_", alphanums + "_")) + function_body

if_expression = Forward()
case_statement = Forward()
statement_seperator = Literal(";")
statement_block = Forward()
bash_functions = oneOf("echo sed awk") + restOfLine


# TODO: match all possible PKGBUILDs
pkgbuildline = (pkgname.setResultsName("pkgname")
        | pkgver.setResultsName("pkgver")
        | pkgrel.setResultsName("pkgrel")
        | pkgdesc.setResultsName("pkgdesc")
        | epoch.setResultsName("epoch")
        | url.setResultsName("url")
        | license.setResultsName("license")
        | install.setResultsName("install")
        | changelog.setResultsName("changelog")
        | source.setResultsName("source")
        | noextract.setResultsName("noextract")
        | chksums.setResultsName("chksums")
        | groups.setResultsName("groups")
        | arch.setResultsName("arch")
        | backup.setResultsName("backup")
        | depends.setResultsName("depends")
开发者ID:ccr-tools,项目名称:aur2ccr,代码行数:33,代码来源:pkgbuild_parser.py

示例15: Word

# 需要导入模块: from pyparsing import Literal [as 别名]
# 或者: from pyparsing.Literal 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.Literal.setResultsName方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。