Merge pull request #2113 from ewanmellor/swift-makereadonly

[Swift] Replace IntervalSet.setReadonly with makeReadonly.
This commit is contained in:
Terence Parr 2017-11-29 09:53:40 -08:00 committed by GitHub
commit aaca1b9f3c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 11 deletions

View File

@ -85,13 +85,12 @@ public class ATN {
/// rule.
///
public func nextTokens(_ s: ATNState) -> IntervalSet {
if let nextTokenWithinRule = s.nextTokenWithinRule
{
if let nextTokenWithinRule = s.nextTokenWithinRule {
return nextTokenWithinRule
}
let intervalSet = nextTokens(s, nil)
s.nextTokenWithinRule = intervalSet
try! intervalSet.setReadonly(true)
intervalSet.makeReadonly()
return intervalSet
}

View File

@ -22,13 +22,13 @@ public class IntervalSet: IntSet, Hashable, CustomStringConvertible {
public static let COMPLETE_CHAR_SET: IntervalSet =
{
let set = IntervalSet.of(Lexer.MIN_CHAR_VALUE, Lexer.MAX_CHAR_VALUE)
try! set.setReadonly(true)
set.makeReadonly()
return set
}()
public static let EMPTY_SET: IntervalSet = {
let set = IntervalSet()
try! set.setReadonly(true)
set.makeReadonly()
return set
}()
@ -704,12 +704,8 @@ public class IntervalSet: IntSet, Hashable, CustomStringConvertible {
return readonly
}
public func setReadonly(_ readonly: Bool) throws {
if self.readonly && !readonly {
throw ANTLRError.illegalState(msg: "can't alter readonly IntervalSet")
}
self.readonly = readonly
public func makeReadonly() {
readonly = true
}
}