本文整理汇总了Python中pyparsing.alphanums方法的典型用法代码示例。如果您正苦于以下问题:Python pyparsing.alphanums方法的具体用法?Python pyparsing.alphanums怎么用?Python pyparsing.alphanums使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyparsing
的用法示例。
在下文中一共展示了pyparsing.alphanums方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: parse
# 需要导入模块: import pyparsing [as 别名]
# 或者: from pyparsing import alphanums [as 别名]
def parse(input_string):
word = Word(alphanums)
command = Group(OneOrMore(word))
token = Suppress("->")
device = Group(OneOrMore(word))
argument = Group(OneOrMore(word))
event = command + token + device + Optional(token + argument)
parse_results = event.parseString(input_string)
cmd = parse_results[0]
dev = parse_results[1]
cmd_str = "_".join(cmd)
dev_str = "_".join(dev)
try:
val = parse_results[2]
except IndexError:
val_str = None
else:
val_str = "_".join(val)
return cmd_str, dev_str, val_str
示例2: grammar
# 需要导入模块: import pyparsing [as 别名]
# 或者: from pyparsing import alphanums [as 别名]
def grammar():
parenthesis = Forward()
parenthesis <<= "(" + ZeroOrMore(CharsNotIn("()") | parenthesis) + ")"
field_def = OneOrMore(Word(alphanums + "_\"'`:-") | parenthesis)
field_def.setParseAction(field_act)
tablename_def = ( Word(alphas + "`_") | QuotedString("\"") )
field_list_def = field_def + ZeroOrMore(Suppress(",") + field_def)
field_list_def.setParseAction(field_list_act)
create_table_def = Literal("CREATE") + "TABLE" + tablename_def.setResultsName("tableName") + "(" + field_list_def.setResultsName("fields") + ")" + ";"
create_table_def.setParseAction(create_table_act)
add_fkey_def = Literal("FOREIGN") + "KEY" + "(" + Word(alphanums).setResultsName("keyName") + ")" + "REFERENCES" + Word(alphanums).setResultsName("fkTable") + "(" + Word(alphanums + "_").setResultsName("fkCol") + ")" + Optional(Literal("DEFERRABLE")) + ";"
add_fkey_def.setParseAction(add_fkey_act)
other_statement_def = OneOrMore(CharsNotIn(";")) + ";"
other_statement_def.setParseAction(other_statement_act)
comment_def = "--" + ZeroOrMore(CharsNotIn("\n"))
comment_def.setParseAction(other_statement_act)
return OneOrMore(comment_def | create_table_def | add_fkey_def | other_statement_def)
示例3: parse
# 需要导入模块: import pyparsing [as 别名]
# 或者: from pyparsing import alphanums [as 别名]
def parse(self, flags):
_flags = []
for k, v in flags.items():
if v == True:
_flags.append(k)
elif v in [False, None]:
pass
else:
_flags.append(k + "_" + v)
def cb_conditional(s, l, t):
if (t.cond in _flags) != (t.negate == "!"):
return t.expr
else:
return []
word = Word(alphanums + ":<>.[]_-,=~/^~")
conditional = Forward()
conditional << (
Optional("!")("negate")
+ word("cond")
+ Suppress("?")
+ Suppress("(")
+ OneOrMore(conditional ^ word)("expr")
+ Suppress(")")
).setParseAction(cb_conditional)
string = word
string_list = OneOrMore(conditional ^ string)
s = " ".join(string_list.parseString(self.__str__()))
logger.debug(
"Parsing '{}' with flags {} => {}".format(self.__str__(), str(_flags), s)
)
return s
示例4: static_function
# 需要导入模块: import pyparsing [as 别名]
# 或者: from pyparsing import alphanums [as 别名]
def static_function(self):
return (
(pyparsing.Keyword("static") | pyparsing.Keyword("inline"))
+ pyparsing.OneOrMore(pyparsing.Word(pyparsing.alphanums + "_*&"))
+ parsers.anything_in_parentheses()
+ parsers.anything_in_curly()
).suppress()
示例5: _cast_transformer
# 需要导入模块: import pyparsing [as 别名]
# 或者: from pyparsing import alphanums [as 别名]
def _cast_transformer(self):
"""Removes obvious casts."""
return pyparsing.Combine(
pyparsing.Regex(r"\([^()]*\)").suppress()
+ (pyparsing.Word(pyparsing.alphanums + "_")
| pyparsing.Literal("(")),
adjacent=False)
示例6: _type_property
# 需要导入模块: import pyparsing [as 别名]
# 或者: from pyparsing import alphanums [as 别名]
def _type_property(self):
return (
_TYPE_PROPERTY_KEYWORD
+ _OPEN_PARENTHESIS
+ pyparsing.Word(pyparsing.alphanums + ' _*[]')
+ _CLOSE_PARENTHESIS
).setParseAction(self._create_sizeof_type)
示例7: XXXX_cast_expression
# 需要导入模块: import pyparsing [as 别名]
# 或者: from pyparsing import alphanums [as 别名]
def XXXX_cast_expression(self):
"""A function returning a parser for parsing cast expressions.
Args:
expression: a pyparsing parser for parsing an expression to be cast.
Returns:
A (pyparsing) parser for parsing cast expressions.
"""
word = pyparsing.Word(pyparsing.alphanums + '_*[]')
nested = pyparsing.Forward().setName("nested")
nested << pyparsing.Combine(
pyparsing.Literal('(').suppress()
+ pyparsing.Combine(
pyparsing.ZeroOrMore(self._integer() | word | nested))
+ pyparsing.Literal(')').suppress()
)
typeof_expression = (
_OPEN_PARENTHESIS
+ pyparsing.Keyword('typeof')
+ nested("typeof_arg")
+ _CLOSE_PARENTHESIS
)
type_expression = (
typeof_expression
| nested("simple_type")
)
return (
type_expression
+ ~(_PLUS | _MINUS)
+ self.expression("expression")
).setParseAction(self._create_cast_expression)
示例8: _identifier_with_dots
# 需要导入模块: import pyparsing [as 别名]
# 或者: from pyparsing import alphanums [as 别名]
def _identifier_with_dots(self):
return pyparsing.Word(
pyparsing.alphas + '_.', pyparsing.alphanums + '_.')
示例9: identifier
# 需要导入模块: import pyparsing [as 别名]
# 或者: from pyparsing import alphanums [as 别名]
def identifier():
return pyparsing.Word(pyparsing.alphas + '_', pyparsing.alphanums + '_')
示例10: __init__
# 需要导入模块: import pyparsing [as 别名]
# 或者: from pyparsing import alphanums [as 别名]
def __init__(self):
# create parsing grammer
sQStringLiteral = pyparsing.QuotedString("'")
sQStringLiteral.setParseAction(
lambda s, loc, toks: StringLiteral(s, loc, toks, False))
dQStringLiteral = pyparsing.QuotedString('"', '\\')
dQStringLiteral.setParseAction(
lambda s, loc, toks: StringLiteral(s, loc, toks, True))
stringLiteral = sQStringLiteral | dQStringLiteral
functionCall = pyparsing.Forward()
functionArg = stringLiteral | functionCall
functionCall << pyparsing.Word(pyparsing.alphas, pyparsing.alphanums+'-') + \
pyparsing.Suppress('(') + \
pyparsing.Optional(functionArg +
pyparsing.ZeroOrMore(pyparsing.Suppress(',') + functionArg)) + \
pyparsing.Suppress(')')
functionCall.setParseAction(
lambda s, loc, toks: FunctionCall(s, loc, toks))
predExpr = pyparsing.infixNotation(
stringLiteral ^ functionCall ,
[
('!', 1, pyparsing.opAssoc.RIGHT, lambda s, loc, toks: NotOperator(s, loc, toks)),
('<', 2, pyparsing.opAssoc.LEFT, infixBinaryOp(BinaryStrOperator)),
('<=', 2, pyparsing.opAssoc.LEFT, infixBinaryOp(BinaryStrOperator)),
('>', 2, pyparsing.opAssoc.LEFT, infixBinaryOp(BinaryStrOperator)),
('>=', 2, pyparsing.opAssoc.LEFT, infixBinaryOp(BinaryStrOperator)),
('==', 2, pyparsing.opAssoc.LEFT, infixBinaryOp(BinaryStrOperator)),
('!=', 2, pyparsing.opAssoc.LEFT, infixBinaryOp(BinaryStrOperator)),
('&&', 2, pyparsing.opAssoc.LEFT, infixBinaryOp(BinaryBoolOperator)),
('||', 2, pyparsing.opAssoc.LEFT, infixBinaryOp(BinaryBoolOperator))
])
self.__ifgrammer = predExpr
示例11: __parse_tc_filter_network
# 需要导入模块: import pyparsing [as 别名]
# 或者: from pyparsing import alphanums [as 别名]
def __parse_tc_filter_network(text):
network_pattern = pp.SkipTo("{:s}=".format(Tc.Param.DST_NETWORK), include=True) + pp.Word(
pp.alphanums + "." + "/"
)
return network_pattern.parseString(text)[-1]
示例12: __init__
# 需要导入模块: import pyparsing [as 别名]
# 或者: from pyparsing import alphanums [as 别名]
def __init__(self):
if PYPARSING:
category = Word(alphas + "_-*", alphanums + "_-*")
operator = oneOf("and or ,")
neg_operator = "not"
elementRef = category
definition = elementRef + ZeroOrMore(operator + elementRef)
nestedformula = Group(Suppress(Optional(Literal("("))) + definition + Suppress(Optional(Literal(")"))))
neg_nestedformula = Optional(neg_operator) + nestedformula
self.finalformula = neg_nestedformula + ZeroOrMore(operator + neg_nestedformula)
elementRef.setParseAction(self.__compute_element)
neg_nestedformula.setParseAction(self.__compute_neg_formula)
nestedformula.setParseAction(self.__compute_formula)
self.finalformula.setParseAction(self.__myreduce)
示例13: getchunk
# 需要导入模块: import pyparsing [as 别名]
# 或者: from pyparsing import alphanums [as 别名]
def getchunk():
"""
Using pyparsing, create chunk reader for chunk strings.
"""
slot = pp.Word("".join([pp.alphas, "_"]), "".join([pp.alphanums, "_"]))
special_value = pp.Group(pp.oneOf([ACTRVARIABLE, "".join([ACTRNEG, ACTRVARIABLE]), ACTRNEG, VISIONGREATER, VISIONSMALLER, "".join([VISIONGREATER, ACTRVARIABLE]), "".join([VISIONSMALLER, ACTRVARIABLE])])\
+ pp.Word("".join([pp.alphanums, "_", '"', "'"])))
strvalue = pp.QuotedString('"', unquoteResults=False)
strvalue2 = pp.QuotedString("'", unquoteResults=False)
varvalue = pp.Word("".join([pp.alphanums, "_"]))
value = varvalue | special_value | strvalue | strvalue2
chunk_reader = pp.OneOrMore(pp.Group(slot + value))
return chunk_reader
示例14: getrule
# 需要导入模块: import pyparsing [as 别名]
# 或者: from pyparsing import alphanums [as 别名]
def getrule():
"""
Using pyparsing, get rule out of a string.
"""
arrow = pp.Literal("==>")
buff = pp.Word(pp.alphas, "".join([pp.alphanums, "_"]))
special_valueLHS = pp.oneOf([x for x in _LHSCONVENTIONS.keys()])
end_buffer = pp.Literal(">")
special_valueRHS = pp.oneOf([x for x in _RHSCONVENTIONS.keys()])
chunk = getchunk()
rule_reader = pp.Group(pp.OneOrMore(pp.Group(special_valueLHS + buff + end_buffer + pp.Group(pp.Optional(chunk))))) + arrow + pp.Group(pp.OneOrMore(pp.Group(special_valueRHS + buff + end_buffer + pp.Group(pp.Optional(chunk)))))
return rule_reader
示例15: parser
# 需要导入模块: import pyparsing [as 别名]
# 或者: from pyparsing import alphanums [as 别名]
def parser(self):
"""
This function returns a parser.
The grammar should be like most full text search engines (Google, Tsearch, Lucene).
Grammar:
- a query consists of alphanumeric words, with an optional '*' wildcard
at the end of a word
- a sequence of words between quotes is a literal string
- words can be used together by using operators ('and' or 'or')
- words with operators can be grouped with parenthesis
- a word or group of words can be preceded by a 'not' operator
- the 'and' operator precedes an 'or' operator
- if an operator is missing, use an 'and' operator
"""
operatorOr = Forward()
operatorWord = Group(Combine(Word(alphanums) + Suppress('*'))).setResultsName('wordwildcard') | \
Group(Word(alphanums)).setResultsName('word')
operatorQuotesContent = Forward()
operatorQuotesContent << (
(operatorWord + operatorQuotesContent) | operatorWord
)
operatorQuotes = Group(
Suppress('"') + operatorQuotesContent + Suppress('"')
).setResultsName("quotes") | operatorWord
operatorParenthesis = Group(
(Suppress("(") + operatorOr + Suppress(")"))
).setResultsName("parenthesis") | operatorQuotes
operatorNot = Forward()
operatorNot << (Group(
Suppress(Keyword("not", caseless=True)) + operatorNot
).setResultsName("not") | operatorParenthesis)
operatorAnd = Forward()
operatorAnd << (Group(
operatorNot + Suppress(Keyword("and", caseless=True)) + operatorAnd
).setResultsName("and") | Group(
operatorNot + OneOrMore(~oneOf("and or") + operatorAnd)
).setResultsName("and") | operatorNot)
operatorOr << (Group(
operatorAnd + Suppress(Keyword("or", caseless=True)) + operatorOr
).setResultsName("or") | operatorAnd)
return operatorOr.parseString