Skip to content

Commit

Permalink
Char fixes;
Browse files Browse the repository at this point in the history
  • Loading branch information
alexeev509 committed Mar 13, 2024
1 parent cb65cef commit acd1a68
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -277,14 +277,15 @@ class ExpressionVisitor(
}

fun convertBinHexOctToPrimitives(num: String, type: String): Number {
val isInt = "i".equals(type)
val result: Number = if (num.startsWith(HEX_PREFIX)) {
if ("i".equals(type)) parseInt(num.drop(2), 16) else parseLong(num.drop(2), 16)
if (isInt) parseInt(num.drop(2), 16) else parseLong(num.drop(2), 16)
} else if (num.startsWith(BIN_PREFIX)) {
if ("i".equals(type)) parseInt(num.drop(2), 2) else parseLong(num.drop(2), 2)
if (isInt) parseInt(num.drop(2), 2) else parseLong(num.drop(2), 2)
} else if (num.startsWith(OCT_PREFIX) && num.length > 1) {
if ("i".equals(type)) parseInt(num.drop(1), 8) else parseLong(num.drop(1), 8)
if (isInt) parseInt(num.drop(1), 8) else parseLong(num.drop(1), 8)
} else {
if ("i".equals(type)) num.toInt() else num.toLong()
if (isInt) num.toInt() else num.toLong()
}
return result;
}
Expand Down
5 changes: 2 additions & 3 deletions src/test/testdata/expected/lsl/charLiterals.lsl
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ typealias Char = char;
automaton A : Int {
var ch1: Char = 'A';
var ch2: Char = 'a';
var ch3: Char = 52;
var ch3: Char = '狐';
var ch4: Char = '*';
var ch5: Char = '';
var ch6: Char = 'S';
var ch5: Char = 'S';
}
5 changes: 2 additions & 3 deletions src/test/testdata/lsl/charLiterals.lsl
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ typealias Char = char;
automaton A : Int {
var ch1: Char = '\u0041';
var ch2: Char = 'a';
var ch3: Char = 52;
var ch3: Char = '\u72D0';
var ch4: Char = '\52';
var ch5: Char = '\5';
var ch6: Char = '\123';
var ch5: Char = '\123';
}

0 comments on commit acd1a68

Please sign in to comment.