mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
fmt: remove redundant parenthesis in the complex infix expr (#17873)
This commit is contained in:
parent
8452644ec3
commit
467a1b4435
@ -169,7 +169,7 @@ fn (vd VDoc) write_content(cn &doc.DocNode, d &doc.Doc, mut hw strings.Builder)
|
||||
os.file_name(cn.file_path)
|
||||
}
|
||||
src_link := get_src_link(vd.manifest.repo_url, file_path_name, cn.pos.line_nr + 1)
|
||||
if cn.content.len != 0 || (cn.name == 'Constants') {
|
||||
if cn.content.len != 0 || cn.name == 'Constants' {
|
||||
hw.write_string(doc_node_html(cn, src_link, false, cfg.include_examples, d.table))
|
||||
}
|
||||
for child in cn.children {
|
||||
|
@ -260,7 +260,7 @@ fn (mut context Context) print_status() {
|
||||
if context.is_silent {
|
||||
return
|
||||
}
|
||||
if (context.cut_index == 1) && (context.max_index == 0) {
|
||||
if context.cut_index == 1 && context.max_index == 0 {
|
||||
return
|
||||
}
|
||||
msg := '> ${context.path:-30} | index: ${context.cut_index:5}/${context.max_index - 1:5}'
|
||||
|
@ -37,7 +37,7 @@ fn (mut g Game) evolve() {
|
||||
temp_grid << []string{}
|
||||
for y in 0 .. g.grid[x].len {
|
||||
count := g.get_surrounding_alive_count(x, y)
|
||||
if count == 3 || ((g.grid[x][y] == cell) && count == 2) {
|
||||
if count == 3 || (g.grid[x][y] == cell && count == 2) {
|
||||
temp_grid[x] << cell
|
||||
} else {
|
||||
temp_grid[x] << nothing
|
||||
|
@ -74,7 +74,7 @@ fn bellman_ford[T](graph [][]T, src int) {
|
||||
mut u := edges[j].src
|
||||
mut v := edges[j].dest
|
||||
mut weight := edges[j].weight
|
||||
if (dist[u] != large) && (dist[u] + weight < dist[v]) {
|
||||
if dist[u] != large && dist[u] + weight < dist[v] {
|
||||
dist[v] = dist[u] + weight
|
||||
}
|
||||
}
|
||||
@ -88,7 +88,7 @@ fn bellman_ford[T](graph [][]T, src int) {
|
||||
mut u := edges[j].src
|
||||
mut v := edges[j].dest
|
||||
mut weight := edges[j].weight
|
||||
if (dist[u] != large) && (dist[u] + weight < dist[v]) {
|
||||
if dist[u] != large && dist[u] + weight < dist[v] {
|
||||
print('\n Graph contains negative weight cycle')
|
||||
// If negative cycle is detected, simply
|
||||
// return or an exit(1)
|
||||
|
@ -77,7 +77,7 @@ fn build_path_reverse(graph map[string][]string, start string, final string, vis
|
||||
|
||||
for (current != start) {
|
||||
for i in array_of_nodes {
|
||||
if (current in graph[i]) && (visited[i] == true) {
|
||||
if current in graph[i] && visited[i] == true {
|
||||
current = i
|
||||
break // the first ocurrence is enough
|
||||
}
|
||||
|
@ -91,7 +91,7 @@ fn build_path_reverse(graph map[string][]string, start string, final string, vis
|
||||
|
||||
for current != start {
|
||||
for i in array_of_nodes {
|
||||
if (current in graph[i]) && (visited[i] == true) {
|
||||
if current in graph[i] && visited[i] == true {
|
||||
current = i
|
||||
break // the first ocurrence is enough
|
||||
}
|
||||
|
@ -41,7 +41,7 @@ fn push_pq[T](mut prior_queue []T, data int, priority int) {
|
||||
lenght_pq := prior_queue.len
|
||||
|
||||
mut i := 0
|
||||
for (i < lenght_pq) && (priority > prior_queue[i].priority) {
|
||||
for i < lenght_pq && priority > prior_queue[i].priority {
|
||||
temp << prior_queue[i]
|
||||
i++
|
||||
}
|
||||
|
@ -35,7 +35,7 @@ fn push_pq[T](mut prior_queue []T, data int, priority int) {
|
||||
lenght_pq := prior_queue.len
|
||||
|
||||
mut i := 0
|
||||
for (i < lenght_pq) && (priority > prior_queue[i].priority) {
|
||||
for i < lenght_pq && priority > prior_queue[i].priority {
|
||||
temp << prior_queue[i]
|
||||
i++
|
||||
}
|
||||
|
@ -831,7 +831,7 @@ fn test_split_into_lines() {
|
||||
|
||||
assert lines_mixed_trailers.len == 9
|
||||
for line in lines_mixed_trailers {
|
||||
assert (line == line_content) || (line == '')
|
||||
assert line == line_content || line == ''
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1019,7 +1019,7 @@ pub fn (s string) split_into_lines() []string {
|
||||
line_start = i + 1
|
||||
} else if s[i] == cr {
|
||||
res << if line_start == i { '' } else { s[line_start..i] }
|
||||
if ((i + 1) < s.len) && (s[i + 1] == lf) {
|
||||
if (i + 1) < s.len && s[i + 1] == lf {
|
||||
line_start = i + 2
|
||||
} else {
|
||||
line_start = i + 1
|
||||
@ -1796,7 +1796,7 @@ fn (s string) at_with_check(idx int) ?u8 {
|
||||
pub fn (c u8) is_space() bool {
|
||||
// 0x85 is NEXT LINE (NEL)
|
||||
// 0xa0 is NO-BREAK SPACE
|
||||
return c == 32 || (c > 8 && c < 14) || (c == 0x85) || (c == 0xa0)
|
||||
return c == 32 || (c > 8 && c < 14) || c == 0x85 || c == 0xa0
|
||||
}
|
||||
|
||||
// is_digit returns `true` if the byte is in range 0-9 and `false` otherwise.
|
||||
|
@ -1054,7 +1054,7 @@ fn test_split_into_lines() {
|
||||
|
||||
assert lines_mixed_trailers.len == 9
|
||||
for line in lines_mixed_trailers {
|
||||
assert (line == line_content) || (line == '')
|
||||
assert line == line_content || line == ''
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -49,7 +49,7 @@ pub fn (mut q Quadtree) insert(p AABB) {
|
||||
|
||||
q.particles << p
|
||||
|
||||
if (q.particles.len > q.capacity) && (q.level < q.depth) {
|
||||
if q.particles.len > q.capacity && q.level < q.depth {
|
||||
if q.nodes.len == 0 {
|
||||
q.split()
|
||||
}
|
||||
|
@ -76,7 +76,7 @@ fn (w &Writer) field_needs_quotes(field string) bool {
|
||||
if field == '' {
|
||||
return false
|
||||
}
|
||||
if field.contains(w.delimiter.ascii_str()) || (field.index_any('"\r\n') != -1) {
|
||||
if field.contains(w.delimiter.ascii_str()) || field.index_any('"\r\n') != -1 {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
|
@ -212,42 +212,41 @@ Private functions
|
||||
// Raw to_lower utf-8 function
|
||||
fn utf8_to_lower(in_cp int) int {
|
||||
mut cp := in_cp
|
||||
if ((0x0041 <= cp) && (0x005a >= cp)) || ((0x00c0 <= cp) && (0x00d6 >= cp))
|
||||
|| ((0x00d8 <= cp) && (0x00de >= cp)) || ((0x0391 <= cp) && (0x03a1 >= cp))
|
||||
|| ((0x03a3 <= cp) && (0x03ab >= cp)) || ((0x0410 <= cp) && (0x042f >= cp)) {
|
||||
if (0x0041 <= cp && 0x005a >= cp) || (0x00c0 <= cp && 0x00d6 >= cp)
|
||||
|| (0x00d8 <= cp && 0x00de >= cp) || (0x0391 <= cp && 0x03a1 >= cp)
|
||||
|| (0x03a3 <= cp && 0x03ab >= cp) || (0x0410 <= cp && 0x042f >= cp) {
|
||||
cp += 32
|
||||
} else if (0x0400 <= cp) && (0x040f >= cp) {
|
||||
} else if 0x0400 <= cp && 0x040f >= cp {
|
||||
cp += 80
|
||||
} else if ((0x0100 <= cp) && (0x012f >= cp)) || ((0x0132 <= cp) && (0x0137 >= cp))
|
||||
|| ((0x014a <= cp) && (0x0177 >= cp)) || ((0x0182 <= cp) && (0x0185 >= cp))
|
||||
|| ((0x01a0 <= cp) && (0x01a5 >= cp)) || ((0x01de <= cp) && (0x01ef >= cp))
|
||||
|| ((0x01f8 <= cp) && (0x021f >= cp)) || ((0x0222 <= cp) && (0x0233 >= cp))
|
||||
|| ((0x0246 <= cp) && (0x024f >= cp)) || ((0x03d8 <= cp) && (0x03ef >= cp))
|
||||
|| ((0x0460 <= cp) && (0x0481 >= cp)) || ((0x048a <= cp) && (0x04ff >= cp)) {
|
||||
} else if (0x0100 <= cp && 0x012f >= cp) || (0x0132 <= cp && 0x0137 >= cp)
|
||||
|| (0x014a <= cp && 0x0177 >= cp) || (0x0182 <= cp && 0x0185 >= cp)
|
||||
|| (0x01a0 <= cp && 0x01a5 >= cp) || (0x01de <= cp && 0x01ef >= cp)
|
||||
|| (0x01f8 <= cp && 0x021f >= cp) || (0x0222 <= cp && 0x0233 >= cp)
|
||||
|| (0x0246 <= cp && 0x024f >= cp) || (0x03d8 <= cp && 0x03ef >= cp)
|
||||
|| (0x0460 <= cp && 0x0481 >= cp) || (0x048a <= cp && 0x04ff >= cp) {
|
||||
cp |= 0x1
|
||||
} else if ((0x0139 <= cp) && (0x0148 >= cp)) || ((0x0179 <= cp) && (0x017e >= cp))
|
||||
|| ((0x01af <= cp) && (0x01b0 >= cp)) || ((0x01b3 <= cp) && (0x01b6 >= cp))
|
||||
|| ((0x01cd <= cp) && (0x01dc >= cp)) {
|
||||
} else if (0x0139 <= cp && 0x0148 >= cp) || (0x0179 <= cp && 0x017e >= cp)
|
||||
|| (0x01af <= cp && 0x01b0 >= cp) || (0x01b3 <= cp && 0x01b6 >= cp)
|
||||
|| (0x01cd <= cp && 0x01dc >= cp) {
|
||||
cp += 1
|
||||
cp &= ~0x1
|
||||
} else if ((0x0531 <= cp) && (0x0556 >= cp)) || ((0x10A0 <= cp) && (0x10C5 >= cp)) {
|
||||
} else if (0x0531 <= cp && 0x0556 >= cp) || (0x10A0 <= cp && 0x10C5 >= cp) {
|
||||
// ARMENIAN or GEORGIAN
|
||||
cp += 0x30
|
||||
} else if (((0x1E00 <= cp) && (0x1E94 >= cp)) || ((0x1EA0 <= cp) && (0x1EF8 >= cp)))
|
||||
&& (cp & 1 == 0) {
|
||||
} else if ((0x1E00 <= cp && 0x1E94 >= cp) || (0x1EA0 <= cp && 0x1EF8 >= cp)) && cp & 1 == 0 {
|
||||
// LATIN CAPITAL LETTER
|
||||
cp += 1
|
||||
} else if (0x24B6 <= cp) && (0x24CF >= cp) {
|
||||
} else if 0x24B6 <= cp && 0x24CF >= cp {
|
||||
// CIRCLED LATIN
|
||||
cp += 0x1a
|
||||
} else if (0xFF21 <= cp) && (0xFF3A >= cp) {
|
||||
} else if 0xFF21 <= cp && 0xFF3A >= cp {
|
||||
// FULLWIDTH LATIN CAPITAL
|
||||
cp += 0x19
|
||||
} else if ((0x1F08 <= cp) && (0x1F0F >= cp)) || ((0x1F18 <= cp) && (0x1F1D >= cp))
|
||||
|| ((0x1F28 <= cp) && (0x1F2F >= cp)) || ((0x1F38 <= cp) && (0x1F3F >= cp))
|
||||
|| ((0x1F48 <= cp) && (0x1F4D >= cp)) || ((0x1F68 <= cp) && (0x1F6F >= cp))
|
||||
|| ((0x1F88 <= cp) && (0x1F8F >= cp)) || ((0x1F98 <= cp) && (0x1F9F >= cp))
|
||||
|| ((0x1FA8 <= cp) && (0x1FAF >= cp)) {
|
||||
} else if (0x1F08 <= cp && 0x1F0F >= cp) || (0x1F18 <= cp && 0x1F1D >= cp)
|
||||
|| (0x1F28 <= cp && 0x1F2F >= cp) || (0x1F38 <= cp && 0x1F3F >= cp)
|
||||
|| (0x1F48 <= cp && 0x1F4D >= cp) || (0x1F68 <= cp && 0x1F6F >= cp)
|
||||
|| (0x1F88 <= cp && 0x1F8F >= cp) || (0x1F98 <= cp && 0x1F9F >= cp)
|
||||
|| (0x1FA8 <= cp && 0x1FAF >= cp) {
|
||||
// GREEK
|
||||
cp -= 8
|
||||
} else {
|
||||
@ -315,42 +314,41 @@ fn utf8_to_lower(in_cp int) int {
|
||||
// Raw to_upper utf-8 function
|
||||
fn utf8_to_upper(in_cp int) int {
|
||||
mut cp := in_cp
|
||||
if ((0x0061 <= cp) && (0x007a >= cp)) || ((0x00e0 <= cp) && (0x00f6 >= cp))
|
||||
|| ((0x00f8 <= cp) && (0x00fe >= cp)) || ((0x03b1 <= cp) && (0x03c1 >= cp))
|
||||
|| ((0x03c3 <= cp) && (0x03cb >= cp)) || ((0x0430 <= cp) && (0x044f >= cp)) {
|
||||
if (0x0061 <= cp && 0x007a >= cp) || (0x00e0 <= cp && 0x00f6 >= cp)
|
||||
|| (0x00f8 <= cp && 0x00fe >= cp) || (0x03b1 <= cp && 0x03c1 >= cp)
|
||||
|| (0x03c3 <= cp && 0x03cb >= cp) || (0x0430 <= cp && 0x044f >= cp) {
|
||||
cp -= 32
|
||||
} else if (0x0450 <= cp) && (0x045f >= cp) {
|
||||
} else if 0x0450 <= cp && 0x045f >= cp {
|
||||
cp -= 80
|
||||
} else if ((0x0100 <= cp) && (0x012f >= cp)) || ((0x0132 <= cp) && (0x0137 >= cp))
|
||||
|| ((0x014a <= cp) && (0x0177 >= cp)) || ((0x0182 <= cp) && (0x0185 >= cp))
|
||||
|| ((0x01a0 <= cp) && (0x01a5 >= cp)) || ((0x01de <= cp) && (0x01ef >= cp))
|
||||
|| ((0x01f8 <= cp) && (0x021f >= cp)) || ((0x0222 <= cp) && (0x0233 >= cp))
|
||||
|| ((0x0246 <= cp) && (0x024f >= cp)) || ((0x03d8 <= cp) && (0x03ef >= cp))
|
||||
|| ((0x0460 <= cp) && (0x0481 >= cp)) || ((0x048a <= cp) && (0x04ff >= cp)) {
|
||||
} else if (0x0100 <= cp && 0x012f >= cp) || (0x0132 <= cp && 0x0137 >= cp)
|
||||
|| (0x014a <= cp && 0x0177 >= cp) || (0x0182 <= cp && 0x0185 >= cp)
|
||||
|| (0x01a0 <= cp && 0x01a5 >= cp) || (0x01de <= cp && 0x01ef >= cp)
|
||||
|| (0x01f8 <= cp && 0x021f >= cp) || (0x0222 <= cp && 0x0233 >= cp)
|
||||
|| (0x0246 <= cp && 0x024f >= cp) || (0x03d8 <= cp && 0x03ef >= cp)
|
||||
|| (0x0460 <= cp && 0x0481 >= cp) || (0x048a <= cp && 0x04ff >= cp) {
|
||||
cp &= ~0x1
|
||||
} else if ((0x0139 <= cp) && (0x0148 >= cp)) || ((0x0179 <= cp) && (0x017e >= cp))
|
||||
|| ((0x01af <= cp) && (0x01b0 >= cp)) || ((0x01b3 <= cp) && (0x01b6 >= cp))
|
||||
|| ((0x01cd <= cp) && (0x01dc >= cp)) {
|
||||
} else if (0x0139 <= cp && 0x0148 >= cp) || (0x0179 <= cp && 0x017e >= cp)
|
||||
|| (0x01af <= cp && 0x01b0 >= cp) || (0x01b3 <= cp && 0x01b6 >= cp)
|
||||
|| (0x01cd <= cp && 0x01dc >= cp) {
|
||||
cp -= 1
|
||||
cp |= 0x1
|
||||
} else if ((0x0561 <= cp) && (0x0586 >= cp)) || ((0x10D0 <= cp) && (0x10F5 >= cp)) {
|
||||
} else if (0x0561 <= cp && 0x0586 >= cp) || (0x10D0 <= cp && 0x10F5 >= cp) {
|
||||
// ARMENIAN or GEORGIAN
|
||||
cp -= 0x30
|
||||
} else if (((0x1E01 <= cp) && (0x1E95 >= cp)) || ((0x1EA1 <= cp) && (0x1EF9 >= cp)))
|
||||
&& (cp & 1 == 1) {
|
||||
} else if ((0x1E01 <= cp && 0x1E95 >= cp) || (0x1EA1 <= cp && 0x1EF9 >= cp)) && cp & 1 == 1 {
|
||||
// LATIN CAPITAL LETTER
|
||||
cp -= 1
|
||||
} else if (0x24D0 <= cp) && (0x24E9 >= cp) {
|
||||
} else if 0x24D0 <= cp && 0x24E9 >= cp {
|
||||
// CIRCLED LATIN
|
||||
cp -= 0x1a
|
||||
} else if (0xFF41 <= cp) && (0xFF5A >= cp) {
|
||||
} else if 0xFF41 <= cp && 0xFF5A >= cp {
|
||||
// FULLWIDTH LATIN CAPITAL
|
||||
cp -= 0x19
|
||||
} else if ((0x1F00 <= cp) && (0x1F07 >= cp)) || ((0x1F10 <= cp) && (0x1F15 >= cp))
|
||||
|| ((0x1F20 <= cp) && (0x1F27 >= cp)) || ((0x1F30 <= cp) && (0x1F37 >= cp))
|
||||
|| ((0x1F40 <= cp) && (0x1F45 >= cp)) || ((0x1F60 <= cp) && (0x1F67 >= cp))
|
||||
|| ((0x1F80 <= cp) && (0x1F87 >= cp)) || ((0x1F90 <= cp) && (0x1F97 >= cp))
|
||||
|| ((0x1FA0 <= cp) && (0x1FA7 >= cp)) {
|
||||
} else if (0x1F00 <= cp && 0x1F07 >= cp) || (0x1F10 <= cp && 0x1F15 >= cp)
|
||||
|| (0x1F20 <= cp && 0x1F27 >= cp) || (0x1F30 <= cp && 0x1F37 >= cp)
|
||||
|| (0x1F40 <= cp && 0x1F45 >= cp) || (0x1F60 <= cp && 0x1F67 >= cp)
|
||||
|| (0x1F80 <= cp && 0x1F87 >= cp) || (0x1F90 <= cp && 0x1F97 >= cp)
|
||||
|| (0x1FA0 <= cp && 0x1FA7 >= cp) {
|
||||
// GREEK
|
||||
cp += 8
|
||||
} else {
|
||||
|
@ -289,7 +289,7 @@ fn (mut fs FlagParser) parse_bool_value(longhand string, shorthand u8) !string {
|
||||
continue
|
||||
}
|
||||
if (arg.len == 2 && arg[0] == `-` && arg[1] == shorthand) || arg == full {
|
||||
if fs.args.len > i + 1 && (fs.args[i + 1] in ['true', 'false']) {
|
||||
if fs.args.len > i + 1 && fs.args[i + 1] in ['true', 'false'] {
|
||||
val := fs.args[i + 1]
|
||||
fs.args.delete(i + 1)
|
||||
fs.args.delete(i)
|
||||
|
@ -456,7 +456,7 @@ pub fn div_64(hi u64, lo u64, y1 u64) (u64, u64) {
|
||||
un0 := un10 & bits.mask32
|
||||
mut q1 := un32 / yn1
|
||||
mut rhat := un32 - (q1 * yn1)
|
||||
for (q1 >= bits.two32) || (q1 * yn0) > ((bits.two32 * rhat) + un1) {
|
||||
for q1 >= bits.two32 || (q1 * yn0) > ((bits.two32 * rhat) + un1) {
|
||||
q1--
|
||||
rhat += yn1
|
||||
if rhat >= bits.two32 {
|
||||
@ -466,7 +466,7 @@ pub fn div_64(hi u64, lo u64, y1 u64) (u64, u64) {
|
||||
un21 := (un32 * bits.two32) + (un1 - (q1 * y))
|
||||
mut q0 := un21 / yn1
|
||||
rhat = un21 - q0 * yn1
|
||||
for (q0 >= bits.two32) || (q0 * yn0) > ((bits.two32 * rhat) + un0) {
|
||||
for q0 >= bits.two32 || (q0 * yn0) > ((bits.two32 * rhat) + un0) {
|
||||
q0--
|
||||
rhat += yn1
|
||||
if rhat >= bits.two32 {
|
||||
|
@ -370,5 +370,5 @@ pub fn (c Complex) acsch() Complex {
|
||||
|
||||
// Complex Equals
|
||||
pub fn (c1 Complex) equals(c2 Complex) bool {
|
||||
return (c1.re == c2.re) && (c1.im == c2.im)
|
||||
return c1.re == c2.re && c1.im == c2.im
|
||||
}
|
||||
|
@ -203,7 +203,7 @@ pub fn asin(x_ f64) f64 {
|
||||
// acos(x) = nan if x < -1 or x > 1
|
||||
[inline]
|
||||
pub fn acos(x f64) f64 {
|
||||
if (x < -1.0) || (x > 1.0) {
|
||||
if x < -1.0 || x > 1.0 {
|
||||
return nan()
|
||||
}
|
||||
if x > 0.5 {
|
||||
|
@ -1982,7 +1982,7 @@ pub fn (mut re RE) match_base(in_txt &u8, in_txt_len int) (int, int) {
|
||||
// check if stop
|
||||
else if m_state == .stop {
|
||||
// we are in search mode, don't exit until the end
|
||||
if ((re.flag & regex.f_src) != 0) && (ist != regex.ist_prog_end) {
|
||||
if (re.flag & regex.f_src) != 0 && ist != regex.ist_prog_end {
|
||||
last_fnd_pc = state.pc
|
||||
state.pc = -1
|
||||
state.i += char_len
|
||||
|
@ -691,7 +691,7 @@ fn test_regex_func() {
|
||||
mut re, re_err, err_pos := regex.regex_base(query)
|
||||
if re_err == regex.compile_ok {
|
||||
start, end := re.match_string(test_str)
|
||||
assert (start == 0) && (end == 6)
|
||||
assert start == 0 && end == 6
|
||||
} else {
|
||||
eprintln('Error in query string in pos ${err_pos}')
|
||||
eprintln('Error: ${re.get_parse_error_string(re_err)}')
|
||||
|
@ -163,7 +163,7 @@ fn parser(s string) (ParserState, PrepNumber) {
|
||||
}
|
||||
|
||||
// read mantissa decimals
|
||||
if (i < s.len) && (s[i] == `.`) {
|
||||
if i < s.len && s[i] == `.` {
|
||||
i++
|
||||
for i < s.len && s[i].is_digit() {
|
||||
if digx < strconv.digits {
|
||||
@ -177,7 +177,7 @@ fn parser(s string) (ParserState, PrepNumber) {
|
||||
}
|
||||
|
||||
// read exponent
|
||||
if (i < s.len) && ((s[i] == `e`) || (s[i] == `E`)) {
|
||||
if i < s.len && (s[i] == `e` || s[i] == `E`) {
|
||||
i++
|
||||
if i < s.len {
|
||||
// esponent sign
|
||||
|
@ -233,8 +233,8 @@ fn underscore_ok(s string) bool {
|
||||
}
|
||||
// Optional base prefix.
|
||||
mut hex := false
|
||||
if (s.len - i >= 2) && (s[i] == `0`) && (((s[i + 1] | 32) == `b`)
|
||||
|| ((s[i + 1] | 32) == `o`) || ((s[i + 1] | 32) == `x`)) {
|
||||
if s.len - i >= 2 && s[i] == `0` && ((s[i + 1] | 32) == `b`
|
||||
|| (s[i + 1] | 32) == `o` || (s[i + 1] | 32) == `x`) {
|
||||
saw = `0` // base prefix counts as a digit for "underscore as digit separator"
|
||||
hex = (s[i + 1] | 32) == `x`
|
||||
i += 2
|
||||
@ -242,7 +242,7 @@ fn underscore_ok(s string) bool {
|
||||
// Number proper.
|
||||
for ; i < s.len; i++ {
|
||||
// Digits are always okay.
|
||||
if (`0` <= s[i] && s[i] <= `9`) || ((hex && `a` <= (s[i] | 32)) && ((s[i] | 32) <= `f`)) {
|
||||
if (`0` <= s[i] && s[i] <= `9`) || ((hex && `a` <= (s[i] | 32)) && (s[i] | 32) <= `f`) {
|
||||
saw = `0`
|
||||
continue
|
||||
}
|
||||
|
@ -269,7 +269,7 @@ fn f32_to_decimal(mant u32, exp u32) Dec32 {
|
||||
// General case, which happens rarely (~4.0%).
|
||||
for vp / 10 > vm / 10 {
|
||||
vm_is_trailing_zeros = vm_is_trailing_zeros && (vm % 10) == 0
|
||||
vr_is_trailing_zeros = vr_is_trailing_zeros && (last_removed_digit == 0)
|
||||
vr_is_trailing_zeros = vr_is_trailing_zeros && last_removed_digit == 0
|
||||
last_removed_digit = u8(vr % 10)
|
||||
vr /= 10
|
||||
vp /= 10
|
||||
@ -278,7 +278,7 @@ fn f32_to_decimal(mant u32, exp u32) Dec32 {
|
||||
}
|
||||
if vm_is_trailing_zeros {
|
||||
for vm % 10 == 0 {
|
||||
vr_is_trailing_zeros = vr_is_trailing_zeros && (last_removed_digit == 0)
|
||||
vr_is_trailing_zeros = vr_is_trailing_zeros && last_removed_digit == 0
|
||||
last_removed_digit = u8(vr % 10)
|
||||
vr /= 10
|
||||
vp /= 10
|
||||
@ -286,7 +286,7 @@ fn f32_to_decimal(mant u32, exp u32) Dec32 {
|
||||
removed++
|
||||
}
|
||||
}
|
||||
if vr_is_trailing_zeros && (last_removed_digit == 5) && (vr % 2) == 0 {
|
||||
if vr_is_trailing_zeros && last_removed_digit == 5 && (vr % 2) == 0 {
|
||||
// Round even if the exact number is .....50..0.
|
||||
last_removed_digit = 4
|
||||
}
|
||||
@ -335,7 +335,7 @@ pub fn f32_to_str(f f32, n_digit int) string {
|
||||
// println("${neg} ${mant} e ${exp-bias32}")
|
||||
|
||||
// Exit early for easy cases.
|
||||
if (exp == strconv.maxexp32) || (exp == 0 && mant == 0) {
|
||||
if exp == strconv.maxexp32 || (exp == 0 && mant == 0) {
|
||||
return get_string_special(neg, exp == 0, mant == 0)
|
||||
}
|
||||
|
||||
@ -362,7 +362,7 @@ pub fn f32_to_str_pad(f f32, n_digit int) string {
|
||||
// println("${neg} ${mant} e ${exp-bias32}")
|
||||
|
||||
// Exit early for easy cases.
|
||||
if (exp == strconv.maxexp32) || (exp == 0 && mant == 0) {
|
||||
if exp == strconv.maxexp32 || (exp == 0 && mant == 0) {
|
||||
return get_string_special(neg, exp == 0, mant == 0)
|
||||
}
|
||||
|
||||
|
@ -258,7 +258,7 @@ fn f64_to_decimal(mant u64, exp u64) Dec64 {
|
||||
vr_div_10 := vr / 10
|
||||
vr_mod_10 := vr % 10
|
||||
vm_is_trailing_zeros = vm_is_trailing_zeros && vm_mod_10 == 0
|
||||
vr_is_trailing_zeros = vr_is_trailing_zeros && (last_removed_digit == 0)
|
||||
vr_is_trailing_zeros = vr_is_trailing_zeros && last_removed_digit == 0
|
||||
last_removed_digit = u8(vr_mod_10)
|
||||
vr = vr_div_10
|
||||
vp = vp_div_10
|
||||
@ -275,7 +275,7 @@ fn f64_to_decimal(mant u64, exp u64) Dec64 {
|
||||
vp_div_10 := vp / 10
|
||||
vr_div_10 := vr / 10
|
||||
vr_mod_10 := vr % 10
|
||||
vr_is_trailing_zeros = vr_is_trailing_zeros && (last_removed_digit == 0)
|
||||
vr_is_trailing_zeros = vr_is_trailing_zeros && last_removed_digit == 0
|
||||
last_removed_digit = u8(vr_mod_10)
|
||||
vr = vr_div_10
|
||||
vp = vp_div_10
|
||||
@ -283,7 +283,7 @@ fn f64_to_decimal(mant u64, exp u64) Dec64 {
|
||||
removed++
|
||||
}
|
||||
}
|
||||
if vr_is_trailing_zeros && (last_removed_digit == 5) && (vr % 2) == 0 {
|
||||
if vr_is_trailing_zeros && last_removed_digit == 5 && (vr % 2) == 0 {
|
||||
// Round even if the exact number is .....50..0.
|
||||
last_removed_digit = 4
|
||||
}
|
||||
@ -343,7 +343,7 @@ pub fn f64_to_str(f f64, n_digit int) string {
|
||||
// println("s:${neg} mant:${mant} exp:${exp} float:${f} byte:${u1.u:016lx}")
|
||||
|
||||
// Exit early for easy cases.
|
||||
if (exp == maxexp64) || (exp == 0 && mant == 0) {
|
||||
if exp == maxexp64 || (exp == 0 && mant == 0) {
|
||||
return get_string_special(neg, exp == 0, mant == 0)
|
||||
}
|
||||
|
||||
@ -368,7 +368,7 @@ pub fn f64_to_str_pad(f f64, n_digit int) string {
|
||||
// println("s:${neg} mant:${mant} exp:${exp} float:${f} byte:${u1.u:016lx}")
|
||||
|
||||
// Exit early for easy cases.
|
||||
if (exp == maxexp64) || (exp == 0 && mant == 0) {
|
||||
if exp == maxexp64 || (exp == 0 && mant == 0) {
|
||||
return get_string_special(neg, exp == 0, mant == 0)
|
||||
}
|
||||
|
||||
|
@ -243,7 +243,7 @@ fn f64_to_decimal(mant u64, exp u64) Dec64 {
|
||||
vr_div_10 := vr / 10
|
||||
vr_mod_10 := vr % 10
|
||||
vm_is_trailing_zeros = vm_is_trailing_zeros && vm_mod_10 == 0
|
||||
vr_is_trailing_zeros = vr_is_trailing_zeros && (last_removed_digit == 0)
|
||||
vr_is_trailing_zeros = vr_is_trailing_zeros && last_removed_digit == 0
|
||||
last_removed_digit = u8(vr_mod_10)
|
||||
vr = vr_div_10
|
||||
vp = vp_div_10
|
||||
@ -260,7 +260,7 @@ fn f64_to_decimal(mant u64, exp u64) Dec64 {
|
||||
vp_div_10 := vp / 10
|
||||
vr_div_10 := vr / 10
|
||||
vr_mod_10 := vr % 10
|
||||
vr_is_trailing_zeros = vr_is_trailing_zeros && (last_removed_digit == 0)
|
||||
vr_is_trailing_zeros = vr_is_trailing_zeros && last_removed_digit == 0
|
||||
last_removed_digit = u8(vr_mod_10)
|
||||
vr = vr_div_10
|
||||
vp = vp_div_10
|
||||
@ -268,7 +268,7 @@ fn f64_to_decimal(mant u64, exp u64) Dec64 {
|
||||
removed++
|
||||
}
|
||||
}
|
||||
if vr_is_trailing_zeros && (last_removed_digit == 5) && (vr % 2) == 0 {
|
||||
if vr_is_trailing_zeros && last_removed_digit == 5 && (vr % 2) == 0 {
|
||||
// Round even if the exact number is .....50..0.
|
||||
last_removed_digit = 4
|
||||
}
|
||||
@ -325,7 +325,7 @@ pub fn f64_to_str(f f64, n_digit int) string {
|
||||
// println("s:${neg} mant:${mant} exp:${exp} float:${f} byte:${u1.u:016lx}")
|
||||
|
||||
// Exit early for easy cases.
|
||||
if (exp == maxexp64) || (exp == 0 && mant == 0) {
|
||||
if exp == maxexp64 || (exp == 0 && mant == 0) {
|
||||
return get_string_special(neg, exp == 0, mant == 0)
|
||||
}
|
||||
|
||||
|
@ -281,7 +281,7 @@ pub fn (t Time) long_weekday_str() string {
|
||||
|
||||
// is_leap_year checks if a given a year is a leap year.
|
||||
pub fn is_leap_year(year int) bool {
|
||||
return (year % 4 == 0) && (year % 100 != 0 || year % 400 == 0)
|
||||
return year % 4 == 0 && (year % 100 != 0 || year % 400 == 0)
|
||||
}
|
||||
|
||||
// days_in_month returns a number of days in a given month.
|
||||
|
@ -70,7 +70,7 @@ pub fn (mut t Table) parse_cflag(cflg string, mod string, ctimedefines []string)
|
||||
if index == -1 {
|
||||
value = flag.trim_space()
|
||||
}
|
||||
if (name in ['-I', '-l', '-L']) && value == '' {
|
||||
if name in ['-I', '-l', '-L'] && value == '' {
|
||||
hint := if name == '-l' { 'library name' } else { 'path' }
|
||||
return error('bad #flag `${flag_orig}`: missing ${hint} after `${name}`')
|
||||
}
|
||||
|
@ -272,7 +272,7 @@ fn (mut c Checker) check_expected_call_arg(got ast.Type, expected_ ast.Type, lan
|
||||
if got_typ_sym.symbol_name_except_generic() == expected_typ_sym.symbol_name_except_generic() {
|
||||
// Check if we are making a comparison between two different types of
|
||||
// the same type like `Type[int] and &Type[]`
|
||||
if (got.is_ptr() != expected.is_ptr())
|
||||
if got.is_ptr() != expected.is_ptr()
|
||||
|| !c.check_same_module(got, expected)
|
||||
|| (!got.is_ptr() && !expected.is_ptr()
|
||||
&& got_typ_sym.name != expected_typ_sym.name) {
|
||||
|
@ -203,7 +203,7 @@ fn (mut c Checker) sql_stmt_line(mut node ast.SqlStmtLine) ast.Type {
|
||||
info := table_sym.info as ast.Struct
|
||||
fields := c.fetch_and_verify_orm_fields(info, node.table_expr.pos, table_sym.name)
|
||||
mut sub_structs := map[int]ast.SqlStmtLine{}
|
||||
for f in fields.filter(((c.table.type_symbols[int(it.typ)].kind == .struct_)
|
||||
for f in fields.filter((c.table.type_symbols[int(it.typ)].kind == .struct_
|
||||
|| (c.table.sym(it.typ).kind == .array
|
||||
&& c.table.sym(c.table.sym(it.typ).array_info().elem_type).kind == .struct_))
|
||||
&& c.table.get_type_name(it.typ) != 'time.Time') {
|
||||
|
@ -375,7 +375,7 @@ pub fn (mut d Doc) file_ast(file_ast ast.File) map[string]DocNode {
|
||||
kind: parent_node_kind
|
||||
}
|
||||
}
|
||||
if d.with_comments && (preceeding_comments.len > 0) {
|
||||
if d.with_comments && preceeding_comments.len > 0 {
|
||||
node.comments << preceeding_comments
|
||||
}
|
||||
preceeding_comments = []
|
||||
|
@ -2147,7 +2147,18 @@ pub fn (mut f Fmt) infix_expr(node ast.InfixExpr) {
|
||||
}
|
||||
start_pos := f.out.len
|
||||
start_len := f.line_len
|
||||
mut redundant_par := false
|
||||
if node.left is ast.ParExpr && node.op in [.and, .logical_or] {
|
||||
if node.left.expr is ast.InfixExpr {
|
||||
if node.left.expr.op !in [.and, .logical_or] {
|
||||
redundant_par = true
|
||||
f.expr(node.left.expr)
|
||||
}
|
||||
}
|
||||
}
|
||||
if !redundant_par {
|
||||
f.expr(node.left)
|
||||
}
|
||||
if node.before_op_comments.len > 0 {
|
||||
f.comments(node.before_op_comments, iembed: node.before_op_comments[0].is_inline)
|
||||
}
|
||||
@ -2173,8 +2184,19 @@ pub fn (mut f Fmt) infix_expr(node ast.InfixExpr) {
|
||||
} else if is_and {
|
||||
f.write(f.node_str(node.right).trim_string_left('&'))
|
||||
} else {
|
||||
redundant_par = false
|
||||
if node.right is ast.ParExpr && node.op in [.and, .logical_or] {
|
||||
if node.right.expr is ast.InfixExpr {
|
||||
if node.right.expr.op !in [.and, .logical_or] {
|
||||
redundant_par = true
|
||||
f.expr(node.right.expr)
|
||||
}
|
||||
}
|
||||
}
|
||||
if !redundant_par {
|
||||
f.expr(node.right)
|
||||
}
|
||||
}
|
||||
if !buffering_save && f.buffering {
|
||||
f.buffering = false
|
||||
if !f.single_line_if && f.line_len > fmt.max_len.last() {
|
||||
|
@ -52,7 +52,7 @@ fn main() {
|
||||
println(s)
|
||||
println('this is quite a long string' +
|
||||
' that is followd by an even longer part that should go to another line')
|
||||
if (a == b && b > r) || (d > r) || (a < b) || (b < d && a + b > r)
|
||||
if (a == b && b > r) || d > r || a < b || (b < d && a + b > r)
|
||||
|| (a + b + d >= 0 && r < 0) || (a > b && d - r < b) {
|
||||
println('ok')
|
||||
}
|
||||
|
@ -20,16 +20,18 @@ fn main() {
|
||||
clean_struct_v_type_name.replace('_Array', '_array').replace('_T_', '<').replace('_', ', ') +
|
||||
'>'
|
||||
{
|
||||
{
|
||||
{
|
||||
{
|
||||
// Indent this much to force a break after the assign (`:=`).
|
||||
// Check that the trailing space is removed
|
||||
should_cast :=
|
||||
(g.table.type_kind(stmt.left_types.first()) in js.shallow_equatables)
|
||||
g.table.type_kind(stmt.left_types.first()) in js.shallow_equatables
|
||||
&& (g.cast_stack.len <= 0 || stmt.left_types.first() != g.cast_stack.last())
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if c.table.final_sym(typ).kind in [.array, .array_fixed, .struct_, .interface_, .none_, .map, .sum_type]
|
||||
|
@ -13,6 +13,7 @@ fn unwrap_grouped_conds() {
|
||||
fn main() {
|
||||
clean_struct_v_type_name = clean_struct_v_type_name.replace('_Array', '_array').replace('_T_', '<').replace('_', ', ') + '>'
|
||||
{
|
||||
{
|
||||
{
|
||||
{
|
||||
// Indent this much to force a break after the assign (`:=`).
|
||||
@ -21,6 +22,7 @@ fn main() {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if c.table.final_sym(typ).kind in [.array, .array_fixed, .struct_, .interface_, .none_, .map, .sum_type]
|
||||
|
@ -86,7 +86,8 @@ fn (mut g Gen) expr_with_opt(expr ast.Expr, expr_typ ast.Type, ret_typ ast.Type)
|
||||
defer {
|
||||
g.inside_opt_or_res = old_inside_opt_or_res
|
||||
}
|
||||
if expr_typ.has_flag(.option) && ret_typ.has_flag(.option)&& (expr in [ast.DumpExpr, ast.Ident, ast.ComptimeSelector, ast.AsCast, ast.CallExpr, ast.MatchExpr, ast.IfExpr, ast.IndexExpr, ast.UnsafeExpr, ast.CastExpr]) {
|
||||
if expr_typ.has_flag(.option) && ret_typ.has_flag(.option)
|
||||
&& expr in [ast.DumpExpr, ast.Ident, ast.ComptimeSelector, ast.AsCast, ast.CallExpr, ast.MatchExpr, ast.IfExpr, ast.IndexExpr, ast.UnsafeExpr, ast.CastExpr] {
|
||||
if expr in [ast.Ident, ast.CastExpr] {
|
||||
if expr_typ.idx() != ret_typ.idx() {
|
||||
return g.expr_opt_with_cast(expr, expr_typ, ret_typ)
|
||||
|
@ -185,7 +185,7 @@ fn (mut g Gen) comptime_call(mut node ast.ComptimeCall) {
|
||||
continue
|
||||
}
|
||||
}
|
||||
if (i - 1 <= node.args.len - 1) && has_decompose
|
||||
if i - 1 <= node.args.len - 1 && has_decompose
|
||||
&& node.args[i - 1].expr is ast.ArrayDecompose {
|
||||
mut d_count := 0
|
||||
for d_i in i .. m.params.len {
|
||||
|
@ -1465,7 +1465,7 @@ fn (mut g JsGen) gen_assign_stmt(stmt ast.AssignStmt, semicolon bool) {
|
||||
should_cast := if stmt.left_types.len == 0 {
|
||||
false
|
||||
} else {
|
||||
(g.table.type_kind(stmt.left_types.first()) in js.shallow_equatables)
|
||||
g.table.type_kind(stmt.left_types.first()) in js.shallow_equatables
|
||||
&& (g.cast_stack.len <= 0 || stmt.left_types.first() != g.cast_stack.last())
|
||||
}
|
||||
|
||||
|
@ -514,7 +514,7 @@ pub fn (mut w Walker) call_expr(mut node ast.CallExpr) {
|
||||
w.mark_fn_as_used(fn_name)
|
||||
stmt := w.all_fns[fn_name] or { return }
|
||||
if stmt.name == node.name {
|
||||
if !node.is_method || (node.receiver_type == stmt.receiver.typ) {
|
||||
if !node.is_method || node.receiver_type == stmt.receiver.typ {
|
||||
w.stmts(stmt.stmts)
|
||||
}
|
||||
}
|
||||
|
@ -3018,7 +3018,7 @@ fn (mut p Parser) dot_expr(left ast.Expr) ast.Expr {
|
||||
name_pos := p.tok.pos()
|
||||
mut field_name := ''
|
||||
// check if the name is on the same line as the dot
|
||||
if (p.prev_tok.pos().line_nr == name_pos.line_nr) || p.tok.kind != .name {
|
||||
if p.prev_tok.pos().line_nr == name_pos.line_nr || p.tok.kind != .name {
|
||||
field_name = p.check_name()
|
||||
} else {
|
||||
p.name_error = true
|
||||
|
@ -158,7 +158,7 @@ pub fn (mut s Scanner) free() {
|
||||
|
||||
[inline]
|
||||
fn (s &Scanner) should_parse_comment() bool {
|
||||
return (s.comments_mode == .parse_comments)
|
||||
return s.comments_mode == .parse_comments
|
||||
|| (s.comments_mode == .toplevel_comments && !s.is_inside_toplvl_statement)
|
||||
}
|
||||
|
||||
@ -520,7 +520,7 @@ fn (mut s Scanner) skip_whitespace() {
|
||||
s.pos++
|
||||
continue
|
||||
}
|
||||
if !(c == 32 || (c > 8 && c < 14) || (c == 0x85) || (c == 0xa0)) {
|
||||
if !(c == 32 || (c > 8 && c < 14) || c == 0x85 || c == 0xa0) {
|
||||
return
|
||||
}
|
||||
c_is_nl := c == scanner.b_cr || c == scanner.b_lf
|
||||
@ -1432,7 +1432,7 @@ fn (mut s Scanner) ident_char() string {
|
||||
// e.g. (octal) \141 (hex) \x61 or (unicode) \u2605
|
||||
// we don't handle binary escape codes in rune literals
|
||||
orig := c
|
||||
if (c.len % 2 == 0) && (escaped_hex || escaped_unicode || escaped_octal) {
|
||||
if c.len % 2 == 0 && (escaped_hex || escaped_unicode || escaped_octal) {
|
||||
if escaped_unicode {
|
||||
// there can only be one, so attempt to decode it now
|
||||
c = s.decode_u_escapes(c, 0, [0])
|
||||
|
@ -51,7 +51,7 @@ pub fn (p PrimeSet) str() string {
|
||||
|
||||
fn extract_count(s string) int {
|
||||
digits := '0123456789'.split('')
|
||||
if (s == '') || !s.split('').any(it in digits) {
|
||||
if s == '' || !s.split('').any(it in digits) {
|
||||
return 0
|
||||
}
|
||||
ds := s.split('').filter(it in digits)
|
||||
|
@ -56,7 +56,7 @@ fn test_if_expr_with_array_call_filter() {
|
||||
assert true
|
||||
}
|
||||
|
||||
if arr.len == 1 || (arr[1].bytes().filter(it.is_letter()).len == 0) {
|
||||
if arr.len == 1 || arr[1].bytes().filter(it.is_letter()).len == 0 {
|
||||
println('yes')
|
||||
assert true
|
||||
}
|
||||
|
@ -89,7 +89,7 @@ fn is_dog_or_cat(a Animal) bool {
|
||||
println('Animal is Dog or Cat: is a Dog: ${is_dog}, is a Cat: ${is_cat}')
|
||||
// return is_dog || is_cat
|
||||
// shorter syntax
|
||||
is_dog_or_cat := if (a is Dog) || (a is Cat) { true } else { false }
|
||||
is_dog_or_cat := if a is Dog || a is Cat { true } else { false }
|
||||
println('Animal is Dog or Cat: ${is_dog_or_cat}')
|
||||
return is_dog_or_cat
|
||||
}
|
||||
@ -359,7 +359,7 @@ fn is_dog(a Animal) bool {
|
||||
println('with type: ${typeof(a).name}') // get implementation type (if possible)
|
||||
|
||||
// sample (additional checks) here
|
||||
is_dog_or_cat := if (a is Dog) || (a is Cat) { true } else { false }
|
||||
is_dog_or_cat := if a is Dog || a is Cat { true } else { false }
|
||||
println('Animal is Dog or Cat: ${is_dog_or_cat}')
|
||||
|
||||
// use/test even another syntax
|
||||
|
@ -24,8 +24,7 @@ pub fn smart_quote(str string, raw bool) string {
|
||||
mut is_pure := true
|
||||
for i := 0; i < len; i++ {
|
||||
ch := u8(str[i])
|
||||
if (ch >= 37 && ch <= 90) || (ch >= 95 && ch <= 126)
|
||||
|| (ch in [` `, `!`, `#`, `[`, `]`]) {
|
||||
if (ch >= 37 && ch <= 90) || (ch >= 95 && ch <= 126) || ch in [` `, `!`, `#`, `[`, `]`] {
|
||||
// safe punctuation + digits + big latin letters,
|
||||
// small latin letters + more safe punctuation,
|
||||
// important punctuation exceptions, that are not
|
||||
|
Loading…
Reference in New Issue
Block a user