Skip to content

Commit

Permalink
Refactor RpgParser.NumberContext.toAst as suggested by TODO
Browse files Browse the repository at this point in the history
  • Loading branch information
lanarimarco committed Jan 24, 2024
1 parent 316fc0f commit e40121b
Showing 1 changed file with 1 addition and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -85,21 +85,7 @@ internal fun RpgParser.LiteralContext.toAst(conf: ToAstConfiguration = ToAstConf
internal fun RpgParser.NumberContext.toAst(conf: ToAstConfiguration = ToAstConfiguration()): NumberLiteral {
val position = this.toPosition(conf.considerPosition)
require(this.NumberPart().isEmpty()) { "Number not empty $position" }
val text = (this.MINUS()?.text ?: "") + this.NUMBER().text

// When assigning a value to a numeric field we could either use
// a comma or a dot as decimal separators

// TODO Rifattorizzare con literalToNumber(text, position)
return when {
text.contains('.') -> {
text.toRealLiteral(position, Locale.US)
}
text.contains(',') -> {
text.toRealLiteral(position, Locale.ITALIAN)
}
else -> text.toIntLiteral(position)
}
return literalToNumber(this.text, position)
}

fun String.toRealLiteral(position: Position?, locale: Locale): RealLiteral {
Expand Down

0 comments on commit e40121b

Please sign in to comment.