本文整理匯總了Python中pyparsing.Keyword.setResultsName方法的典型用法代碼示例。如果您正苦於以下問題:Python Keyword.setResultsName方法的具體用法?Python Keyword.setResultsName怎麽用?Python Keyword.setResultsName使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類pyparsing.Keyword
的用法示例。
在下文中一共展示了Keyword.setResultsName方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: _create_filter_parser
# 需要導入模塊: from pyparsing import Keyword [as 別名]
# 或者: from pyparsing.Keyword import setResultsName [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: create_grammar
# 需要導入模塊: from pyparsing import Keyword [as 別名]
# 或者: from pyparsing.Keyword import setResultsName [as 別名]
def create_grammar():
global arrows
global stereotypes
assert len(arrows) > 0
assert len(stereotypes) > 0
linechars = ''.join((c for c in printables if c not in '}\n')) + ' \t'
norbracket = ''.join((c for c in printables if c != ']')) + ' \t'
nogt = ''.join((c for c in printables if c != '>')) + ' \t'
norparen = ''.join((c for c in printables if c != ')')) + ' \t'
line = Word(linechars)
cls_body = Group(ZeroOrMore(line))
classkeyword = Keyword('class').setResultsName('type')
st_names = stereotypes.keys()
st = Literal(st_names[0])
for s in st_names[1:]:
st = st | Literal(s)
stereotype = Group(Optional(Literal('<<').suppress() + st + Literal('>>').suppress()))
identifier_list = Word(alphas) + ZeroOrMore(Literal(',').suppress() + Word(alphas))
baseclasses = Group(Optional(Literal(':').suppress() + identifier_list))
cls = Group(stereotype + classkeyword + Word(alphas) + baseclasses + \
Literal('{').suppress() + cls_body + Literal('}').suppress())
arrow_names = arrows.keys()
arrow_names.sort(lambda x,y: -cmp(len(x), len(y)))
arrow = Keyword(arrow_names[0])
for ar in arrow_names[1:]:
arrow = arrow | Keyword(ar)
relation_caption = Literal('(').suppress() + Word(norparen) + \
Literal(')').suppress()
quantifier = Literal('[').suppress() + Word(norbracket) + Literal(']').suppress()
relation = Group(
Word(alphas) + Group(Optional(quantifier)) + \
arrow.setResultsName('type') + \
Word(alphas) + Group(Optional(quantifier)) + \
Group(Optional(relation_caption))
)
grammar = ZeroOrMore(cls | relation)
grammar.ignore(cStyleComment)
grammar.ignore("//" + restOfLine)
return grammar
示例3: Suppress
# 需要導入模塊: from pyparsing import Keyword [as 別名]
# 或者: from pyparsing.Keyword import setResultsName [as 別名]
tok_sql_op | Suppress(",")) + Suppress(")")
tok_sql_loose_val = \
((Suppress("(") + sql_select + Suppress(")") + \
tok_sql_literal_as + tok_sql_identifier) | tok_sql_func_call | \
tok_sql_identifier | tok_sql_quoted_value | \
tok_sql_computed_value)
tok_sql_kvp = tok_sql_identifier + tok_sql_op + tok_sql_loose_val
tok_sql_cols = delimitedList(tok_sql_identifier)
tok_sql_table_list = delimitedList(tok_sql_table_alias)
tok_sql_vals = delimitedList(tok_sql_loose_val)
tok_sql_kvp_list = delimitedList(tok_sql_kvp)
tok_sql_where_clause = \
(tok_sql_kvp)
sql_select << (tok_sql_literal_select.setResultsName("op") + \
Optional(tok_sql_inline_comment) + \
(Literal("*") | delimitedList(tok_sql_loose_val)).\
setResultsName("column_list") + \
tok_sql_literal_from + \
tok_sql_table_list.setResultsName("table_list") + \
Optional(tok_sql_literal_where + \
tok_sql_where_clause.\
setResultsName("where_clause")) + \
Optional(tok_sql_literal_group + \
Suppress(tok_sql_literal_by) + \
tok_sql_cols.setResultsName("groupby_clause") + \
Optional(tok_sql_literal_having +
tok_sql_kvp_list.\
setResultsName("having_clause"))))
示例4: Forward
# 需要導入模塊: from pyparsing import Keyword [as 別名]
# 或者: from pyparsing.Keyword import setResultsName [as 別名]
[
(oneOf("+ -"), 1, opAssoc.RIGHT, FOLUnOp),
(oneOf("^"), 2, opAssoc.LEFT, FOLBinOp),
(oneOf("* /"), 2, opAssoc.LEFT, FOLBinOp),
(oneOf("+ -"), 2, opAssoc.LEFT, FOLBinOp),
(oneOf("< <= > >= "), 2, opAssoc.LEFT, FOLBinOp),
],
)
# main parser for FOL formula
formula = Forward()
formula.ignore(comment)
forall_expression = Group(
forall.setResultsName("quantifier")
+ delimitedList(variable).setResultsName("vars")
+ colon
+ formula.setResultsName("args")
).setParseAction(FOLQuant)
exists_expression = Group(
exists.setResultsName("quantifier")
+ delimitedList(variable).setResultsName("vars")
+ colon
+ formula.setResultsName("args")
).setParseAction(FOLQuant)
operand = forall_expression | exists_expression | boolean | term
# specify the precedence -- highest precedence first, lowest last
operator_list = [(not_, 1, opAssoc.RIGHT, FOLUnOp)]
示例5: oneOf
# 需要導入模塊: from pyparsing import Keyword [as 別名]
# 或者: from pyparsing.Keyword import setResultsName [as 別名]
# basic where clause
simpleWhereClause = (
where_
+ oneOf(
" ".join([eventFields, instanceFields, signalFields, timex3Fields, tlinkFields, slinkFields, alinkFields])
).setResultsName("conditionField")
+ (
is_ + Optional(not_.setResultsName("not_")) + alphaNums_.setResultsName("conditionValue")
| state_ + is_ + Optional(not_.setResultsName("not_")) + state.setResultsName("state")
)
)
# top-level statement definition
cavatStmt << (
helpToken.setResultsName("action") + Optional(OneOrMore(alphaNums_).setResultsName("query"))
| showToken.setResultsName("action")
+ reportType.setResultsName("report")
+ of_
+ (
tag.setResultsName("tag")
+ tlinkPositionedArg.setResultsName("start")
+ tlinkPositionedArg.setResultsName("end")
+ distance_.setResultsName("distance")
+ Optional(in_ + distanceUnits.setResultsName("units"))
| fieldName.setResultsName("result") + Optional(simpleWhereClause.setResultsName("condition"))
)
+ Optional(as_ + outputFormat.setResultsName("format"))
| corpusToken.setResultsName("action")
+ (
import_.setResultsName("import_")
示例6: Optional
# 需要導入模塊: from pyparsing import Keyword [as 別名]
# 或者: from pyparsing.Keyword import setResultsName [as 別名]
Optional(Group('@' + Word(alphanums + '_-')).setResultsName('moleculeCompartment')))
species_definition = Group(Optional(Group('@' + Word(alphanums + '_')).setResultsName('speciesCompartment') + Suppress('::')) +
delimitedList(molecule_instance, delim='.').setResultsName('speciesPattern'))
reaction_definition = Group(Group(delimitedList(species_definition, delim='+')).setResultsName('reactants') + (uni_arrow | bi_arrow) +
Group(delimitedList(species_definition, delim='+')).setResultsName('products') +
Group(lbracket + (numarg | (identifier + Suppress(Optional('()')))) + Optional(comma + (numarg| (identifier + Suppress(Optional('()'))))) + rbracket).setResultsName('rate'))
# generic hash section grammar
hashed_section = (hashsymbol + Group(OneOrMore(name) + section_enclosure2_))
#hash system_constants
#system_constants = Group()
hashed_system_constants = Group(hashsymbol + Suppress(system_constants_) + lbrace + OneOrMore(statement) + rbrace)
# hash molecule_entry
diffusion_entry_ = Group((diffusion_constant_2d_.setResultsName('2D') | diffusion_constant_3d_.setResultsName('3D')) + Suppress(equal) + (function_entry_.setResultsName('function') | (identifier | numarg).setResultsName('variable')))
molecule_entry = Group(molecule_definition + Optional(Group(lbrace + Optional(diffusion_entry_.setResultsName('diffusionFunction')) + (ZeroOrMore(statement)).setResultsName('moleculeParameters') + rbrace)))
hashed_molecule_section = Group(hashsymbol + Suppress(define_molecules_) + lbrace + OneOrMore(molecule_entry) + rbrace)
#hash function entry
function_name = Group(identifier + '()')
math_function_entry = Group(function_name.setResultsName('functionName') + Suppress(equal) + Group(restOfLine).setResultsName('functionBody'))
hashed_function_section = Group(hashsymbol + Suppress(define_functions_) + lbrace + ZeroOrMore(math_function_entry) +rbrace)
# hash reaction entry
hashed_reaction_section = Group(hashsymbol + Suppress(define_reactions_) + lbrace + OneOrMore(reaction_definition) + rbrace)
# hash observable entry
count_definition = Group(count_ + lbracket + species_definition.setResultsName('speciesPattern') + Suppress(',') + identifier + rbracket)
observable_entry = Group(lbrace + Group(delimitedList(count_definition, delim='+')).setResultsName('patterns') + rbrace + Suppress('=>') + quotedString.setResultsName('outputfile'))
示例7: __init__
# 需要導入模塊: from pyparsing import Keyword [as 別名]
# 或者: from pyparsing.Keyword import setResultsName [as 別名]
def __init__(self):
intNum = Word(nums)
floatNum = Combine(intNum + Optional("." + intNum))
string = QuotedString("'") | QuotedString('"')
regex = QuotedString("/")
ident = Word( alphas, alphanums + "_" )
time_period = Keyword("minutes") | Keyword("seconds")
ordering = Keyword("unique") | Keyword("random")
string_type = Keyword("random").setResultsName("ordering") + \
Keyword("string").setResultsName("data_type") + \
Keyword("of") + Keyword("length") + \
intNum.setResultsName("length")
numeric_type = ordering.setResultsName("ordering") + \
Keyword("number").setResultsName("data_type") + Keyword("from") + \
floatNum.setResultsName("min") + Keyword("to") + \
floatNum.setResultsName("max")
var_type = string_type | numeric_type
var = Group(Keyword("var").setResultsName("type") + \
ident.setResultsName("name") + Keyword("is") + \
Keyword("a") + var_type)
ident_list = delimitedList( ident )
using_ordering = Keyword("randomly") | Keyword("sequentially")
using = Group(Keyword("using").setResultsName("type") + \
ident_list.setResultsName("vars") + Keyword("from") + \
string.setResultsName("filename") + \
using_ordering.setResultsName("ordering"))
pause = Group(Keyword("pause").setResultsName("type") + \
Keyword("between") + \
intNum.setResultsName("lower_time") + Keyword("and") + \
intNum.setResultsName("upper_time") + Keyword("seconds"))
get = Keyword("get").setResultsName("method")
post = Keyword("post").setResultsName("method")
put = Keyword("put").setResultsName("method")
delete = Keyword("delete").setResultsName("method")
method = (get | post | put | delete).setResultsName("type")
url = string.setResultsName("url")
data = Keyword("with") + Keyword("data") + \
string.setResultsName("data")
match = Group( \
Keyword("ensure") + Keyword("match") + \
regex.setResultsName("regex"))
match_list = Group(OneOrMore(match)).setResultsName("matches")
request = Group(method + \
Optional(Keyword("all")).setResultsName("all") + \
url + Optional(data) + Optional(match_list)).setName("request")
action = request | pause | var | using
action_list = \
Group(OneOrMore(action)).setResultsName("actions")
session = Group( Keyword("create") + \
Keyword("session") + Keyword("with") + \
Keyword("weight") + \
intNum.setResultsName("weight") + Keyword("as") + \
string.setResultsName("name") + \
":" + action_list)
session_list = OneOrMore(session).setResultsName("sessions")
spawn = Group( Keyword("spawn") + \
Keyword("users") + Keyword("every") + \
intNum.setResultsName("user_time") + \
time_period.setResultsName("user_time_units") + \
Keyword("for") + \
intNum.setResultsName("max_duration") + \
time_period.setResultsName("max_duration_units") + \
Optional( Keyword("up") + Keyword("to") + \
intNum.setResultsName("max_users") + Keyword("users")))
spawn_list = OneOrMore(spawn).setResultsName("spawns")
load = Group( Keyword("create") + Keyword("load") + ":" + \
spawn_list).setResultsName("load")
comment = "#" + restOfLine
script = session_list + load
script.ignore(comment)
self.grammar = script