vfmt2: fix literal integer number formatting

pull/4050/head
Delyan Angelov 2020-03-17 03:49:15 +02:00 committed by GitHub
parent cff6f4abd6
commit f73b38a0d8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 13 additions and 9 deletions

View File

@ -40,7 +40,7 @@ pub:
pub struct IntegerLiteral { pub struct IntegerLiteral {
pub: pub:
val int val string
} }
pub struct FloatLiteral { pub struct FloatLiteral {

View File

@ -69,9 +69,9 @@ pub fn (x Expr) str() string {
*/ */
IntegerLiteral { IntegerLiteral {
return it.val.str() return it.val
} }
IntegerLiteral { StringLiteral {
return '"$it.val"' return '"$it.val"'
} }
else { else {

View File

@ -492,7 +492,7 @@ pub fn (c mut Checker) array_init(array_init mut ast.ArrayInit) table.Type {
mut fixed_size := 1 mut fixed_size := 1
match array_init.exprs[0] { match array_init.exprs[0] {
ast.IntegerLiteral { ast.IntegerLiteral {
fixed_size = it.val fixed_size = it.val.int()
} }
else { else {
c.error('expecting `int` for fixed size', array_init.pos) c.error('expecting `int` for fixed size', array_init.pos)

View File

@ -433,7 +433,7 @@ fn (f mut Fmt) expr(node ast.Expr) {
f.write(']') f.write(']')
} }
ast.IntegerLiteral { ast.IntegerLiteral {
f.write(it.val.str()) f.write(it.val)
} }
ast.MapInit { ast.MapInit {
f.writeln('{') f.writeln('{')

View File

@ -0,0 +1,4 @@
fn main() {
x := 0xdeadbeef
u := 9978654321
}

View File

@ -747,7 +747,7 @@ fn (g mut Gen) expr(node ast.Expr) {
g.infix_expr(it) g.infix_expr(it)
} }
ast.IntegerLiteral { ast.IntegerLiteral {
g.write(it.val.str()) g.write(it.val.int().str())
} }
ast.MatchExpr { ast.MatchExpr {
g.match_expr(it) g.match_expr(it)

View File

@ -108,7 +108,7 @@ fn (g mut JsGen) expr(node ast.Expr) {
// println('cgen expr()') // println('cgen expr()')
match node { match node {
ast.IntegerLiteral { ast.IntegerLiteral {
g.write(it.val.str()) g.write(it.val)
} }
ast.FloatLiteral { ast.FloatLiteral {
g.write(it.val) g.write(it.val)

View File

@ -1310,7 +1310,7 @@ fn (p mut Parser) parse_number_literal() ast.Expr {
} }
else { else {
node = ast.IntegerLiteral{ node = ast.IntegerLiteral{
val: lit.int() val: lit
} }
} }
p.next() p.next()