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


Python Word.suppress方法代码示例

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


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

示例1: ImportFromString

# 需要导入模块: from pyparsing import Word [as 别名]
# 或者: from pyparsing.Word import suppress [as 别名]
	def ImportFromString(self, text):
		#alphabet + number + underbar
		nameG = Word( srange("[a-zA-Z_]"), srange("[a-zA-Z0-9_]") )
		stringDoubleG = Literal('"') + SkipTo('"') + Literal('"')
		stringSingleG = Literal("'") + SkipTo("'") + Literal("'")
		stringG = stringDoubleG | stringSingleG
		#comment
		comment = (Literal('/*').suppress() + SkipTo('*/').suppress() + Literal('*/').suppress())
		digraphNameG = Word( srange("[a-zA-Z_]"), srange("[a-zA-Z0-9_]") )
		digraphNameG.setParseAction( self.DigraphNameAction )
		nodeNameG = Word( srange("[a-zA-Z_]"), srange("[a-zA-Z0-9_]") )
		nodeNameG.setParseAction( self.NodeNameAction )
		startG = Literal('digraph').suppress() + digraphNameG.suppress() + Literal('{').suppress()
		endG = Literal('}').suppress()

		attrBaseG = nameG+Literal('=').suppress()+(nameG ^ stringG)
		attrBaseG.setParseAction( self.AttributeAction )
		attrRepeatG = attrBaseG + ZeroOrMore( Literal(',').suppress() + attrBaseG )
		attrG = ZeroOrMore( Literal('[').suppress() + ZeroOrMore( attrRepeatG ) + Literal(']').suppress() )
		nodeG = nodeNameG + attrG
		edgeNameG = nameG + Literal('->').suppress() + nameG
		edgeNameG.setParseAction( self.EdgeNameAction )
		edgeG = edgeNameG + attrG
		sizeG = Literal('size') + Literal('=') + (quotedString | dblQuotedString)
		baseG = (sizeG | (nodeG ^ edgeG))  + Literal(';').suppress()
		baseG = baseG | comment
		baseG = ZeroOrMore(baseG)
		grammerG = startG + baseG + endG
		grammerG.parseString(text)
开发者ID:dajie,项目名称:TestCode,代码行数:31,代码来源:dot_import.py

示例2: ObfuscateBNF

# 需要导入模块: from pyparsing import Word [as 别名]
# 或者: from pyparsing.Word import suppress [as 别名]
class ObfuscateBNF(object):
    __metaclass__ = abc.ABCMeta

    def __init__(self, get_obfuscated):
        """BNF grammar for source statements.

        Parameters
        ----------
        get_obfuscated : function
            Function to return the obfuscated name for an identifier.
        """
        self.get_obfuscated = get_obfuscated

        self.directive = oneOf("#:")
        self.comment = ~self.directive + pythonStyleComment

        self.separator = Word("[email protected]$%^&*()+`-={}|[]:;<>?,/.", max=2)

        self.string = \
            QuotedString(quoteChar='"', escChar='\\', multiline=False,
                         unquoteResults=False) |\
            QuotedString(quoteChar="'", escChar='\\', multiline=False,
                         unquoteResults=False)

        self.doc_string = \
            QuotedString(quoteChar='"""', escChar='\\', multiline=True,
                         unquoteResults=False) |\
            QuotedString(quoteChar="'''", escChar='\\', multiline=True,
                         unquoteResults=False)
        self.string_or_doc = self.doc_string | self.string
        self.triple_quote = Literal("'''") | Literal('"""')

        self.e = Literal('E') | Literal('e')
        self.point = Literal('.')

        self.plusorminus = Literal('+') | Literal('-')
        self.number = Word(nums)
        self.integer = Combine(Optional(self.plusorminus) + self.number)
        self.fnumber = Combine(
            self.integer +
            Optional(self.point + Optional(self.number)) +
            Optional(self.e + self.integer))

        self.tab = Literal('    ')

        self.ident = Word(alphas+'_', alphanums+'_')
        self.conseq_idents_numbs = OneOrMore(self.ident | self.fnumber)
        self.attrib = self.ident + OneOrMore('.'+self.ident)

        self.statement = (
            ZeroOrMore(
                (self.directive |
                 self.tab |
                 self.conseq_idents_numbs |
                 self.separator |
                 self.string_or_doc |
                 self.triple_quote)
            ) + Optional(self.comment).suppress()
        )

        self.attribs = (
            ZeroOrMore(
                (self.directive.suppress() |
                 self.tab.suppress() |
                 self.attrib |
                 self.ident.suppress() |
                 self.separator.suppress() |
                 self.fnumber.suppress() |
                 self.string_or_doc.suppress() |
                 self.triple_quote.suppress())
            ) + Optional(self.comment).suppress()
        )

        self.conseq_idents = (
            ZeroOrMore(
                (self.directive.suppress() |
                 self.tab.suppress() |
                 self.ident |
                 self.separator.suppress() |
                 self.fnumber.suppress() |
                 self.string.suppress())
            ) + Optional(self.comment).suppress()
        )

        self.conseq_idents_no_obfuscate = (
            ZeroOrMore(
                (self.directive.suppress() |
                 self.tab.suppress() |
                 self.ident |
                 self.separator.suppress() |
                 self.fnumber.suppress() |
                 self.string_or_doc.suppress() |
                 self.triple_quote.suppress())
            ) + Optional(self.comment).suppress()
        )

        self.attribs.setParseAction(self.add_attribs_reserveds)
        self.conseq_idents.setParseAction(self.add_conseq_idents)
        self.conseq_idents_no_obfuscate.setParseAction(
            self.add_conseq_idents_no_obfuscate)
#.........这里部分代码省略.........
开发者ID:rdevost,项目名称:pymixup,代码行数:103,代码来源:obfuscatebnf.py

示例3: Word

# 需要导入模块: from pyparsing import Word [as 别名]
# 或者: from pyparsing.Word import suppress [as 别名]
	if dot['current'] != None :
		obj = dot['current']
		obj[toks[0]] = toks[1]

#alphabet + number + underbar
nameG = Word( srange("[a-zA-Z_]"), srange("[a-zA-Z0-9_]") )
stringDoubleG = Literal('"') + SkipTo('"') + Literal('"')
stringSingleG = Literal("'") + SkipTo("'") + Literal("'")
stringG = stringDoubleG | stringSingleG
#comment
comment = (Literal('/*').suppress() + SkipTo('*/').suppress() + Literal('*/').suppress())
digraphNameG = Word( srange("[a-zA-Z_]"), srange("[a-zA-Z0-9_]") )
digraphNameG.setParseAction( DigraphNameAction )
nodeNameG = Word( srange("[a-zA-Z_]"), srange("[a-zA-Z0-9_]") )
nodeNameG.setParseAction( NodeNameAction )
startG = Literal('digraph').suppress() + digraphNameG.suppress() + Literal('{').suppress()
endG = Literal('}').suppress()

attrBaseG = nameG+Literal('=').suppress()+(nameG ^ stringG)
attrBaseG.setParseAction( AttributeAction )
attrRepeatG = attrBaseG + ZeroOrMore( Literal(',').suppress() + attrBaseG )
attrG = ZeroOrMore( Literal('[').suppress() + ZeroOrMore( attrRepeatG ) + Literal(']').suppress() )
nodeG = nodeNameG + attrG
edgeNameG = nameG + Literal('->').suppress() + nameG
edgeNameG.setParseAction( EdgeNameAction )
edgeG = edgeNameG + attrG
sizeG = Literal('size') + Literal('=') + (quotedString | dblQuotedString)
baseG = (sizeG | (nodeG ^ edgeG))  + Literal(';').suppress()
#baseG = nodeG + Literal(';').suppress()
baseG = baseG | comment
baseG = ZeroOrMore(baseG)
开发者ID:dajie,项目名称:TestCode,代码行数:33,代码来源:pyparse_test.py


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