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


Python Combine.copy方法代码示例

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


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

示例1: instance

# 需要导入模块: from pyparsing import Combine [as 别名]
# 或者: from pyparsing.Combine import copy [as 别名]
def instance():
	lit_e = CaselessLiteral('E')
	plusorminus = Literal('+') | Literal('-')
	number = Word(nums) 
	integer = Combine(Optional(plusorminus) +
						number).setParseAction(lambda t:int(t[0]))
	index = integer.copy().addParseAction(index_check(0))
	floatnumber = Combine( integer +
							Optional( Literal('.') + Optional(number) ) +
							Optional( lit_e + integer )
						).setParseAction(lambda t:float(t[0]))

	#comment = Suppress("%") + Word(alphanums + " ") 
	comment = Regex(r"%.*").setName("comment").suppress()
	linend = Or( [comment , LineEnd()] ).suppress()
	section_end = (Literal('#') + LineEnd()).suppress()

	vertex = (Group( OneOrMore( floatnumber('point') +
					 OneOrMore( White() ).suppress() ) ) + linend)('vertex')
	vertex_header = (Keyword('VERTEX') + linend).suppress()
	vertex_section = (vertex_header + Group(OneOrMore(vertex))('vertices') +
						section_end)

	simplex = (Group( OneOrMore( index('index')
					+ OneOrMore( White() ).suppress() ) ) + linend)('simplex')
	simplex_header = (Keyword('SIMPLEX') + linend).suppress()
	simplex_section = (simplex_header + Group(OneOrMore(simplex))('simplices') +
						section_end)

	boundarysegment = (Group( index('id') +
								OneOrMore( index('index') +
								OneOrMore( White() ).suppress() ) ) +
								linend)('boundarysegment')
	boundarysegment_header = (Keyword('BOUNDARYSEGMENTS') + linend).suppress()
	boundarysegment_section = (boundarysegment_header +
								Dict(OneOrMore(
									boundarysegment ))('boundarysegments') +
								section_end)

	sections = Each([vertex_section, simplex_section, boundarysegment_section])
	dgf_header = (Keyword('DGF') + linend).suppress()
	dgf = (dgf_header + Dict(sections) + OneOrMore( section_end ))('dgf')
	return dgf
开发者ID:wwu-numerik,项目名称:pydune,代码行数:45,代码来源:grammar.py

示例2: expr

# 需要导入模块: from pyparsing import Combine [as 别名]
# 或者: from pyparsing.Combine import copy [as 别名]
    (Keyword("distinct", caseless=True)("op").setDebugActions(*debug) + expr("params")).addParseAction(to_json_call) |
    Keyword("null", caseless=True).setName("null").setDebugActions(*debug) |
    case |
    (Literal("(").setDebugActions(*debug).suppress() + selectStmt + Literal(")").suppress()) |
    (Literal("(").setDebugActions(*debug).suppress() + Group(delimitedList(expr)) + Literal(")").suppress()) |
    realNum.setName("float").setDebugActions(*debug) |
    intNum.setName("int").setDebugActions(*debug) |
    (Literal("-")("op").setDebugActions(*debug) + expr("params")).addParseAction(to_json_call) |
    sqlString.setName("string").setDebugActions(*debug) |
    (
        Word(alphas)("op").setName("function name").setDebugActions(*debug) +
        Literal("(").setName("func_param").setDebugActions(*debug) +
        Optional(selectStmt | Group(delimitedList(expr)))("params") +
        ")"
    ).addParseAction(to_json_call).setDebugActions(*debug) |
    ident.copy().setName("variable").setDebugActions(*debug)
)
expr << Group(infixNotation(
    compound,
    [
        (
            o,
            3 if isinstance(o, tuple) else 2,
            opAssoc.LEFT,
            to_json_operator
        )
        for o in KNOWN_OPS
    ]+[
        (
            COLLATENOCASE,
            1,
开发者ID:klahnakoski,项目名称:pyLibrary,代码行数:33,代码来源:sql_parser.py

示例3: _p_simple

# 需要导入模块: from pyparsing import Combine [as 别名]
# 或者: from pyparsing.Combine import copy [as 别名]
filtertype.setName('filtertype')
simple = attr + filtertype + value
simple.leaveWhitespace()
simple.setName('simple')


def _p_simple(s, l, t):
    attr, filtertype, value = t
    return filtertype(attributeDesc=pureldap.LDAPAttributeDescription(attr),
                      assertionValue=pureldap.LDAPAssertionValue(value))


simple.setParseAction(_p_simple)
present = attr + "=*"
present.setParseAction(lambda s, l, t: pureldap.LDAPFilter_present(t[0]))
initial = value.copy()
initial.setParseAction(lambda s, l, t: pureldap.LDAPFilter_substrings_initial(t[0]))
initial.setName('initial')
any_value = value + Suppress(Literal("*"))
any_value.setParseAction(lambda s, l, t: pureldap.LDAPFilter_substrings_any(t[0]))
any = Suppress(Literal("*")) + ZeroOrMore(any_value)
any.setName('any')
final = value.copy()
final.setName('final')
final.setParseAction(lambda s, l, t: pureldap.LDAPFilter_substrings_final(t[0]))
substring = attr + Suppress(Literal("=")) + Group(Optional(initial) + any + Optional(final))
substring.setName('substring')


def _p_substring(s, l, t):
    attrtype, substrings = t
开发者ID:cwaldbieser,项目名称:ldaptor,代码行数:33,代码来源:ldapfilter.py

示例4: get_parser

# 需要导入模块: from pyparsing import Combine [as 别名]
# 或者: from pyparsing.Combine import copy [as 别名]

#.........这里部分代码省略.........

    def push_param_list(code_str, loc, toks):
        """ toks will be a list of the form [ name1, name2, '=', val2, name3, ... ] """
        params = {}
        i = 0
        l = len(toks)
        while i < l:
            param_name = toks[i]
            if i + 2 < l and toks[i + 1] == '=':
                param_value = toks[i + 2]
                increment = 3
            else:
                param_value = DEFAULT_PARAM_VALUE
                increment = 1
            params[param_name] = param_value

            i += increment
        return params
    
    def push_default_stmt(code_str, loc, toks):
        ''' toks will be of the form ["particle", param_dict] or ["decay", param_dict] '''
        return ParsedDefault(toks[1], toks[0].lower() == 'particle')

    def push_stmt_list(code_str, loc, toks):
        """ toks will be a ParseResults of Particle/ParsedDecay/ParsedParam objects """
        proc_group = ProcessGroup()
        
        seen_particles = {}
        edges = []
        
        particle_defaults = {}

        def params_for_object(obj, defaults):
            params = defaults.copy()
            params.update(obj.params)
            return params
        
        # Add particle objects we've generated already
        toks = toks.asList()
        for token in toks:
            if isinstance(token, ParsedDefault) and token.for_particle:
                particle_defaults.update(token.params)
                    
            elif isinstance(token, ParsedParticle):
                #print 'Adding ', token.name
                seen_particles[token.name] = Particle( token.params.pop('type', token.name),
                                                       **params_for_object(token, particle_defaults) )

        def find_or_insert_particle(name):
            if seen_particles.has_key(name):
                #print 'Using existing particle for %s' % name
                return seen_particles[name]
            else:
                #print 'Creating %s' % name
                seen_particles[name] = Particle(name, **particle_defaults) # Type is assumed to be the name of the particle
                return seen_particles[name]

        # Next add decays and any particles they reference that we haven't found already
        particle_defaults = {} # Reset so that we can use the right defaults at each place in the file
        decay_defaults = {}
        for token in toks:
            if isinstance(token, ParsedDefault):
                if token.for_particle:
                    particle_defaults.update(token.params)
                else:
                    decay_defaults.update(token.params)
开发者ID:mattbellis,项目名称:pydecay,代码行数:70,代码来源:graphphys.py

示例5: _word_action

# 需要导入模块: from pyparsing import Combine [as 别名]
# 或者: from pyparsing.Combine import copy [as 别名]
    global _ws_state
    _ws_state = t[0]
    return ""

def _word_action(t):
    global _ws_state
    if _ws_state:
        r = ''.join((_ws_state, t[0]))
        _ws_state = ""
        return r

def _text_action(t):
    global _ws_state
    _ws_state = ""

_text = Combine(OneOrMore(_word.copy().setParseAction(_word_action) | _ws.copy().setParseAction(_ws_action))).setParseAction(_text_action).setFailAction(lambda s, l, ex, err: _text_action(None))
_description = _text.copy()


_decimal = Word(nums).setParseAction(lambda t: int(t[0]))

_cmd_state = None

def _get_reset_cmd_state_action(cmd):
    def _reset_cmd_state_action(t):
        global _cmd_state
        if cmd is None or (_cmd_state is not None and _cmd_state == cmd):
            _cmd_state = None
    return Empty().setParseAction(_reset_cmd_state_action)

def _get_keyword_action(kw):
开发者ID:vsemionov,项目名称:wordbase,代码行数:33,代码来源:cmdparser.py


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