当前位置: 首页>>代码示例>>Python>>正文


Python Regex.leaveWhitespace方法代码示例

本文整理汇总了Python中pyparsing.Regex.leaveWhitespace方法的典型用法代码示例。如果您正苦于以下问题:Python Regex.leaveWhitespace方法的具体用法?Python Regex.leaveWhitespace怎么用?Python Regex.leaveWhitespace使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pyparsing.Regex的用法示例。


在下文中一共展示了Regex.leaveWhitespace方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: Suppress

# 需要导入模块: from pyparsing import Regex [as 别名]
# 或者: from pyparsing.Regex import leaveWhitespace [as 别名]
from bibtexvcs.bibfile import Entry, Comment, ImplicitComment, MacroReference, MacroDefinition, Name, Preamble

LCURLY = Suppress("{")
RCURLY = Suppress("}")
QUOTE = Suppress('"')
COMMA = Suppress(",")
AT = Suppress("@")
EQUALS = Suppress("=")
HASH = Suppress("#")

bracketed = lambda expr: LCURLY + expr + RCURLY

# Define parser components for strings (the hard bit)
charsNoCurly = Regex(r"[^{}]+")
charsNoCurly.leaveWhitespace()
charsNoQuotecurly = Regex(r'[^"{}]+')
charsNoQuotecurly.leaveWhitespace()

# Curly string is some stuff without curlies, or nested curly sequences
curlyString = Forward().leaveWhitespace()
curlyItem = Group(curlyString) | charsNoCurly
curlyString <<= LCURLY + ZeroOrMore(curlyItem) + RCURLY

# quoted string is either just stuff within quotes, or stuff within quotes, within
# which there is nested curliness
quotedItem = Group(curlyString) | charsNoQuotecurly
quotedString = QUOTE + ZeroOrMore(quotedItem) + QUOTE

number = Regex("[0-9]+")
# Basis characters (by exclusion) for variable / field names.  The following
开发者ID:supermihi,项目名称:bibtexvcs,代码行数:32,代码来源:parser.py

示例2: Suppress

# 需要导入模块: from pyparsing import Regex [as 别名]
# 或者: from pyparsing.Regex import leaveWhitespace [as 别名]
RPAREN = Suppress(')')
QUOTE = Suppress('"')
COMMA = Suppress(',')
AT = Suppress('@')
EQUALS = Suppress('=')
HASH = Suppress('#')


def bracketed(expr):
    """ Return matcher for `expr` between curly brackets or parentheses """
    return (LPAREN + expr + RPAREN) | (LCURLY + expr + RCURLY)


# Define parser components for strings (the hard bit)
chars_no_curly = Regex(r"[^{}]+")
chars_no_curly.leaveWhitespace()
chars_no_quotecurly = Regex(r'[^"{}]+')
chars_no_quotecurly.leaveWhitespace()
# Curly string is some stuff without curlies, or nested curly sequences
curly_string = Forward()
curly_item = Group(curly_string) | chars_no_curly
curly_string << LCURLY + ZeroOrMore(curly_item) + RCURLY
# quoted string is either just stuff within quotes, or stuff within quotes, within
# which there is nested curliness
quoted_item = Group(curly_string) | chars_no_quotecurly
quoted_string = QUOTE + ZeroOrMore(quoted_item) + QUOTE

# Numbers can just be numbers. Only integers though.
number = Regex('[0-9]+')

# Basis characters (by exclusion) for variable / field names.  The following
开发者ID:SYNchroACK,项目名称:crits_dependencies,代码行数:33,代码来源:btpyparse.py

示例3: Regex

# 需要导入模块: from pyparsing import Regex [as 别名]
# 或者: from pyparsing.Regex import leaveWhitespace [as 别名]
PN_LOCAL = Regex(u"""([%(PN_CHARS_U)s:0-9]|%(PLX)s)
                     (([%(PN_CHARS)s\\.:]|%(PLX)s)*
                      ([%(PN_CHARS)s:]|%(PLX)s) )?"""%dict(PN_CHARS_U=PN_CHARS_U_re,
                                                       PN_CHARS=PN_CHARS_re,
                                                         PLX=PLX_re), flags=re.X|re.UNICODE)

def _hexExpand(match):
    return unichr(int(match.group(0)[1:], 16))

PN_LOCAL.setParseAction(lambda x: re.sub("(%s)"%PERCENT_re, _hexExpand, x[0]))




# [141] PNAME_LN ::= PNAME_NS PN_LOCAL
PNAME_LN = PNAME_NS + Param('localname', PN_LOCAL.leaveWhitespace())

# [142] BLANK_NODE_LABEL ::= '_:' ( PN_CHARS_U | [0-9] ) ((PN_CHARS|'.')* PN_CHARS)?
BLANK_NODE_LABEL = Regex(u'_:[0-9%s](?:[\\.%s]*[%s])?' % (
    PN_CHARS_U_re, PN_CHARS_re, PN_CHARS_re), flags=re.U)
BLANK_NODE_LABEL.setParseAction(lambda x: rdflib.BNode(x[0]))


# [166] VARNAME ::= ( PN_CHARS_U | [0-9] ) ( PN_CHARS_U | [0-9] | #x00B7 | [#x0300-#x036F] | [#x203F-#x2040] )*
VARNAME = Regex(u'[%s0-9][%s0-9\u00B7\u0300-\u036F\u203F-\u2040]*' % (
    PN_CHARS_U_re, PN_CHARS_U_re), flags=re.U)

# [143] VAR1 ::= '?' VARNAME
VAR1 = Combine(Suppress('?') + VARNAME)

# [144] VAR2 ::= '$' VARNAME
开发者ID:joernhees,项目名称:rdflib,代码行数:33,代码来源:parser.py


注:本文中的pyparsing.Regex.leaveWhitespace方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。