forked from jasder/antlr
Fixed printing of RewriteOps, now tests are passing.
This commit is contained in:
parent
cb396a5047
commit
2dab85ce2b
|
@ -8,7 +8,6 @@
|
||||||
|
|
||||||
/* Begin PBXBuildFile section */
|
/* Begin PBXBuildFile section */
|
||||||
DB09919D1E22DE9B00FE71AA /* TokenStreamTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = DB0991951E22DE6000FE71AA /* TokenStreamTests.swift */; };
|
DB09919D1E22DE9B00FE71AA /* TokenStreamTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = DB0991951E22DE6000FE71AA /* TokenStreamTests.swift */; };
|
||||||
DB0991A11E22DF3B00FE71AA /* Info.plist in Resources */ = {isa = PBXBuildFile; fileRef = DB0991A01E22DF3B00FE71AA /* Info.plist */; };
|
|
||||||
DB4EB8A51E2CB1B60095F402 /* SwiftTest.g4 in Resources */ = {isa = PBXBuildFile; fileRef = DB4EB8A41E2CB1B60095F402 /* SwiftTest.g4 */; };
|
DB4EB8A51E2CB1B60095F402 /* SwiftTest.g4 in Resources */ = {isa = PBXBuildFile; fileRef = DB4EB8A41E2CB1B60095F402 /* SwiftTest.g4 */; };
|
||||||
DBBAE6351E22DCAC00C2FEA6 /* ANTLRErrorListener.swift in Sources */ = {isa = PBXBuildFile; fileRef = DBBAE58E1E22DCAC00C2FEA6 /* ANTLRErrorListener.swift */; };
|
DBBAE6351E22DCAC00C2FEA6 /* ANTLRErrorListener.swift in Sources */ = {isa = PBXBuildFile; fileRef = DBBAE58E1E22DCAC00C2FEA6 /* ANTLRErrorListener.swift */; };
|
||||||
DBBAE6361E22DCAC00C2FEA6 /* ANTLRErrorListener.swift in Sources */ = {isa = PBXBuildFile; fileRef = DBBAE58E1E22DCAC00C2FEA6 /* ANTLRErrorListener.swift */; };
|
DBBAE6361E22DCAC00C2FEA6 /* ANTLRErrorListener.swift in Sources */ = {isa = PBXBuildFile; fileRef = DBBAE58E1E22DCAC00C2FEA6 /* ANTLRErrorListener.swift */; };
|
||||||
|
@ -324,22 +323,17 @@
|
||||||
DBBAE76C1E22DCAC00C2FEA6 /* VocabularySingle.swift in Sources */ = {isa = PBXBuildFile; fileRef = DBBAE6311E22DCAC00C2FEA6 /* VocabularySingle.swift */; };
|
DBBAE76C1E22DCAC00C2FEA6 /* VocabularySingle.swift in Sources */ = {isa = PBXBuildFile; fileRef = DBBAE6311E22DCAC00C2FEA6 /* VocabularySingle.swift */; };
|
||||||
DBBAE76D1E22DCAC00C2FEA6 /* WritableToken.swift in Sources */ = {isa = PBXBuildFile; fileRef = DBBAE6321E22DCAC00C2FEA6 /* WritableToken.swift */; };
|
DBBAE76D1E22DCAC00C2FEA6 /* WritableToken.swift in Sources */ = {isa = PBXBuildFile; fileRef = DBBAE6321E22DCAC00C2FEA6 /* WritableToken.swift */; };
|
||||||
DBBAE76E1E22DCAC00C2FEA6 /* WritableToken.swift in Sources */ = {isa = PBXBuildFile; fileRef = DBBAE6321E22DCAC00C2FEA6 /* WritableToken.swift */; };
|
DBBAE76E1E22DCAC00C2FEA6 /* WritableToken.swift in Sources */ = {isa = PBXBuildFile; fileRef = DBBAE6321E22DCAC00C2FEA6 /* WritableToken.swift */; };
|
||||||
DBBAE7701E22DCAC00C2FEA6 /* Info-IOS.plist in Resources */ = {isa = PBXBuildFile; fileRef = DBBAE6331E22DCAC00C2FEA6 /* Info-IOS.plist */; };
|
|
||||||
DBBAE7721E22DCAC00C2FEA6 /* Info-OSX.plist in Resources */ = {isa = PBXBuildFile; fileRef = DBBAE6341E22DCAC00C2FEA6 /* Info-OSX.plist */; };
|
DBBAE7721E22DCAC00C2FEA6 /* Info-OSX.plist in Resources */ = {isa = PBXBuildFile; fileRef = DBBAE6341E22DCAC00C2FEA6 /* Info-OSX.plist */; };
|
||||||
DBF000AA1E7F521E006DB586 /* SwiftTest.tokens in Resources */ = {isa = PBXBuildFile; fileRef = DBF000A21E7F521E006DB586 /* SwiftTest.tokens */; };
|
|
||||||
DBF000AB1E7F521E006DB586 /* SwiftTestBaseListener.swift in Sources */ = {isa = PBXBuildFile; fileRef = DBF000A31E7F521E006DB586 /* SwiftTestBaseListener.swift */; };
|
DBF000AB1E7F521E006DB586 /* SwiftTestBaseListener.swift in Sources */ = {isa = PBXBuildFile; fileRef = DBF000A31E7F521E006DB586 /* SwiftTestBaseListener.swift */; };
|
||||||
DBF000AC1E7F521E006DB586 /* SwiftTestLexer.swift in Sources */ = {isa = PBXBuildFile; fileRef = DBF000A41E7F521E006DB586 /* SwiftTestLexer.swift */; };
|
DBF000AC1E7F521E006DB586 /* SwiftTestLexer.swift in Sources */ = {isa = PBXBuildFile; fileRef = DBF000A41E7F521E006DB586 /* SwiftTestLexer.swift */; };
|
||||||
DBF000AD1E7F521E006DB586 /* SwiftTestLexer.tokens in Resources */ = {isa = PBXBuildFile; fileRef = DBF000A51E7F521E006DB586 /* SwiftTestLexer.tokens */; };
|
|
||||||
DBF000AE1E7F521E006DB586 /* SwiftTestLexerATN.swift in Sources */ = {isa = PBXBuildFile; fileRef = DBF000A61E7F521E006DB586 /* SwiftTestLexerATN.swift */; };
|
DBF000AE1E7F521E006DB586 /* SwiftTestLexerATN.swift in Sources */ = {isa = PBXBuildFile; fileRef = DBF000A61E7F521E006DB586 /* SwiftTestLexerATN.swift */; };
|
||||||
DBF000AF1E7F521E006DB586 /* SwiftTestListener.swift in Sources */ = {isa = PBXBuildFile; fileRef = DBF000A71E7F521E006DB586 /* SwiftTestListener.swift */; };
|
DBF000AF1E7F521E006DB586 /* SwiftTestListener.swift in Sources */ = {isa = PBXBuildFile; fileRef = DBF000A71E7F521E006DB586 /* SwiftTestListener.swift */; };
|
||||||
DBF000B01E7F521E006DB586 /* SwiftTestParser.swift in Sources */ = {isa = PBXBuildFile; fileRef = DBF000A81E7F521E006DB586 /* SwiftTestParser.swift */; };
|
DBF000B01E7F521E006DB586 /* SwiftTestParser.swift in Sources */ = {isa = PBXBuildFile; fileRef = DBF000A81E7F521E006DB586 /* SwiftTestParser.swift */; };
|
||||||
DBF000B11E7F521E006DB586 /* SwiftTestParserATN.swift in Sources */ = {isa = PBXBuildFile; fileRef = DBF000A91E7F521E006DB586 /* SwiftTestParserATN.swift */; };
|
DBF000B11E7F521E006DB586 /* SwiftTestParserATN.swift in Sources */ = {isa = PBXBuildFile; fileRef = DBF000A91E7F521E006DB586 /* SwiftTestParserATN.swift */; };
|
||||||
DBF000B31E7F59B3006DB586 /* TokenStreamRewriterTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = DBF000B21E7F59B3006DB586 /* TokenStreamRewriterTests.swift */; };
|
DBF000B31E7F59B3006DB586 /* TokenStreamRewriterTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = DBF000B21E7F59B3006DB586 /* TokenStreamRewriterTests.swift */; };
|
||||||
DBF000B91E7F627D006DB586 /* LexerA.swift in Sources */ = {isa = PBXBuildFile; fileRef = DBF000B61E7F627D006DB586 /* LexerA.swift */; };
|
DBF000B91E7F627D006DB586 /* LexerA.swift in Sources */ = {isa = PBXBuildFile; fileRef = DBF000B61E7F627D006DB586 /* LexerA.swift */; };
|
||||||
DBF000BA1E7F627D006DB586 /* LexerA.tokens in Resources */ = {isa = PBXBuildFile; fileRef = DBF000B71E7F627D006DB586 /* LexerA.tokens */; };
|
|
||||||
DBF000BB1E7F627D006DB586 /* LexerAATN.swift in Sources */ = {isa = PBXBuildFile; fileRef = DBF000B81E7F627D006DB586 /* LexerAATN.swift */; };
|
DBF000BB1E7F627D006DB586 /* LexerAATN.swift in Sources */ = {isa = PBXBuildFile; fileRef = DBF000B81E7F627D006DB586 /* LexerAATN.swift */; };
|
||||||
DBF000C11E7F6546006DB586 /* LexerB.swift in Sources */ = {isa = PBXBuildFile; fileRef = DBF000BE1E7F6546006DB586 /* LexerB.swift */; };
|
DBF000C11E7F6546006DB586 /* LexerB.swift in Sources */ = {isa = PBXBuildFile; fileRef = DBF000BE1E7F6546006DB586 /* LexerB.swift */; };
|
||||||
DBF000C21E7F6546006DB586 /* LexerB.tokens in Resources */ = {isa = PBXBuildFile; fileRef = DBF000BF1E7F6546006DB586 /* LexerB.tokens */; };
|
|
||||||
DBF000C31E7F6546006DB586 /* LexerBATN.swift in Sources */ = {isa = PBXBuildFile; fileRef = DBF000C01E7F6546006DB586 /* LexerBATN.swift */; };
|
DBF000C31E7F6546006DB586 /* LexerBATN.swift in Sources */ = {isa = PBXBuildFile; fileRef = DBF000C01E7F6546006DB586 /* LexerBATN.swift */; };
|
||||||
F9A424AD1BCD348C00A9CD35 /* Antlr4.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F9A4211C1BCCC35000A9CD35 /* Antlr4.framework */; };
|
F9A424AD1BCD348C00A9CD35 /* Antlr4.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F9A4211C1BCCC35000A9CD35 /* Antlr4.framework */; };
|
||||||
/* End PBXBuildFile section */
|
/* End PBXBuildFile section */
|
||||||
|
@ -928,7 +922,6 @@
|
||||||
DBF000911E7F4D07006DB586 /* ShellScript */,
|
DBF000911E7F4D07006DB586 /* ShellScript */,
|
||||||
F9A424A41BCD348C00A9CD35 /* Sources */,
|
F9A424A41BCD348C00A9CD35 /* Sources */,
|
||||||
F9A424A51BCD348C00A9CD35 /* Frameworks */,
|
F9A424A51BCD348C00A9CD35 /* Frameworks */,
|
||||||
F9A424A61BCD348C00A9CD35 /* Resources */,
|
|
||||||
);
|
);
|
||||||
buildRules = (
|
buildRules = (
|
||||||
);
|
);
|
||||||
|
@ -946,7 +939,7 @@
|
||||||
F9A421131BCCC35000A9CD35 /* Project object */ = {
|
F9A421131BCCC35000A9CD35 /* Project object */ = {
|
||||||
isa = PBXProject;
|
isa = PBXProject;
|
||||||
attributes = {
|
attributes = {
|
||||||
LastUpgradeCheck = 0810;
|
LastUpgradeCheck = 0820;
|
||||||
ORGANIZATIONNAME = jlabs;
|
ORGANIZATIONNAME = jlabs;
|
||||||
TargetAttributes = {
|
TargetAttributes = {
|
||||||
F9A4211B1BCCC35000A9CD35 = {
|
F9A4211B1BCCC35000A9CD35 = {
|
||||||
|
@ -997,23 +990,10 @@
|
||||||
isa = PBXResourcesBuildPhase;
|
isa = PBXResourcesBuildPhase;
|
||||||
buildActionMask = 2147483647;
|
buildActionMask = 2147483647;
|
||||||
files = (
|
files = (
|
||||||
DBBAE7701E22DCAC00C2FEA6 /* Info-IOS.plist in Resources */,
|
|
||||||
DBBAE7721E22DCAC00C2FEA6 /* Info-OSX.plist in Resources */,
|
DBBAE7721E22DCAC00C2FEA6 /* Info-OSX.plist in Resources */,
|
||||||
);
|
);
|
||||||
runOnlyForDeploymentPostprocessing = 0;
|
runOnlyForDeploymentPostprocessing = 0;
|
||||||
};
|
};
|
||||||
F9A424A61BCD348C00A9CD35 /* Resources */ = {
|
|
||||||
isa = PBXResourcesBuildPhase;
|
|
||||||
buildActionMask = 2147483647;
|
|
||||||
files = (
|
|
||||||
DBF000C21E7F6546006DB586 /* LexerB.tokens in Resources */,
|
|
||||||
DBF000BA1E7F627D006DB586 /* LexerA.tokens in Resources */,
|
|
||||||
DB0991A11E22DF3B00FE71AA /* Info.plist in Resources */,
|
|
||||||
DBF000AD1E7F521E006DB586 /* SwiftTestLexer.tokens in Resources */,
|
|
||||||
DBF000AA1E7F521E006DB586 /* SwiftTest.tokens in Resources */,
|
|
||||||
);
|
|
||||||
runOnlyForDeploymentPostprocessing = 0;
|
|
||||||
};
|
|
||||||
/* End PBXResourcesBuildPhase section */
|
/* End PBXResourcesBuildPhase section */
|
||||||
|
|
||||||
/* Begin PBXShellScriptBuildPhase section */
|
/* Begin PBXShellScriptBuildPhase section */
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<Scheme
|
<Scheme
|
||||||
LastUpgradeVersion = "0810"
|
LastUpgradeVersion = "0820"
|
||||||
version = "1.3">
|
version = "1.3">
|
||||||
<BuildAction
|
<BuildAction
|
||||||
parallelizeBuildables = "YES"
|
parallelizeBuildables = "YES"
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<Scheme
|
<Scheme
|
||||||
LastUpgradeVersion = "0810"
|
LastUpgradeVersion = "0820"
|
||||||
version = "1.7">
|
version = "1.7">
|
||||||
<BuildAction
|
<BuildAction
|
||||||
parallelizeBuildables = "YES"
|
parallelizeBuildables = "YES"
|
||||||
|
|
|
@ -95,18 +95,20 @@ public class TokenStreamRewriter {
|
||||||
/** Token buffer index. */
|
/** Token buffer index. */
|
||||||
internal var index: Int
|
internal var index: Int
|
||||||
internal var text: String?
|
internal var text: String?
|
||||||
weak var tokens: TokenStream!
|
|
||||||
internal var lastIndex: Int = 0
|
internal var lastIndex: Int = 0
|
||||||
|
internal weak var tokens: TokenStream!
|
||||||
|
|
||||||
init(_ index: Int, _ tokens: TokenStream) {
|
init(_ index: Int, _ tokens: TokenStream) {
|
||||||
self.index = index
|
self.index = index
|
||||||
self.tokens = tokens
|
self.tokens = tokens
|
||||||
}
|
}
|
||||||
//_ tokens : TokenStream ,_ tokens : TokenStream
|
|
||||||
init(_ index: Int, _ text: String?, _ tokens: TokenStream) {
|
init(_ index: Int, _ text: String?, _ tokens: TokenStream) {
|
||||||
self.index = index
|
self.index = index
|
||||||
self.text = text
|
self.text = text
|
||||||
self.tokens = tokens
|
self.tokens = tokens
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Execute the rewrite operation by possibly adding to the buffer.
|
/** Execute the rewrite operation by possibly adding to the buffer.
|
||||||
* Return the index of the next token to operate on.
|
* Return the index of the next token to operate on.
|
||||||
*/
|
*/
|
||||||
|
@ -115,10 +117,8 @@ public class TokenStreamRewriter {
|
||||||
}
|
}
|
||||||
|
|
||||||
public var description: String {
|
public var description: String {
|
||||||
let opName: String = NSStringFromClass(RewriteOperation.self)
|
let opName = String(describing: type(of: self))
|
||||||
// var index : Int = opName.indexOf("$");
|
return "<\(opName)@\(try! tokens.get(index)):\"\(text!)\">"
|
||||||
// opName = opName.substring( index+1);
|
|
||||||
return "<\(opName) @ \(try? tokens.get(index)):\\\(text)\">"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -165,11 +165,10 @@ public class TokenStreamRewriter {
|
||||||
override
|
override
|
||||||
public var description: String {
|
public var description: String {
|
||||||
if text == nil {
|
if text == nil {
|
||||||
return "<DeleteOp@\(try? tokens.get(index))..\(try? tokens.get(lastIndex))>"
|
return "<DeleteOp@\(try! tokens.get(index))..\(try! tokens.get(lastIndex))>"
|
||||||
}
|
}
|
||||||
return "<ReplaceOp@\(try? tokens.get(index))..\(try? tokens.get(lastIndex)):\\\(text)>"
|
return "<ReplaceOp@\(try! tokens.get(index))..\(try! tokens.get(lastIndex)):\"\(text!)\">"
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public class RewriteOperationArray{
|
public class RewriteOperationArray{
|
||||||
|
@ -288,7 +287,8 @@ public class TokenStreamRewriter {
|
||||||
rop.lastIndex = max(prevRop.lastIndex, rop.lastIndex)
|
rop.lastIndex = max(prevRop.lastIndex, rop.lastIndex)
|
||||||
print("new rop \(rop)")
|
print("new rop \(rop)")
|
||||||
} else if !disjoint {
|
} else if !disjoint {
|
||||||
throw ANTLRError.illegalArgument(msg: "replace op boundaries of \(rop.description) overlap with previous \(prevRop.description)")
|
throw ANTLRError.illegalArgument(msg: "replace op boundaries of \(rop.description) " +
|
||||||
|
"overlap with previous \(prevRop.description)")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -333,7 +333,8 @@ public class TokenStreamRewriter {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if iop.index >= rop.index && iop.index <= rop.lastIndex {
|
if iop.index >= rop.index && iop.index <= rop.lastIndex {
|
||||||
throw ANTLRError.illegalArgument(msg: "insert op \(iop.description) within boundaries of previous \(rop.description)")
|
throw ANTLRError.illegalArgument(msg: "insert op \(iop.description) within" +
|
||||||
|
" boundaries of previous \(rop.description)")
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -199,7 +199,6 @@ class TokenStreamRewriterTests: XCTestCase {
|
||||||
XCTAssertEqual(expecting, result)
|
XCTAssertEqual(expecting, result)
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: tweak printing
|
|
||||||
func testInsertInPriorReplace() throws {
|
func testInsertInPriorReplace() throws {
|
||||||
let input = ANTLRInputStream("abc")
|
let input = ANTLRInputStream("abc")
|
||||||
let lexer = LexerA(input)
|
let lexer = LexerA(input)
|
||||||
|
@ -209,9 +208,9 @@ class TokenStreamRewriterTests: XCTestCase {
|
||||||
try tokens.replace(0, 2, "x")
|
try tokens.replace(0, 2, "x")
|
||||||
tokens.insertBefore(1, "0")
|
tokens.insertBefore(1, "0")
|
||||||
|
|
||||||
var err: Error?
|
|
||||||
do {
|
do {
|
||||||
_ = try tokens.getText()
|
_ = try tokens.getText()
|
||||||
|
XCTFail("Expected exception not thrown.")
|
||||||
} catch ANTLRError.illegalArgument(let msg) {
|
} catch ANTLRError.illegalArgument(let msg) {
|
||||||
let expecting = "insert op <InsertBeforeOp@[@1,1:1='b',<2>,1:1]:\"0\"> within boundaries of previous <ReplaceOp@[@0,0:0='a',<1>,1:0]..[@2,2:2='c',<3>,1:2]:\"x\">"
|
let expecting = "insert op <InsertBeforeOp@[@1,1:1='b',<2>,1:1]:\"0\"> within boundaries of previous <ReplaceOp@[@0,0:0='a',<1>,1:0]..[@2,2:2='c',<3>,1:2]:\"x\">"
|
||||||
|
|
||||||
|
@ -311,7 +310,6 @@ class TokenStreamRewriterTests: XCTestCase {
|
||||||
XCTAssertEqual(expecting, result)
|
XCTAssertEqual(expecting, result)
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: tweak printing
|
|
||||||
func testReplaceRangeThenInsertAtRightEdge() throws {
|
func testReplaceRangeThenInsertAtRightEdge() throws {
|
||||||
let input = ANTLRInputStream("abcccba")
|
let input = ANTLRInputStream("abcccba")
|
||||||
let lexer = LexerA(input)
|
let lexer = LexerA(input)
|
||||||
|
@ -321,9 +319,9 @@ class TokenStreamRewriterTests: XCTestCase {
|
||||||
try tokens.replace(2, 4, "x")
|
try tokens.replace(2, 4, "x")
|
||||||
tokens.insertBefore(4, "y")
|
tokens.insertBefore(4, "y")
|
||||||
|
|
||||||
var err: Error?
|
|
||||||
do {
|
do {
|
||||||
_ = try tokens.getText()
|
_ = try tokens.getText()
|
||||||
|
XCTFail("Expected exception not thrown.")
|
||||||
} catch ANTLRError.illegalArgument(let msg) {
|
} catch ANTLRError.illegalArgument(let msg) {
|
||||||
let expecting = "insert op <InsertBeforeOp@[@4,4:4='c',<3>,1:4]:\"y\"> within boundaries of previous <ReplaceOp@[@2,2:2='c',<3>,1:2]..[@4,4:4='c',<3>,1:4]:\"x\">"
|
let expecting = "insert op <InsertBeforeOp@[@4,4:4='c',<3>,1:4]:\"y\"> within boundaries of previous <ReplaceOp@[@2,2:2='c',<3>,1:2]..[@4,4:4='c',<3>,1:4]:\"x\">"
|
||||||
|
|
||||||
|
@ -368,43 +366,41 @@ class TokenStreamRewriterTests: XCTestCase {
|
||||||
XCTAssertEqual(expecting, result)
|
XCTAssertEqual(expecting, result)
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: tweak printing
|
func testReplaceThenReplaceSuperset() throws {
|
||||||
func testReplaceThenReplaceSuperset() throws {
|
let input = ANTLRInputStream("abcccba")
|
||||||
let input = ANTLRInputStream("abcccba")
|
let lexer = LexerA(input)
|
||||||
let lexer = LexerA(input)
|
let stream = CommonTokenStream(lexer)
|
||||||
let stream = CommonTokenStream(lexer)
|
try stream.fill()
|
||||||
try stream.fill()
|
let tokens = TokenStreamRewriter(stream)
|
||||||
let tokens = TokenStreamRewriter(stream)
|
try tokens.replace(2, 4, "xyz")
|
||||||
try tokens.replace(2, 4, "xyz")
|
try tokens.replace(3, 5, "foo")
|
||||||
try tokens.replace(3, 5, "foo")
|
|
||||||
|
|
||||||
var err: Error?
|
do {
|
||||||
do {
|
_ = try tokens.getText()
|
||||||
_ = try tokens.getText()
|
XCTFail("Expected exception not thrown.")
|
||||||
} catch ANTLRError.illegalArgument(let msg) {
|
} catch ANTLRError.illegalArgument(let msg) {
|
||||||
let expecting = "replace op boundaries of <ReplaceOp@[@3,3:3='c',<3>,1:3]..[@5,5:5='b',<2>,1:5]:\"foo\"> overlap with previous <ReplaceOp@[@2,2:2='c',<3>,1:2]..[@4,4:4='c',<3>,1:4]:\"xyz\">"
|
let expecting = "replace op boundaries of <ReplaceOp@[@3,3:3='c',<3>,1:3]..[@5,5:5='b',<2>,1:5]:\"foo\"> overlap with previous <ReplaceOp@[@2,2:2='c',<3>,1:2]..[@4,4:4='c',<3>,1:4]:\"xyz\">"
|
||||||
XCTAssertEqual(expecting, msg)
|
XCTAssertEqual(expecting, msg)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: tweak printing
|
func testReplaceThenReplaceLowerIndexedSuperset() throws {
|
||||||
func testReplaceThenReplaceLowerIndexedSuperset() throws {
|
let input = ANTLRInputStream("abcccba")
|
||||||
let input = ANTLRInputStream("abcccba")
|
let lexer = LexerA(input)
|
||||||
let lexer = LexerA(input)
|
let stream = CommonTokenStream(lexer)
|
||||||
let stream = CommonTokenStream(lexer)
|
try stream.fill()
|
||||||
try stream.fill()
|
let tokens = TokenStreamRewriter(stream)
|
||||||
let tokens = TokenStreamRewriter(stream)
|
try tokens.replace(2, 4, "xyz")
|
||||||
try tokens.replace(2, 4, "xyz")
|
try tokens.replace(1, 3, "foo")
|
||||||
try tokens.replace(1, 3, "foo")
|
|
||||||
|
|
||||||
var err: Error?
|
do {
|
||||||
do {
|
_ = try tokens.getText()
|
||||||
_ = try tokens.getText()
|
XCTFail("Expected exception not thrown.")
|
||||||
} catch ANTLRError.illegalArgument(let msg) {
|
} catch ANTLRError.illegalArgument(let msg) {
|
||||||
let expecting = "replace op boundaries of <ReplaceOp@[@1,1:1='b',<2>,1:1]..[@3,3:3='c',<3>,1:3]:\"foo\"> overlap with previous <ReplaceOp@[@2,2:2='c',<3>,1:2]..[@4,4:4='c',<3>,1:4]:\"xyz\">"
|
let expecting = "replace op boundaries of <ReplaceOp@[@1,1:1='b',<2>,1:1]..[@3,3:3='c',<3>,1:3]:\"foo\"> overlap with previous <ReplaceOp@[@2,2:2='c',<3>,1:2]..[@4,4:4='c',<3>,1:4]:\"xyz\">"
|
||||||
XCTAssertEqual(expecting, msg)
|
XCTAssertEqual(expecting, msg)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func testReplaceSingleMiddleThenOverlappingSuperset() throws {
|
func testReplaceSingleMiddleThenOverlappingSuperset() throws {
|
||||||
let input = ANTLRInputStream("abcba")
|
let input = ANTLRInputStream("abcba")
|
||||||
|
@ -519,9 +515,9 @@ class TokenStreamRewriterTests: XCTestCase {
|
||||||
try stream.fill()
|
try stream.fill()
|
||||||
// cannot split earlier replace
|
// cannot split earlier replace
|
||||||
|
|
||||||
var err: Error?
|
|
||||||
do {
|
do {
|
||||||
_ = try tokens.getText()
|
_ = try tokens.getText()
|
||||||
|
XCTFail("Expected exception not thrown.")
|
||||||
} catch ANTLRError.illegalArgument(let msg) {
|
} catch ANTLRError.illegalArgument(let msg) {
|
||||||
let expecting = "replace op boundaries of <ReplaceOp@[@1,1:1='b',<2>,1:1]..[@2,2:2='c',<3>,1:2]:\"foo\"> overlap with previous <ReplaceOp@[@0,0:0='a',<1>,1:0]..[@3,3:3='c',<3>,1:3]:\"bar\">"
|
let expecting = "replace op boundaries of <ReplaceOp@[@1,1:1='b',<2>,1:1]..[@2,2:2='c',<3>,1:2]:\"foo\"> overlap with previous <ReplaceOp@[@0,0:0='a',<1>,1:0]..[@3,3:3='c',<3>,1:3]:\"bar\">"
|
||||||
XCTAssertEqual(expecting, msg)
|
XCTAssertEqual(expecting, msg)
|
||||||
|
@ -627,7 +623,6 @@ class TokenStreamRewriterTests: XCTestCase {
|
||||||
XCTAssertEqual(expecting, result)
|
XCTAssertEqual(expecting, result)
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Test Fix for https://github.com/antlr/antlr4/issues/550
|
|
||||||
func testDistinguishBetweenInsertAfterAndInsertBeforeToPreserverOrder() throws {
|
func testDistinguishBetweenInsertAfterAndInsertBeforeToPreserverOrder() throws {
|
||||||
let input = ANTLRInputStream("aa")
|
let input = ANTLRInputStream("aa")
|
||||||
let lexer = LexerA(input)
|
let lexer = LexerA(input)
|
||||||
|
|
Loading…
Reference in New Issue