本文整理汇总了Python中pyparsing.Word.setName方法的典型用法代码示例。如果您正苦于以下问题:Python Word.setName方法的具体用法?Python Word.setName怎么用?Python Word.setName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyparsing.Word
的用法示例。
在下文中一共展示了Word.setName方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _build_grammar
# 需要导入模块: from pyparsing import Word [as 别名]
# 或者: from pyparsing.Word import setName [as 别名]
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
示例2: parse
# 需要导入模块: from pyparsing import Word [as 别名]
# 或者: from pyparsing.Word import setName [as 别名]
def parse(self, string):
# An integer value
integer = Word(nums)
integer.setParseAction(Integer.parse)
integer.setName("integer")
# An expression in dice notation
expression = StringStart() + operatorPrecedence(integer, [
(CaselessLiteral('d').suppress(), 2, opAssoc.LEFT, Dice.parse_binary),
(CaselessLiteral('d').suppress(), 1, opAssoc.RIGHT, Dice.parse_unary),
(Literal('/').suppress(), 2, opAssoc.LEFT, Div.parse),
(Literal('*').suppress(), 2, opAssoc.LEFT, Mul.parse),
(Literal('-').suppress(), 2, opAssoc.LEFT, Sub.parse),
(Literal('+').suppress(), 2, opAssoc.LEFT, Add.parse),
(CaselessLiteral('t').suppress(), 1, opAssoc.LEFT, Total.parse),
(CaselessLiteral('s').suppress(), 1, opAssoc.LEFT, Sort.parse),
(Literal('^').suppress(), 2, opAssoc.LEFT, Keep.parse),
(Literal('v').suppress(), 2, opAssoc.LEFT, Drop.parse),
]) + StringEnd()
expression.setName("expression")
示例3: show
# 需要导入模块: from pyparsing import Word [as 别名]
# 或者: from pyparsing.Word import setName [as 别名]
ZeroOrMore, restOfLine
import raco
from raco import expression
import raco.datalog.model as model
def show(x):
print x
return x
drop = lambda x: Literal(x).suppress()
# define Datalog tokens
ident = Word(alphas, alphanums + "_$")
predicate = ident.setName("Predicate")
E = CaselessLiteral("E")
# Get all the aggregate expression classes
aggregate_functions = raco.expression.aggregate_functions()
# All binary operators
binopclasses = expression.binary_ops()
# a list of string literals representing opcodes
opcodes = sum([oc.literals for oc in binopclasses], [])
binopstr = " ".join(opcodes)
示例4: Word
# 需要导入模块: from pyparsing import Word [as 别名]
# 或者: from pyparsing.Word import setName [as 别名]
# Set the parse action for the operator
if action is not None:
operator_expression.setParseAction(action)
this <<= operator_expression | last
last = this
# Set the full expression and return it
expression <<= last
return expression
# An integer value
integer = Word(nums)
integer.setParseAction(Integer.parse)
integer.setName("integer")
# An expression in dice notation
expression = (
StringStart()
+ operatorPrecedence(
integer,
[
(CaselessLiteral("d").suppress(), 2, opAssoc.LEFT, Dice.parse_binary),
(CaselessLiteral("d").suppress(), 1, opAssoc.RIGHT, Dice.parse_unary),
(Literal("/").suppress(), 2, opAssoc.LEFT, Div.parse),
(Literal("*").suppress(), 2, opAssoc.LEFT, Mul.parse),
(Literal("-").suppress(), 2, opAssoc.LEFT, Sub.parse),
(Literal("+").suppress(), 2, opAssoc.LEFT, Add.parse),
(CaselessLiteral("t").suppress(), 1, opAssoc.LEFT, Total.parse),
(CaselessLiteral("s").suppress(), 1, opAssoc.LEFT, Sort.parse),
示例5: NotImplementedError
# 需要导入模块: from pyparsing import Word [as 别名]
# 或者: from pyparsing.Word import setName [as 别名]
raise NotImplementedError()
from pyparsing import Word, Literal, Optional, ZeroOrMore, Suppress, \
Group, Forward, OneOrMore, ParseException, \
CharsNotIn, Combine, StringStart, \
StringEnd, delimitedList
import string
filter_ = Forward()
attr = Word(string.ascii_letters,
string.ascii_letters + string.digits + ';-',)
attr.leaveWhitespace()
attr.setName('attr')
hexdigits = Word(string.hexdigits, exact=2)
hexdigits.setName('hexdigits')
escaped = Suppress(Literal('\\')) + hexdigits
escaped.setName('escaped')
def _p_escaped(s, l, t):
text = t[0]
return chr(int(text, 16))
escaped.setParseAction(_p_escaped)
value = Combine(OneOrMore(CharsNotIn('*()\\\0') | escaped))
value.setName('value')
equal = Literal("=")
示例6: Word
# 需要导入模块: from pyparsing import Word [as 别名]
# 或者: from pyparsing.Word import setName [as 别名]
from errors import TwillAssertionError, TwillNameError
from pyparsing import OneOrMore, Word, printables, quotedString, Optional, \
alphas, alphanums, ParseException, ZeroOrMore, restOfLine, Combine, \
Literal, Group, removeQuotes, CharsNotIn
import twill.commands as commands
import namespaces
import re
### pyparsing stuff
# basically, a valid Python identifier:
command = Word(alphas + "_", alphanums + "_")
command = command.setResultsName('command')
command.setName("command")
# arguments to it.
# we need to reimplement all this junk from pyparsing because pcre's
# idea of escapable characters contains a lot more than the C-like
# thing pyparsing implements
_bslash = "\\"
_sglQuote = Literal("'")
_dblQuote = Literal('"')
_escapables = printables
_escapedChar = Word(_bslash, _escapables, exact=2)
dblQuotedString = Combine( _dblQuote + ZeroOrMore( CharsNotIn('\\"\n\r') | _escapedChar | '""' ) + _dblQuote ).streamline().setName("string enclosed in double quotes")
sglQuotedString = Combine( _sglQuote + ZeroOrMore( CharsNotIn("\\'\n\r") | _escapedChar | "''" ) + _sglQuote ).streamline().setName("string enclosed in single quotes")
quotedArg = ( dblQuotedString | sglQuotedString )
quotedArg.setParseAction(removeQuotes)
示例7: L
# 需要导入模块: from pyparsing import Word [as 别名]
# 或者: from pyparsing.Word import setName [as 别名]
LBRACKET = L("[").suppress()
RBRACKET = L("]").suppress()
COLON = L(":").suppress()
NIL = L('"-"')
NIL.setName("Nil")
NIL.setParseAction(lambda s, l, t: NilValue)
PRIORITY = LANGLE + Word(srange("[0-9]"), min=1, max=3) + RANGLE # 191 Max
PRIORITY = PRIORITY.setResultsName("priority")
PRIORITY.setName("Priority")
PRIORITY.setParseAction(lambda s, l, t: int(t[0]))
TIMESTAMP = Word(printables)
TIMESTAMP = TIMESTAMP.setResultsName("timestamp")
TIMESTAMP.setName("Timestamp")
HOSTNAME = Combine(NIL | Word(printables))
HOSTNAME = HOSTNAME.setResultsName("hostname")
HOSTNAME.setName("Hostname")
APPNAME = Word("".join(set(printables) - {"["}))
APPNAME = APPNAME.setResultsName("appname")
APPNAME.setName("AppName")
PROCID = Combine(LBRACKET + Word("".join(set(printables) - {"]"})) + RBRACKET)
PROCID = PROCID.setResultsName("procid")
PROCID.setName("ProcID")
HEADER = PRIORITY + TIMESTAMP + SP + HOSTNAME + SP + APPNAME + PROCID
示例8: NullValue
# 需要导入模块: from pyparsing import Word [as 别名]
# 或者: from pyparsing.Word import setName [as 别名]
NullValue = NullValue()
printables = "".join(set(_printables + " " + "\t") - {"|", "@"})
PIPE = L("|").suppress()
AT = L("@").suppress()
NULL = L("(null)")
NULL.setParseAction(lambda s, l, t: NullValue)
TIMESTAMP = Word(printables)
TIMESTAMP = TIMESTAMP.setResultsName("timestamp")
TIMESTAMP.setName("Timestamp")
COUNTRY_CODE = Word(printables)
COUNTRY_CODE = COUNTRY_CODE.setResultsName("country_code")
COUNTRY_CODE.setName("Country Code")
URL = Word(printables)
URL = URL.setResultsName("url")
URL.setName("URL")
REQUEST = TIMESTAMP + PIPE + Optional(COUNTRY_CODE) + PIPE + URL
PROJECT_NAME = NULL | Word(printables)
PROJECT_NAME = PROJECT_NAME.setResultsName("project_name")
PROJECT_NAME.setName("Project Name")
示例9: integer
# 需要导入模块: from pyparsing import Word [as 别名]
# 或者: from pyparsing.Word import setName [as 别名]
def integer():
token = Word(nums)
token.setParseAction(Integer.parse)
token.setName("integer")
return token