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


Python TokenStreamRewriter.insertBeforeIndex方法代码示例

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


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

示例1: testInsertBeforeIndexZero

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

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

示例2: testInsertBeforeTokenThenDeleteThatToken

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

        rewriter.insertBeforeIndex(1, 'foo')
        rewriter.replaceRange(1, 2, 'foo')

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

示例3: testLeaveAloneDisjointInsert2

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

        rewriter.replaceRange(2, 3, 'foo')
        rewriter.insertBeforeIndex(1, 'x')

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

示例4: testCombineInsertOnLeftWithDelete

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

        rewriter.delete('default', 0, 2)
        rewriter.insertBeforeIndex(0, 'z')

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

示例5: testCombineInsertOnLeftWithReplace

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

        rewriter.replaceRange(0, 2, 'foo')
        rewriter.insertBeforeIndex(0, 'z')

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

示例6: test2InsertBeforeAfterMiddleIndex

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

        rewriter.insertBeforeIndex(1, 'x')
        rewriter.insertAfter(1, 'x')

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

示例7: testCombineInserts

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

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

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

示例8: testReplaceRangeThenInsertAtLeftEdge

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

        rewriter.replaceRange(2, 4, 'x')
        rewriter.insertBeforeIndex(2, 'y')

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

示例9: testInsertThenReplaceSameIndex

# 需要导入模块: from antlr4.TokenStreamRewriter import TokenStreamRewriter [as 别名]
# 或者: from antlr4.TokenStreamRewriter.TokenStreamRewriter import insertBeforeIndex [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

示例10: test2ReplaceMiddleIndex1InsertBefore

# 需要导入模块: from antlr4.TokenStreamRewriter import TokenStreamRewriter [as 别名]
# 或者: from antlr4.TokenStreamRewriter.TokenStreamRewriter import insertBeforeIndex [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

示例11: testPreservesOrderOfContiguousInserts

# 需要导入模块: from antlr4.TokenStreamRewriter import TokenStreamRewriter [as 别名]
# 或者: from antlr4.TokenStreamRewriter.TokenStreamRewriter import insertBeforeIndex [as 别名]
    def testPreservesOrderOfContiguousInserts(self):
        """
        Test for fix for: https://github.com/antlr/antlr4/issues/550
        """
        input = InputStream('aa')
        lexer = TestLexer(input)
        stream = CommonTokenStream(lexer=lexer)
        stream.fill()
        rewriter = TokenStreamRewriter(tokens=stream)

        rewriter.insertBeforeIndex(0, '<b>')
        rewriter.insertAfter(0, '</b>')
        rewriter.insertBeforeIndex(1, '<b>')
        rewriter.insertAfter(1, '</b>')

        self.assertEqual('<b>a</b><b>a</b>', rewriter.getDefaultText())
开发者ID:antlr,项目名称:antlr4,代码行数:18,代码来源:TestTokenStreamRewriter.py

示例12: testReplaceThenDeleteMiddleIndex

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

        rewriter.replaceRange(0, 2, 'x')
        rewriter.insertBeforeIndex(1, '0')

        with self.assertRaises(ValueError) as ctx:
            rewriter.getDefaultText()
        self.assertEqual(
            'insert op <[email protected][@1,1:1=\'b\',<2>,1:1]:"0"> within boundaries of previous <[email protected][@0,0:0=\'a\',<1>,1:0]..[@2,2:2=\'c\',<3>,1:2]:"x">',
            str(ctx.exception)
        )
开发者ID:antlr,项目名称:antlr4,代码行数:18,代码来源:TestTokenStreamRewriter.py

示例13: testReplaceRangeThenInsertAtRightEdge

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

        rewriter.replaceRange(2, 4, 'x')
        rewriter.insertBeforeIndex(4, 'y')

        with self.assertRaises(ValueError) as ctx:
            rewriter.getDefaultText()
        msg = str(ctx.exception)
        self.assertEqual(
            "insert op <[email protected][@4,4:4='c',<3>,1:4]:\"y\"> within boundaries of previous <[email protected][@2,2:2='c',<3>,1:2]..[@4,4:4='c',<3>,1:4]:\"x\">",
            msg
        )
开发者ID:antlr,项目名称:antlr4,代码行数:19,代码来源:TestTokenStreamRewriter.py


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