本文整理汇总了Python中pyparsing.OneOrMore.leaveWhitespace方法的典型用法代码示例。如果您正苦于以下问题:Python OneOrMore.leaveWhitespace方法的具体用法?Python OneOrMore.leaveWhitespace怎么用?Python OneOrMore.leaveWhitespace使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyparsing.OneOrMore
的用法示例。
在下文中一共展示了OneOrMore.leaveWhitespace方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: translate
# 需要导入模块: from pyparsing import OneOrMore [as 别名]
# 或者: from pyparsing.OneOrMore import leaveWhitespace [as 别名]
def translate(self, text, filename):
self.source = text
self.super = None
self.inheritance = 0
self.declaration_lines = ['inheritance = 0']
self.block_lines = []
self.body_lines = ['def body():']
self.target_lines = self.body_lines
self.indent = 1
template_close = Literal('%>')
white = White()
attribute = Word(alphanums + '_') + Literal('=') + QuotedString('"') + Optional(white)
directive = "<%@" + Optional(white) + Word(alphanums + '_') + white + ZeroOrMore(attribute) + template_close
declaration = "<%!" + SkipTo(template_close) + template_close
expression = "<%=" + SkipTo(template_close) + template_close
scriptlet = '<%' + SkipTo(template_close) + template_close
template_text = directive | declaration | expression | scriptlet
plain_text = Regex(r'((?!<%).|\s)+', re.MULTILINE)
body = template_text | plain_text
lit = OneOrMore(body)
directive.setParseAction(self.compile_directive)
declaration.setParseAction(self.compile_declaration)
expression.setParseAction(self.compile_expression)
scriptlet.setParseAction(self.compile_scriptlet)
plain_text.setParseAction(self.compile_plain_text)
lit.leaveWhitespace()
lit.parseString(self.source)
translated = '\n' + '\n'.join(self.declaration_lines + ['\n'] + self.block_lines + ['\n'] + self.body_lines)
if self.super:
translated = self.super.module_source + translated
return translated
示例2: Optional
# 需要导入模块: from pyparsing import OneOrMore [as 别名]
# 或者: from pyparsing.OneOrMore import leaveWhitespace [as 别名]
+ Optional(LACC + OneOrMore(DECLARATION | CSS_COMMENT | SCSS_COMMENT) + RACC)
+ OPT_SEMICOLON
)
# Selectors
ELEMENT_NAME = Combine(OneOrMore(IDENT | "&")) | Literal("*")
ATTRIB = LBRACK + SkipTo("]") + RBRACK
CLASS_NAME = Word(".", alphanums + "-_")
HASH = Regex(r"#[-a-zA-Z_][-a-zA-Z0-9_]+")
FILTER = HASH | CLASS_NAME | ATTRIB
# PSEUDO = Regex(r':{1,2}[A-Za-z0-9-_]+')
PSEUDO = Regex(r":{1,2}[^\s;{}]+")
SELECTOR = OneOrMore(ELEMENT_NAME | FILTER | INTERPOLATION_VAR | PSEUDO)
SELECTOR.leaveWhitespace()
SELECTOR_GROUP = SELECTOR + ZeroOrMore(Optional(Word("+>", max=1)) + SELECTOR)
SELECTOR_GROUP.skipWhitespace = True
SELECTOR_TREE = SELECTOR_GROUP + ZeroOrMore(COMMA + SELECTOR_GROUP)
# @debug
DEBUG = "@debug" + EXPRESSION + OPT_SEMICOLON
# @warn
WARN = "@warn" + quotedString + OPT_SEMICOLON
# @include
INCLUDE = "@include" + IDENT + Optional(PARAMS) + OPT_SEMICOLON
# @extend
EXTEND = "@extend" + OneOrMore(ELEMENT_NAME | FILTER | INTERPOLATION_VAR | PSEUDO) + OPT_SEMICOLON
示例3: Literal
# 需要导入模块: from pyparsing import OneOrMore [as 别名]
# 或者: from pyparsing.OneOrMore import leaveWhitespace [as 别名]
from pyparsing import Literal, OneOrMore, QuotedString, SkipTo, stringEnd
"""Givent a string, this parser skips to the starting charcters '<%',
returning everything it skips over as a token. Everything that is
between '<%=' and '%>' are returned as a token labeled
assignment. This is repeated until we run out of '<%' at which point
we return everything up to the end of a string as a token."""
startExp = Literal('<%')
assignExp = QuotedString('<%=', endQuoteChar='%>', multiline=True)
assignExp = assignExp.setResultsName('assignment')
ERBParser = OneOrMore(SkipTo(startExp) + assignExp) + SkipTo(stringEnd)
ERBParser.leaveWhitespace()
class ERBTemplate(object):
def loadFromFile(self, fileName):
tokens = ERBParser.parseFile(fileName)
# Create a dictionary where the key is the position the token
# was found and and the value is the token's name as set by setResultsName
typeByPos = dict( [ (v[1],k) for (k,vlist) in tokens._ParseResults__tokdict.items()
for v in vlist ] )
self.typeByPos = typeByPos
self.tokens = tokens
def render(self, context):
tokens = self.tokens
tokenCount = len(tokens)