本文整理汇总了Python中pyparsing.Keyword.suppress方法的典型用法代码示例。如果您正苦于以下问题:Python Keyword.suppress方法的具体用法?Python Keyword.suppress怎么用?Python Keyword.suppress使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyparsing.Keyword
的用法示例。
在下文中一共展示了Keyword.suppress方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _create_filter_parser
# 需要导入模块: from pyparsing import Keyword [as 别名]
# 或者: from pyparsing.Keyword import suppress [as 别名]
def _create_filter_parser():
and_kw = Keyword('AND')
or_kw = Keyword('OR')
variable = Literal('?') + Word(alphanums + '_').leaveWhitespace()
uri_term = NotAny(Literal('"')) + Word(printables, excludeChars='>*')
uri_part = Keyword('*') ^ uri_term ^ variable
literal_term = QuotedString(quoteChar='"', escChar='\\')
triple = Group(Literal('<').suppress() + uri_part.setResultsName('subj')
+ uri_part.setResultsName('pred')
+ (Group(uri_part).setResultsName('obj')
^ Group(literal_term).setResultsName('objlit'))
+ Literal('>').suppress())
expr = Forward()
atom = (triple.setResultsName('triple')
| Literal('(').suppress() + expr + Literal(')').suppress())
and_group = Group(atom + ZeroOrMore(and_kw.suppress() + atom))
or_group = Group(atom + ZeroOrMore(or_kw.suppress() + atom))
expr << (and_group.setResultsName('and') ^ or_group.setResultsName('or'))
return expr
示例2: SPICE_BNF
# 需要导入模块: from pyparsing import Keyword [as 别名]
# 或者: from pyparsing.Keyword import suppress [as 别名]
def SPICE_BNF():
global bnf
if not bnf:
# punctuation
colon = Literal(":").suppress()
lbrace = Literal("{").suppress()
rbrace = Literal("}").suppress()
lbrack = Literal("[").suppress()
rbrack = Literal("]").suppress()
lparen = Literal("(").suppress()
rparen = Literal(")").suppress()
equals = Literal("=").suppress()
comma = Literal(",").suppress()
semi = Literal(";").suppress()
# primitive types
int8_ = Keyword("int8").setParseAction(replaceWith(ptypes.int8))
uint8_ = Keyword("uint8").setParseAction(replaceWith(ptypes.uint8))
int16_ = Keyword("int16").setParseAction(replaceWith(ptypes.int16))
uint16_ = Keyword("uint16").setParseAction(replaceWith(ptypes.uint16))
int32_ = Keyword("int32").setParseAction(replaceWith(ptypes.int32))
uint32_ = Keyword("uint32").setParseAction(replaceWith(ptypes.uint32))
int64_ = Keyword("int64").setParseAction(replaceWith(ptypes.int64))
uint64_ = Keyword("uint64").setParseAction(replaceWith(ptypes.uint64))
# keywords
enum32_ = Keyword("enum32").setParseAction(replaceWith(32))
enum16_ = Keyword("enum16").setParseAction(replaceWith(16))
enum8_ = Keyword("enum8").setParseAction(replaceWith(8))
flags32_ = Keyword("flags32").setParseAction(replaceWith(32))
flags16_ = Keyword("flags16").setParseAction(replaceWith(16))
flags8_ = Keyword("flags8").setParseAction(replaceWith(8))
channel_ = Keyword("channel")
server_ = Keyword("server")
client_ = Keyword("client")
protocol_ = Keyword("protocol")
typedef_ = Keyword("typedef")
struct_ = Keyword("struct")
message_ = Keyword("message")
image_size_ = Keyword("image_size")
bytes_ = Keyword("bytes")
cstring_ = Keyword("cstring")
switch_ = Keyword("switch")
default_ = Keyword("default")
case_ = Keyword("case")
identifier = Word(alphas, alphanums + "_")
enumname = Word(alphanums + "_")
integer = (
(Combine(CaselessLiteral("0x") + Word(nums + "abcdefABCDEF")) | Word(nums + "+-", nums))
.setName("int")
.setParseAction(cvtInt)
)
typename = identifier.copy().setParseAction(lambda toks: ptypes.TypeRef(str(toks[0])))
# This is just normal "types", i.e. not channels or messages
typeSpec = Forward()
attributeValue = integer ^ identifier
attribute = Group(Combine("@" + identifier) + Optional(lparen + delimitedList(attributeValue) + rparen))
attributes = Group(ZeroOrMore(attribute))
arraySizeSpecImage = Group(image_size_ + lparen + integer + comma + identifier + comma + identifier + rparen)
arraySizeSpecBytes = Group(bytes_ + lparen + identifier + comma + identifier + rparen)
arraySizeSpecCString = Group(cstring_ + lparen + rparen)
arraySizeSpec = (
lbrack
+ Optional(
identifier ^ integer ^ arraySizeSpecImage ^ arraySizeSpecBytes ^ arraySizeSpecCString, default=""
)
+ rbrack
)
variableDef = Group(
typeSpec
+ Optional("*", default=None)
+ identifier
+ Optional(arraySizeSpec, default=None)
+ attributes
- semi
).setParseAction(parseVariableDef)
switchCase = Group(
Group(
OneOrMore(
default_.setParseAction(replaceWith(None)) + colon
| Group(case_.suppress() + Optional("!", default="") + identifier) + colon
)
)
+ variableDef
).setParseAction(lambda toks: ptypes.SwitchCase(toks[0][0], toks[0][1]))
switchBody = Group(
switch_
+ lparen
+ delimitedList(identifier, delim=".", combine=True)
+ rparen
+ lbrace
+ Group(OneOrMore(switchCase))
#.........这里部分代码省略.........
示例3: Dict
# 需要导入模块: from pyparsing import Keyword [as 别名]
# 或者: from pyparsing.Keyword import suppress [as 别名]
tokens[1] = date_time
del tokens[2]
TIMESTAMP = quote + POSITIVE_NUMBER + quote
TIMESTAMP.setParseAction(parseTimestamp)
UTC_FLAG = Dict(
Group(
(
int_ + Keyword('inUtc') + equals + UINT_VALUE
).setParseAction(parseFlag)
)
)
COMPOSED_DATE = (
date.suppress() + lcurly +
int_ + day.suppress() + equals + UINT_VALUE +
int_ + month.suppress() + equals + UINT_VALUE +
int_ + year.suppress() + equals + UINT_VALUE +
rcurly + Optional(COMMENT)
)
COMPOSED_DATE.setParseAction(parseDate)
COMPOSED_TIME = (
time.suppress() + lcurly +
int_ + hour.suppress() + equals + UINT_VALUE +
int_ + min_.suppress() + equals + UINT_VALUE +
int_ + sec.suppress() + equals + UINT_VALUE +
rcurly + Optional(COMMENT)
)
COMPOSED_TIME.setParseAction(parseTime)
示例4: Keyword
# 需要导入模块: from pyparsing import Keyword [as 别名]
# 或者: from pyparsing.Keyword import suppress [as 别名]
insert_kw = Keyword('insert', caseless=True)
into_kw = Keyword('into', caseless=True)
# define sql reserved words
reserved_words = (
update_kw | volatile_kw | create_kw | table_kw
| as_kw | from_kw | where_kw | join_kw | on_kw | left_kw
| right_kw | cross_kw | outer_kw | on_kw | insert_kw | into_kw
)
ident = ~reserved_words + Word(alphas, alphanums + '_$.').setName('identifier')
function = (
(Word(alphas) + '(' + Word(alphanums + '*_$.') + ')')
+ Optional(as_kw.suppress() + delimitedList(ident, '.', combine=True))
)
column_name = delimitedList(ident, '.', combine=True)
column_name_list = Group(delimitedList(column_name))
# To make it simple, enclode all expressions in parens.
expression = "(" + OneOrMore( Word(alphanums + '_-.') | Word('-+*')) + ")"
# column from the select statement with `as` keyword support.
# the quoted string handles cases like : SELECT 'CA' AS state
select_column = (
( delimitedList(ident, '.', combine=True).setResultsName('parsed_name') | quotedString | expression )
+ Optional(as_kw.suppress() + delimitedList(ident, '.', combine=True)).setResultsName('parsed_alias')
).setParseAction(_flat_alias)
示例5: DropGraph
# 需要导入模块: from pyparsing import Keyword [as 别名]
# 或者: from pyparsing.Keyword import suppress [as 别名]
lambda s, l, t: DropGraph(name=t.name))
describe_graph = (describe + graph).\
setParseAction(lambda s, l, t: DescribeGraph())
def vi(s,l,t):
return CreateVertexIndex(label=t.label,
name=t.index_name,
fields=t.fields,
type=t.type)
create_vertex_index = (create + index_type('type') + index + \
ident('index_name') +
on_ + vertex.suppress() + ident('label') +
lparen + delimitedList(ident, ",")('fields') + rparen).\
setParseAction(vi)
def cei(s, l, t):
return CreateEdgeIndex(direction=t.direction.upper(),
name=t.name,
edge=t.edge,
vertex=t.vertex,
property=t.property)
create_edge_index = (create + direction("direction") + index +
ident('name') +
on_ + vertex + ident('vertex') +
on_ + edge + ident('edge') +