本文整理汇总了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')
示例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())
示例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())
示例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())
示例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())
示例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')
示例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())
示例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())
示例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())
示例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())
示例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())
示例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)
)
示例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
)