本文整理汇总了Python中pyparsing.Regex.setName方法的典型用法代码示例。如果您正苦于以下问题:Python Regex.setName方法的具体用法?Python Regex.setName怎么用?Python Regex.setName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyparsing.Regex
的用法示例。
在下文中一共展示了Regex.setName方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: define_identifier
# 需要导入模块: from pyparsing import Regex [as 别名]
# 或者: from pyparsing.Regex import setName [as 别名]
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
示例2: Group
# 需要导入模块: from pyparsing import Regex [as 别名]
# 或者: from pyparsing.Regex import setName [as 别名]
case = (
CASE +
Group(ZeroOrMore((WHEN + expr("when") + THEN + expr("then")).addParseAction(to_when_call)))("case") +
Optional(ELSE + expr("else")) +
END
).addParseAction(to_case_call)
selectStmt = Forward()
compound = (
(Keyword("not", caseless=True)("op").setDebugActions(*debug) + expr("params")).addParseAction(to_json_call) |
(Keyword("distinct", caseless=True)("op").setDebugActions(*debug) + expr("params")).addParseAction(to_json_call) |
Keyword("null", caseless=True).setName("null").setDebugActions(*debug) |
case |
(Literal("(").setDebugActions(*debug).suppress() + selectStmt + Literal(")").suppress()) |
(Literal("(").setDebugActions(*debug).suppress() + Group(delimitedList(expr)) + Literal(")").suppress()) |
realNum.setName("float").setDebugActions(*debug) |
intNum.setName("int").setDebugActions(*debug) |
(Literal("-")("op").setDebugActions(*debug) + expr("params")).addParseAction(to_json_call) |
sqlString.setName("string").setDebugActions(*debug) |
(
Word(alphas)("op").setName("function name").setDebugActions(*debug) +
Literal("(").setName("func_param").setDebugActions(*debug) +
Optional(selectStmt | Group(delimitedList(expr)))("params") +
")"
).addParseAction(to_json_call).setDebugActions(*debug) |
ident.copy().setName("variable").setDebugActions(*debug)
)
expr << Group(infixNotation(
compound,
[
(