本文整理汇总了Python中pyparsing.Word.setWhitespaceChars方法的典型用法代码示例。如果您正苦于以下问题:Python Word.setWhitespaceChars方法的具体用法?Python Word.setWhitespaceChars怎么用?Python Word.setWhitespaceChars使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyparsing.Word
的用法示例。
在下文中一共展示了Word.setWhitespaceChars方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: parse
# 需要导入模块: from pyparsing import Word [as 别名]
# 或者: from pyparsing.Word import setWhitespaceChars [as 别名]
#.........这里部分代码省略.........
# shorter than indent will yield empty string, not IndexError
yield line[indent:]
# determine the indentation offset
indent = loc - s.rfind('\n', 0, loc) - 1
multiline = '\n'.join(remove_indent(tokens[0], indent))
# remove leading and trailing newlines
if multiline[0] == '\n':
multiline = multiline[1:]
if multiline[-1] == '\n':
multiline = multiline[:-1]
return multiline
MULTILINE = QuotedString('"""', multiline=True)
MULTILINE.setParseAction(clean_multiline_string)
# A Step
#
# Steps begin with a keyword such as Given, When, Then or And They can
# contain an optional inline comment, although it's possible to encapsulate
# it in a string. Finally they can contain a table or a multiline 'Python'
# string.
#
# <variables> are not parsed as part of the grammar as it's not easy to
# distinguish between a variable and XML. Instead scenarios will replace
# instances in the steps based on the outline keys.
#
STATEMENT_SENTENCE = Group(
lang.STATEMENT + # Given, When, Then, And
OneOrMore(UTFWORD.setWhitespaceChars(' \t') |
quotedString.setWhitespaceChars(' \t')) +
EOL
)
STATEMENT = Group(
STATEMENT_SENTENCE('sentence') +
Optional(TABLE('table') | MULTILINE('multiline'))
)
STATEMENT.setParseAction(Step)
STATEMENTS = Group(ZeroOrMore(STATEMENT))
#
# Background:
#
BACKGROUND_DEFN = \
lang.BACKGROUND('keyword') + Suppress(':') + EOL
BACKGROUND_DEFN.setParseAction(Background)
BACKGROUND = Group(
BACKGROUND_DEFN('node') +
STATEMENTS('statements')
)
BACKGROUND.setParseAction(Background.add_statements)
#
# Scenario: description
#
SCENARIO_DEFN = Group(
Group(ZeroOrMore(TAG))('tags') +
lang.SCENARIO('keyword') + Suppress(':') +
restOfLine('name') +