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


Python TokenStreamRewriter.replaceIndex方法代码示例

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


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

示例1: testReplaceMiddleIndex

# 需要导入模块: from antlr4.TokenStreamRewriter import TokenStreamRewriter [as 别名]
# 或者: from antlr4.TokenStreamRewriter.TokenStreamRewriter import replaceIndex [as 别名]
    def testReplaceMiddleIndex(self):
        input = InputStream('abc')
        lexer = TestLexer(input)
        stream = CommonTokenStream(lexer=lexer)
        stream.fill()
        rewriter = TokenStreamRewriter(tokens=stream)

        rewriter.replaceIndex(1, 'x')

        self.assertEqual(rewriter.getDefaultText(), 'axc')
开发者ID:antlr,项目名称:antlr4,代码行数:12,代码来源:TestTokenStreamRewriter.py

示例2: testReplaceSingleMiddleThenOverlappingSuperset

# 需要导入模块: from antlr4.TokenStreamRewriter import TokenStreamRewriter [as 别名]
# 或者: from antlr4.TokenStreamRewriter.TokenStreamRewriter import replaceIndex [as 别名]
    def testReplaceSingleMiddleThenOverlappingSuperset(self):
        input = InputStream('abcba')
        lexer = TestLexer(input)
        stream = CommonTokenStream(lexer=lexer)
        stream.fill()
        rewriter = TokenStreamRewriter(tokens=stream)

        rewriter.replaceIndex(2, 'xyz')
        rewriter.replaceRange(0, 3, 'foo')

        self.assertEqual('fooa', rewriter.getDefaultText())
开发者ID:antlr,项目名称:antlr4,代码行数:13,代码来源:TestTokenStreamRewriter.py

示例3: testInsertThenReplaceSameIndex

# 需要导入模块: from antlr4.TokenStreamRewriter import TokenStreamRewriter [as 别名]
# 或者: from antlr4.TokenStreamRewriter.TokenStreamRewriter import replaceIndex [as 别名]
    def testInsertThenReplaceSameIndex(self):
        input = InputStream('abc')
        lexer = TestLexer(input)
        stream = CommonTokenStream(lexer=lexer)
        stream.fill()
        rewriter = TokenStreamRewriter(tokens=stream)

        rewriter.insertBeforeIndex(0, '0')
        rewriter.replaceIndex(0, 'x')

        self.assertEqual('0xbc', rewriter.getDefaultText())
开发者ID:antlr,项目名称:antlr4,代码行数:13,代码来源:TestTokenStreamRewriter.py

示例4: testReplaceThenInsertAfterLastIndex

# 需要导入模块: from antlr4.TokenStreamRewriter import TokenStreamRewriter [as 别名]
# 或者: from antlr4.TokenStreamRewriter.TokenStreamRewriter import replaceIndex [as 别名]
    def testReplaceThenInsertAfterLastIndex(self):
        input = InputStream('abc')
        lexer = TestLexer(input)
        stream = CommonTokenStream(lexer=lexer)
        stream.fill()
        rewriter = TokenStreamRewriter(tokens=stream)

        rewriter.replaceIndex(2, 'x')
        rewriter.insertAfter(2, 'y')

        self.assertEqual('abxy', rewriter.getDefaultText())
开发者ID:antlr,项目名称:antlr4,代码行数:13,代码来源:TestTokenStreamRewriter.py

示例5: test2ReplaceMiddleIndex1InsertBefore

# 需要导入模块: from antlr4.TokenStreamRewriter import TokenStreamRewriter [as 别名]
# 或者: from antlr4.TokenStreamRewriter.TokenStreamRewriter import replaceIndex [as 别名]
    def test2ReplaceMiddleIndex1InsertBefore(self):
        input = InputStream('abc')
        lexer = TestLexer(input)
        stream = CommonTokenStream(lexer=lexer)
        stream.fill()
        rewriter = TokenStreamRewriter(tokens=stream)

        rewriter.insertBeforeIndex(0, "_")
        rewriter.replaceIndex(1, 'x')
        rewriter.replaceIndex(1, 'y')

        self.assertEqual('_ayc', rewriter.getDefaultText())
开发者ID:antlr,项目名称:antlr4,代码行数:14,代码来源:TestTokenStreamRewriter.py


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