mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
fmt: simplify IndexExpr
processing
This commit is contained in:
parent
a678be7195
commit
5a5f4ce99a
@ -402,7 +402,10 @@ fn (f mut Fmt) expr(node ast.Expr) {
|
||||
f.expr(it.right)
|
||||
}
|
||||
ast.IndexExpr {
|
||||
f.index_expr(it)
|
||||
f.expr(it.left)
|
||||
f.write('[')
|
||||
f.expr(it.index)
|
||||
f.write(']')
|
||||
}
|
||||
ast.IntegerLiteral {
|
||||
f.write(it.val.str())
|
||||
@ -471,6 +474,11 @@ fn (f mut Fmt) expr(node ast.Expr) {
|
||||
f.write(it.op.str())
|
||||
f.expr(it.right)
|
||||
}
|
||||
ast.RangeExpr {
|
||||
f.expr(it.low)
|
||||
f.write('..')
|
||||
f.expr(it.high)
|
||||
}
|
||||
ast.SelectorExpr {
|
||||
f.expr(it.expr)
|
||||
f.write('.')
|
||||
@ -512,25 +520,3 @@ fn (f mut Fmt) wrap_long_line() {
|
||||
f.line_len = 0
|
||||
}
|
||||
}
|
||||
|
||||
fn (f mut Fmt) index_expr(node ast.IndexExpr) {
|
||||
mut is_range := false
|
||||
match node.index {
|
||||
ast.RangeExpr {
|
||||
is_range = true
|
||||
f.expr(node.left)
|
||||
f.write('[')
|
||||
f.expr(it.low)
|
||||
f.write('..')
|
||||
f.expr(it.high)
|
||||
f.write(']')
|
||||
}
|
||||
else {}
|
||||
}
|
||||
if !is_range {
|
||||
f.expr(node.left)
|
||||
f.write('[')
|
||||
f.expr(node.index)
|
||||
f.write(']')
|
||||
}
|
||||
}
|
||||
|
@ -56,8 +56,14 @@ fn new_user() User {
|
||||
}
|
||||
|
||||
[inline]
|
||||
fn fn_contains_range_expr() {
|
||||
a := 1 in arr[0..2]
|
||||
fn fn_contains_index_expr() {
|
||||
a := 1 in arr[0..]
|
||||
b := 1 in arr[..2]
|
||||
c := 1 in arr[1..3]
|
||||
d := arr[2]
|
||||
e := arr[2..]
|
||||
f := arr[..2]
|
||||
g := arr[1..3]
|
||||
}
|
||||
|
||||
fn voidfn() {
|
||||
|
@ -59,8 +59,14 @@ User
|
||||
|
||||
|
||||
[inline]
|
||||
fn fn_contains_range_expr() {
|
||||
a:=1 in arr[0..2]
|
||||
fn fn_contains_index_expr() {
|
||||
a := 1 in arr[0..]
|
||||
b := 1 in arr[..2]
|
||||
c := 1 in arr[1..3]
|
||||
d := arr[2]
|
||||
e := arr[2..]
|
||||
f := arr[..2]
|
||||
g := arr[1..3]
|
||||
}
|
||||
|
||||
fn voidfn(){
|
||||
|
Loading…
Reference in New Issue
Block a user