本文整理汇总了Python中pyparsing.Combine类的典型用法代码示例。如果您正苦于以下问题:Python Combine类的具体用法?Python Combine怎么用?Python Combine使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Combine类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: define_number
def define_number(self):
"""
Return the syntax definition for a number in Arabic Numerals.
Override this method to support numeral systems other than Arabic
Numerals (0-9).
Do not override this method just to change the character used to
separate thousands and decimals: Use :attr:`T_THOUSANDS_SEPARATOR`
and :attr:`T_DECIMAL_SEPARATOR`, respectively.
"""
# Defining the basic tokens:
to_dot = lambda t: "."
to_plus = lambda t: "+"
to_minus = lambda t: "-"
positive_sign = Literal(self._grammar.get_token("positive_sign"))
positive_sign.setParseAction(to_plus)
negative_sign = Literal(self._grammar.get_token("negative_sign"))
negative_sign.setParseAction(to_minus)
decimal_sep = Literal(self._grammar.get_token("decimal_separator"))
decimal_sep.setParseAction(to_dot)
thousands_sep = Suppress(self._grammar.get_token("thousands_separator"))
digits = Word(nums)
# Building the integers and decimals:
sign = positive_sign | negative_sign
thousands = Word(nums, max=3) + \
OneOrMore(thousands_sep + Word(nums, exact=3))
integers = thousands | digits
decimals = decimal_sep + digits
number = Combine(Optional(sign) + integers + Optional(decimals))
number.setParseAction(self.make_number)
number.setName("number")
return number
开发者ID:aipub,项目名称:booleano,代码行数:34,代码来源:parsers.py
示例2: func_tokens
def func_tokens(dictionary, parse_action):
func_name = Word(alphas+'_', alphanums+'_')
func_ident = Combine('$' + func_name.copy()('funcname'))
func_tok = func_ident + originalTextFor(nestedExpr())('args')
func_tok.leaveWhitespace()
func_tok.setParseAction(parse_action)
func_tok.enablePackrat()
rx_tok = Combine(Literal('$').suppress() + Word(nums)('num'))
def replace_token(tokens):
index = int(tokens.num)
return dictionary.get(index, u'')
rx_tok.setParseAction(replace_token)
strip = lambda s, l, tok: tok[0].strip()
text_tok = CharsNotIn(u',').setParseAction(strip)
quote_tok = QuotedString('"')
if dictionary:
arglist = Optional(delimitedList(quote_tok | rx_tok | text_tok))
else:
arglist = Optional(delimitedList(quote_tok | text_tok))
return func_tok, arglist, rx_tok
开发者ID:frnogueira,项目名称:puddletag,代码行数:27,代码来源:findfunc.py
示例3: 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
示例4: make_enewick_parser
def make_enewick_parser():
# atoms
lparen = Literal("(").suppress()
rparen = Literal(")").suppress()
colon = Literal(":").suppress()
# semicolon = Literal(";").suppress()
comma = Literal(",").suppress()
point = Literal(".")
e = CaselessLiteral("E")
sharp = Literal("#").suppress()
# terminal
name = Word(
alphanums + alphas8bit + "_" + "-" + "." + "+" + "&" + "/" + "~" + "{" + "}" + "*" + "'" + '"' + "\\" + "?"
)
string = Word(alphas)
fnumber = Combine(
Word("+-" + nums, nums) + Optional(point + Optional(Word(nums))) + Optional(e + Word("+-" + nums, nums))
).setParseAction(cvtReal)
number = Combine(Word(nums)).setParseAction(cvtInt)
label = (
Optional(name).setResultsName("label")
+ Optional(sharp + Optional(string).setResultsName("type") + number.setResultsName("tag"))
+ Optional(colon + fnumber).setResultsName("length")
)
subtree = Forward()
subtreelist = Forward()
subtree << Group(((lparen + subtreelist + rparen).setResultsName("subtree") | label) + Optional(label))
subtreelist << subtree + Optional(comma + subtreelist)
tree = subtree + Word(";").suppress()
return tree.parseString
开发者ID:paurullan,项目名称:phylonets,代码行数:35,代码来源:enewick.py
示例5: expression
def expression(self):
from pyparsing import Suppress,Combine,Optional,oneOf,OneOrMore,Word,nums,Group,alphas,alphanums,Literal,SkipTo,empty,lineEnd
cvtInt = lambda toks: int(toks[0])
cvtReal = lambda toks: float(toks[0])
cvtTuple = lambda toks : tuple(toks.asList())
nameJoin = lambda toks : "".join([tok.replace("#","") for tok in toks[0]])
#lambda toks: " ".join([str(t) for t in toks[0]])
# define punctuation as suppressed literals
lparen,rparen,lbrack,rbrack,lbrace,rbrace,colon = map(Suppress,"()[]{}:")
integer = Combine(Optional(oneOf("+ -")) + Word(nums))\
.setName("integer")\
.setParseAction( cvtInt )
real = Combine(Optional(oneOf("+ -")) + Word(nums) + "." +
Optional(Word(nums)) +
Optional(oneOf("e E")+Optional(oneOf("+ -")) +Word(nums))).setName("real").setParseAction( cvtReal )
# TREE DEFINITION
# ((seq2: 0.537243, seq1: 0.000004): 0.255741, seq3: 0.281503);
tree_w_branches = (
OneOrMore(Word("():,."+alphas+nums))+Literal(";")
).setParseAction(lambda tokens: " ".join(tokens[:-1])+";")
# SITE PROBABILITIES
# site Freq Data:
# 1 1 AAA: A(0.978) A(1.000)
site_prob = (
integer.setResultsName("site",listAllMatches=True) +
integer.setResultsName("freq",listAllMatches=True) +
Word(alphas+"-").setResultsName("extant",listAllMatches=True) + colon +
Group(OneOrMore(Group(Word(alphas,exact=1)+lparen+real+rparen))).setResultsName("probability",listAllMatches=True) +
lineEnd
)
# ANCESTRAL SEQUENCES
# seq1 ACC
# node #4 ACC
# Optional # character with node # needs to be joined into a single name
sequence = (
Group(Word(alphanums)+
Optional(Combine(Literal("#")+Word(nums)))).setParseAction(nameJoin).setResultsName("name",listAllMatches=True)+
Word(alphas+"- ").setResultsName("sequence", listAllMatches=True)+lineEnd
)
return (SkipTo(Literal("Ancestral reconstruction by AAML."),include=True).suppress() +
tree_w_branches.setResultsName("tree") +
SkipTo(Literal("site")+Literal("Freq")+Literal("Data:"), include=True,).suppress()+
Group(OneOrMore(site_prob)).setResultsName("sites")+
SkipTo(Literal("List of extant and reconstructed sequences")+Word(nums)+Word(nums), include=True).suppress()+
Group(OneOrMore(sequence)).setResultsName("sequences")+
SkipTo(Literal("for a site."),include=True).suppress()+
Group(OneOrMore(real)).setResultsName("probability")+
empty
)
开发者ID:bsmithers,项目名称:hpf,代码行数:56,代码来源:paml.py
示例6: is_ipv4_addr
def is_ipv4_addr(inputstr):
from pyparsing import Combine, Word, nums
ipAddress = Combine(Word(nums) + ('.' + Word(nums)) * 3)
try:
ipAddress.parseString(inputstr)
return True
except:
return False
开发者ID:lpther,项目名称:SysadminToolkit,代码行数:10,代码来源:utils.py
示例7: _BNF
def _BNF(self):
base16 = Literal("$")
hex = Combine(base16 + Word(hexnums + "_"))
base4 = Literal("%%")
quaternary = Combine(base4 + Word("0123_"))
base2 = Literal("%")
binary = Combine(base2 + Word("01_"))
plusminus = Literal("+") | Literal("-")
integer = Combine(Optional(plusminus) + Word(nums+"_"))
name_token = Combine(Optional(Literal(":") | Literal("@")) + Word("_" + alphas, "_" + alphanums))
name_token.setParseAction(self._mark_name_token)
lparens = Literal("(").suppress()
rparens = Literal(")").suppress()
# op0 = Literal("@")
op1 = (Literal("^^") | Literal("||") | Literal("|<") | Literal(">|") | Literal("!")).setParseAction(self._mark_unary)
op2 = Literal("->") | Literal("<-") | Literal(">>") | Literal("<<") | Literal("~>") | Literal("><")
op3 = Literal("&")
op4 = Literal("|") | Literal("^")
op5 = Literal("**") | Literal("*") | Literal("//") | Literal("/")
op6 = Literal("+") | Literal("-")
op7 = Literal("#>") | Literal("<#")
op8 = Literal("<") | Literal(">") | Literal("<>") | Literal("==") | Literal("=<") | Literal("=>")
op9 = Literal("NOT").setParseAction(self._mark_unary)
op10 = Literal("AND")
op11 = Literal("OR")
op12 = Literal(",")
expr = Forward()
atom = name_token | hex | quaternary | binary | integer | quotedString
atom.setParseAction(self._push)
atom = atom | (lparens + expr.suppress() + rparens)
# term0 = atom + ZeroOrMore((op0 + atom) .setParseAction(self._push))
# term1 = term0 + ZeroOrMore((op1 + term0) .setParseAction(self._push))
term1 = atom + ZeroOrMore((op1 + atom) .setParseAction(self._push))
term2 = term1 + ZeroOrMore((op2 + term1) .setParseAction(self._push))
term3 = term2 + ZeroOrMore((op3 + term2) .setParseAction(self._push))
term4 = term3 + ZeroOrMore((op4 + term3) .setParseAction(self._push))
term5 = term4 + ZeroOrMore((op5 + term4) .setParseAction(self._push))
term6 = term5 + ZeroOrMore((op6 + term5) .setParseAction(self._push))
term7 = term6 + ZeroOrMore((op7 + term6) .setParseAction(self._push))
term8 = term7 + ZeroOrMore((op8 + term7) .setParseAction(self._push))
term9 = term8 + ZeroOrMore((op9 + term8) .setParseAction(self._push))
term10 = term9 + ZeroOrMore((op10 + term9) .setParseAction(self._push))
term11 = term10 + ZeroOrMore((op11 + term10).setParseAction(self._push))
expr << term11 + ZeroOrMore((op12 + term11).setParseAction(self._push))
return expr
开发者ID:Seairth,项目名称:Orochi,代码行数:55,代码来源:expression.py
示例8: getkw_bnf
def getkw_bnf(self):
sect_begin = Literal("{").suppress()
sect_end = Literal("}").suppress()
array_begin = Literal("[").suppress()
array_end = Literal("]").suppress()
tag_begin = Literal("<").suppress()
tag_end = Literal(">").suppress()
eql = Literal("=").suppress()
dmark = Literal('$').suppress()
end_data=Literal('$end').suppress()
prtable = alphanums+r'!$%&*+-./<>[email protected]^_|~'
ival=Regex('[-]?\d+')
dval=Regex('-?\d+\.\d*([eE]?[+-]?\d+)?')
lval=Regex('([Yy]es|[Nn]o|[Tt]rue|[Ff]alse|[Oo]n|[Oo]ff)')
# Helper definitions
kstr= quotedString.setParseAction(removeQuotes) ^ \
dval ^ ival ^ lval ^ Word(prtable)
name = Word(alphas+"_",alphanums+"_")
vec=array_begin+delimitedList(dval ^ ival ^ lval ^ Word(prtable) ^ \
Literal("\n").suppress() ^ \
quotedString.setParseAction(removeQuotes))+array_end
sect=name+sect_begin
tag_sect=name+Group(tag_begin+name+tag_end)+sect_begin
# Grammar
keyword = name + eql + kstr
vector = name + eql + vec
data=Combine(dmark+name)+SkipTo(end_data)+end_data
section=Forward()
sect_def=(sect | tag_sect ) #| vec_sect)
input=section | data | vector | keyword
section << sect_def+ZeroOrMore(input) + sect_end
# Parsing actions
ival.setParseAction(self.conv_ival)
dval.setParseAction(self.conv_dval)
lval.setParseAction(self.conv_lval)
keyword.setParseAction(self.store_key)
vector.setParseAction(self.store_vector)
data.setParseAction(self.store_data)
sect.setParseAction(self.add_sect)
tag_sect.setParseAction(self.add_sect)
sect_end.setParseAction(self.pop_sect)
bnf=ZeroOrMore(input) + StringEnd().setFailAction(parse_error)
bnf.ignore(pythonStyleComment)
return bnf
开发者ID:juselius,项目名称:libgetkw,代码行数:49,代码来源:getkw.py
示例9: receiver_input_rule
def receiver_input_rule():
path = Combine(ZeroOrMore(word + ".") + word)
input = path.setResultsName("input")
operator = oneOf(operators.keys()).setResultsName("operator")
value = path.setResultsName("value")
comparison = operator + value
is_or_was = Word("is") | Word("was")
condition = Group(input + is_or_was.setResultsName("temporal") + comparison)
res = ZeroOrMore(condition + _and) + condition
conditions = Group(res).setResultsName("conditions")
return Optional("always").setResultsName("always_fire_rule") + when + conditions + then + actions
开发者ID:abultman,项目名称:PiAutomator,代码行数:15,代码来源:RuleParser.py
示例10: parser
def parser():
global _parser
if _parser is None:
ParserElement.setDefaultWhitespaceChars("")
lbrack = Literal("[")
rbrack = Literal("]")
lbrace = Literal("{")
rbrace = Literal("}")
lparen = Literal("(")
rparen = Literal(")")
reMacro = Suppress("\\") + oneOf(list("dwsZ"))
escapedChar = ~reMacro + Combine("\\" + oneOf(list(printables)))
reLiteralChar = "".join(c for c in string.printable if c not in r"\[]{}().*?+|")
reRange = Combine(lbrack.suppress() + SkipTo(rbrack,ignore=escapedChar) + rbrack.suppress())
reLiteral = ( escapedChar | oneOf(list(reLiteralChar)) )
reDot = Literal(".")
repetition = (
( lbrace + Word(nums).setResultsName("count") + rbrace ) |
( lbrace + Word(nums).setResultsName("minCount")+","+ Word(nums).setResultsName("maxCount") + rbrace ) |
oneOf(list("*+?"))
)
reExpr = Forward()
reGroup = (lparen.suppress() +
Optional(Literal("?").suppress() + oneOf(list(":P"))).setResultsName("option") +
reExpr.setResultsName("expr") +
rparen.suppress())
reTerm = ( reLiteral | reRange | reMacro | reDot | reGroup )
reExpr << operatorPrecedence( reTerm,
[
(repetition, 1, opAssoc.LEFT, create(Repetition)),
(None, 2, opAssoc.LEFT, create(Sequence)),
(Suppress('|'), 2, opAssoc.LEFT, create(Alternation)),
]
)
reGroup.setParseAction(create(Group))
reRange.setParseAction(create(Range))
reLiteral.setParseAction(create(Character))
reMacro.setParseAction(create(Macro))
reDot.setParseAction(create(Dot))
_parser = reExpr
return _parser
开发者ID:GunioRobot,项目名称:pycucumber,代码行数:48,代码来源:regex_parser.py
示例11: getkw_bnf
def getkw_bnf(self):
sect_begin = Literal("{").suppress()
sect_end = Literal("}").suppress()
array_begin = Literal("[").suppress()
array_end = Literal("]").suppress()
arg_begin = Literal("(").suppress()
arg_end = Literal(")").suppress()
eql = Literal("=").suppress()
dmark = Literal('$').suppress()
end_data=Literal('$end').suppress()
prtable = alphanums+r'!$%&*+-./<>[email protected]^_|~'
# Helper definitions
kstr=Word(prtable) ^ quotedString.setParseAction(removeQuotes)
name = Word(alphas+"_",alphanums+"_")
vec=array_begin+delimitedList(Word(prtable) ^ \
Literal("\n").suppress() ^ \
quotedString.setParseAction(removeQuotes))+array_end
sect=name+sect_begin
key_sect=name+Group(arg_begin+kstr+arg_end)+sect_begin
vec_sect=name+Group(arg_begin+vec+ arg_end)+sect_begin
# Grammar
keyword = name + eql + kstr
vector = name + eql + vec
data=Combine(dmark+name)+SkipTo(end_data)+end_data
section=Forward()
sect_def=(sect | key_sect | vec_sect)
input=section | data | vector | keyword
section << sect_def+ZeroOrMore(input) + sect_end
# Parsing actions
keyword.setParseAction(self.store_key)
vector.setParseAction(self.store_vector)
data.setParseAction(self.store_data)
sect.setParseAction(self.add_sect)
key_sect.setParseAction(self.add_sect)
vec_sect.setParseAction(self.add_vecsect)
sect_end.setParseAction(self.pop_sect)
bnf=ZeroOrMore(input) + StringEnd().setFailAction(parse_error)
bnf.ignore(pythonStyleComment)
return bnf
开发者ID:juselius,项目名称:gimic,代码行数:44,代码来源:getkw.py
示例12: instance
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,代码行数:43,代码来源:grammar.py
示例13: _build_grammar
def _build_grammar(self):
expr = Forward()
float_lit = Combine(Word(nums) + '.' + Word(nums))
float_lit.setName('float')
float_lit.setParseAction(lambda x: \
self.to_literal(float(x[0])))
int_lit = Word(nums)
int_lit.setName('int')
int_lit.setParseAction(lambda x: \
self.to_literal(int(x[0])))
num = (float_lit | int_lit)
num.setParseAction(lambda x: x[0])
tag_name = Word(alphas + "_", alphanums + "_")
tag_name.setName('tag_name')
tag_name.setParseAction(lambda t: tag_reference.TagReference(t[0]))
quoted_string = QuotedString("'")
quoted_string.setParseAction(lambda s: self.to_literal(s[0]))
oper = oneOf('+ * / -')
oper.setParseAction(lambda o: o[0])
lpar = Literal("(").suppress()
rpar = Literal(")").suppress()
arith = Group(lpar + expr + oper + expr + rpar)
arith.setParseAction(lambda t: \
self.to_arith(t[0][0], t[0][1], t[0][2]))
assign = tag_name + '=' + expr
assign.setName('assign')
assign.setParseAction(lambda x: self.to_assign(x[0],x[2]))
print_tags = Literal('?')
print_tags.setParseAction(lambda x: self.to_print_tags())
expr <<(arith|assign|tag_name|num|quoted_string|print_tags)
expr.setParseAction(lambda x: x[0])
return expr
开发者ID:diegov,项目名称:retag,代码行数:43,代码来源:dsl_engine.py
示例14: _get_handbrake_title_pattern
def _get_handbrake_title_pattern(self):
title = Literal("+ title").suppress()
integer = Word("0123456789")
time = Combine(integer + ":" + integer + ":" + integer)
duration = Literal("+ duration:").suppress()
subtitle = Literal("+ subtitle tracks:")
iso = Literal('(iso639-2:').suppress() + Word(alphas)
subtitle_track = Literal("+").suppress() + Group(integer + SkipTo(iso).suppress() + iso) + restOfLine.suppress()
title_num = integer.setResultsName("title")
duration_num = time.setResultsName("duration")
subtitles = Group(ZeroOrMore(subtitle_track)).setResultsName("subtitles")
pattern = title + title_num + \
SkipTo(duration).suppress() + \
duration + duration_num + \
SkipTo(subtitle).suppress() + subtitle.suppress() + subtitles
return pattern
开发者ID:jeffreyparker,项目名称:brakejob,代码行数:19,代码来源:brakejob.py
示例15: pattern
def pattern():
"""pyparsing pattern
"""
def attachLocation(s, loc, tocs):
"""pyparsing callback. Saves path position in the original string
"""
return [(loc, tocs[0])]
path = CharsNotIn(" \t")("path")
path.setParseAction(attachLocation)
longPath = CharsNotIn(" \t", min=2)("path")
longPath.setParseAction(attachLocation)
slashPath = Combine(Literal('/') + Optional(CharsNotIn(" \t")))("path")
slashPath.setParseAction(attachLocation)
pat = ((Literal('f ') + Optional(White()) + Optional(path)) ^ longPath ^ slashPath) + \
Optional(White() + Word(nums)("line"))
pat.leaveWhitespace()
pat.setParseAction(CommandOpen.create)
return pat
开发者ID:hlamer,项目名称:completer,代码行数:21,代码来源:workspace_commands.py
示例16: parser
def parser():
global _parser
if _parser is None:
ParserElement.setDefaultWhitespaceChars("")
lbrack, rbrack, lbrace, rbrace, lparen, rparen = map(Literal, "[]{}()")
reMacro = Combine("\\" + oneOf(list("dws")))
escapedChar = ~ reMacro + Combine("\\" + oneOf(list(printables)))
reLiteralChar = "".join(c for c in printables if c not in r"\[]{}().*?+|") + " \t"
reRange = Combine(lbrack + SkipTo(rbrack, ignore=escapedChar) + rbrack)
reLiteral = (escapedChar | oneOf(list(reLiteralChar)))
reDot = Literal(".")
repetition = (
(lbrace + Word(nums).setResultsName("count") + rbrace) |
(lbrace + Word(nums).setResultsName("minCount") + "," + Word(nums).setResultsName("maxCount") + rbrace) |
oneOf(list("*+?"))
)
reRange.setParseAction(handle_range)
reLiteral.setParseAction(handle_literal)
reMacro.setParseAction(handle_macro)
reDot.setParseAction(handle_dot)
reTerm = (reLiteral | reRange | reMacro | reDot)
reExpr = operatorPrecedence(reTerm, [
(repetition, 1, opAssoc.LEFT, handle_repetition),
(None, 2, opAssoc.LEFT, handle_sequence),
(Suppress('|'), 2, opAssoc.LEFT, handle_alternative),
])
_parser = reExpr
return _parser
开发者ID:Bernie,项目名称:spyne,代码行数:34,代码来源:invregexp.py
示例17: 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 = Combine( 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:meastim,项目名称:ajaxlogsbrowser,代码行数:24,代码来源:apachehttpd_log2pg.py
示例18: _define_grammar
def _define_grammar(self):
'''define the grammar to be used, and add actions'''
self._define_actions()
eol = LineEnd().suppress()
white = Optional(White()).suppress()
begin = Keyword('begin').suppress()
end = Keyword('end').suppress()
comment = (Literal('#') + restOfLine).suppress()
data_value = Combine(OneOrMore(CharsNotIn('#\n\r')))
data_line = (LineStart() + white + Optional(data_value) +
Optional(comment) + eol)
block_name = Word(alphas, alphanums + '_')
begin_block = (LineStart() + begin + block_name +
Optional(comment) + eol)
end_block = LineStart() + end + block_name + Optional(comment) + eol
junk = ZeroOrMore(LineStart() + white + NotAny(begin) +
restOfLine + eol).suppress()
data = Group(ZeroOrMore(NotAny(end) + data_line))
block_def = begin_block + data + end_block
block_defs = junk + OneOrMore(block_def + junk)
self._grammar = block_defs
begin_block.addParseAction(self._begin_block_action)
end_block.addParseAction(self._end_block_action)
data_value.addParseAction(self._data_value_action)
开发者ID:bizatheo,项目名称:training-material,代码行数:24,代码来源:pyparsing_block_parser.py
示例19: urlsplit
def urlsplit(url, scheme='', allow_fragments=1):
"""Parse a URL into 5 components:
<scheme>://<netloc>/<path>?<query>#<fragment>
Return a 5-tuple: (scheme, netloc, path, query, fragment).
Note that we don't break the components up in smaller bits
(e.g. netloc is a single string) and we don't expand % escapes."""
global _urlBNF
key = url, scheme, allow_fragments
cached = _parse_cache.get(key, None)
if cached:
return cached
if len(_parse_cache) >= MAX_CACHE_SIZE: # avoid runaway growth
clear_cache()
if (_urlBNF is None):
scheme_chars = alphanums + "+-."
urlscheme = Word( scheme_chars )
netloc_chars = "".join( [ c for c in printables if c not in "/." ] )
netloc = Combine(delimitedList( Word( netloc_chars ), ".", combine=True ))
path_chars = "".join( [ c for c in printables if c not in "?" ] )
path = Word( path_chars )
query_chars = "".join( [ c for c in printables if c not in "#" ] )
query = Word( query_chars )
fragment = Word( printables+" " )
_urlBNF = Combine(Optional(urlscheme.setResultsName("scheme") + ":" ) +
Optional(Literal("//").suppress() + netloc, default="").setResultsName("netloc") +
Optional(path.setResultsName("path"), default="") +
Optional(Literal("?").suppress() + query, default="").setResultsName("query") +
Optional(Literal("#").suppress() + fragment, default="").setResultsName("fragment") )
tokens = _urlBNF.parseString( url )
tuple = (tokens.scheme or scheme), tokens.netloc[0], tokens.path, tokens.query[0], tokens.fragment[0]
_parse_cache[key] = tuple
return tuple
开发者ID:La-Lojban,项目名称:Lojban-Translator,代码行数:36,代码来源:pyparsing_test.py
示例20: grammar
def grammar(self):
number = Combine(Word(nums) + Optional("." + OneOrMore(Word(nums))))
table = Combine(Word(alphas) + OneOrMore(Word("_"+alphanums)))
number.setParseAction(self._number_parse_action)
table.setParseAction(self._table_parse_action)
signop = oneOf('+ -')
multop = oneOf('* /')
plusop = oneOf('+ -')
operand = number | table
return operatorPrecedence(operand, [
(signop, 1, opAssoc.RIGHT),
(multop, 2, opAssoc.LEFT),
(plusop, 2, opAssoc.LEFT)
])
开发者ID:peterlandry,项目名称:django-census,代码行数:18,代码来源:parse.py
注:本文中的pyparsing.Combine类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论