Skip to content

Commit 7e35d40

Browse files
committed
v2: add formatting workarounds, to make v run cmd/v2/v2.v --skip-imports -d vlib/v2/tests/syntax.v_ run
1 parent c989f9b commit 7e35d40

4 files changed

Lines changed: 35 additions & 23 deletions

File tree

‎vlib/builtin/rune_map.v‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@ const rune_maps_utl = -2 // NOTE: this should *NOT* be used anywhere in rune_map
2525
// It is represented that way, instead of the more natural array of structs, to save on the .c encoding used for the initialisation.
2626
// The overhead for representing it as an array of structs was ~28KB in .c, while with the flat array of ints, it is ~7.5KB.
2727
// Given that xz can compress it to ~1.8KB, it could be probably represented in an even more compact way...
28-
const rune_maps = [
29-
i32(0xB5), 0xB5, 743, 0,
28+
const rune_maps = [ i32(0xB5), 0xB5, 743, 0, // this being on the same line, is needed as a workaround for a bug in v2's parser
3029
0xC0, 0xD6, 0, 32,
3130
0xD8, 0xDE, 0, 32,
3231
0xE0, 0xF6, -32, 0,

‎vlib/builtin/string.v‎

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2166,10 +2166,13 @@ pub fn (str string) is_hex() bool {
21662166
}
21672167

21682168
for i < str.len {
2169-
if (str[i] < `0` || str[i] > `9`) && ((str[i] < `a` || str[i] > `f`)
2170-
&& (str[i] < `A` || str[i] > `F`)) {
2169+
// TODO: remove this workaround for v2's parser
2170+
// vfmt off
2171+
if (str[i] < `0` || str[i] > `9`) &&
2172+
((str[i] < `a` || str[i] > `f`) && (str[i] < `A` || str[i] > `F`)) {
21712173
return false
21722174
}
2175+
// vfmt on
21732176
i++
21742177
}
21752178

@@ -2885,15 +2888,19 @@ pub fn (s string) camel_to_snake() string {
28852888
c := s[i]
28862889
c_is_upper := c.is_capital()
28872890
// Cases: `aBcd == a_bcd` || `ABcd == ab_cd`
2888-
if ((c_is_upper && !prev_is_upper)
2889-
|| (!c_is_upper && prev_is_upper && s[i - 2].is_capital())) && c != `_` {
2891+
// TODO: remove this workaround for v2's parser
2892+
// vfmt off
2893+
if ((c_is_upper && !prev_is_upper) ||
2894+
(!c_is_upper && prev_is_upper && s[i - 2].is_capital())) &&
2895+
c != `_` {
28902896
unsafe {
28912897
if b[pos - 1] != `_` {
28922898
b[pos] = `_`
28932899
pos++
28942900
}
28952901
}
28962902
}
2903+
// vfmt on
28972904
lower_c := if c_is_upper { c + 32 } else { c }
28982905
unsafe {
28992906
b[pos] = lower_c

‎vlib/builtin/utf8.v‎

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -146,28 +146,31 @@ pub fn utf8_str_visible_length(s string) int {
146146
// diacritical marks extended
147147
// diacritical marks supplement
148148
// diacritical marks for symbols
149-
if (r >= 0xe1aab0 && r <= 0xe1ac7f)
150-
|| (r >= 0xe1b780 && r <= 0xe1b87f)
151-
|| (r >= 0xe28390 && r <= 0xe2847f)
152-
|| (r >= 0xefb8a0 && r <= 0xefb8af) {
149+
// TODO: remove this workaround for v2's parser
150+
// vfmt off
151+
if (r >= 0xe1aab0 && r <= 0xe1ac7f) ||
152+
(r >= 0xe1b780 && r <= 0xe1b87f) ||
153+
(r >= 0xe28390 && r <= 0xe2847f) ||
154+
(r >= 0xefb8a0 && r <= 0xefb8af) {
153155
// diacritical marks
154156
l--
155157
}
156158
// Hangru
157159
// CJK Unified Ideographics
158160
// Hangru
159161
// CJK
160-
else if (r >= 0xe18480 && r <= 0xe1859f)
161-
|| (r >= 0xe2ba80 && r <= 0xe2bf95)
162-
|| (r >= 0xe38080 && r <= 0xe4b77f)
163-
|| (r >= 0xe4b880 && r <= 0xea807f)
164-
|| (r >= 0xeaa5a0 && r <= 0xeaa79f)
165-
|| (r >= 0xeab080 && r <= 0xed9eaf)
166-
|| (r >= 0xefa480 && r <= 0xefac7f)
167-
|| (r >= 0xefb8b8 && r <= 0xefb9af) {
162+
else if (r >= 0xe18480 && r <= 0xe1859f) ||
163+
(r >= 0xe2ba80 && r <= 0xe2bf95) ||
164+
(r >= 0xe38080 && r <= 0xe4b77f) ||
165+
(r >= 0xe4b880 && r <= 0xea807f) ||
166+
(r >= 0xeaa5a0 && r <= 0xeaa79f) ||
167+
(r >= 0xeab080 && r <= 0xed9eaf) ||
168+
(r >= 0xefa480 && r <= 0xefac7f) ||
169+
(r >= 0xefb8b8 && r <= 0xefb9af) {
168170
// half marks
169171
l++
170172
}
173+
// vfmt on
171174
}
172175
4 {
173176
r := u64((u32(c) << 24) | unsafe {
@@ -176,12 +179,15 @@ pub fn utf8_str_visible_length(s string) int {
176179
// Enclosed Ideographic Supplement
177180
// Emoji
178181
// CJK Unified Ideographs Extension B-G
179-
if (r >= 0x0f9f8880 && r <= 0xf09f8a8f)
180-
|| (r >= 0xf09f8c80 && r <= 0xf09f9c90)
181-
|| (r >= 0xf09fa490 && r <= 0xf09fa7af)
182-
|| (r >= 0xf0a08080 && r <= 0xf180807f) {
182+
// TODO: remove this workaround for v2's parser
183+
// vfmt off
184+
if (r >= 0x0f9f8880 && r <= 0xf09f8a8f) ||
185+
(r >= 0xf09f8c80 && r <= 0xf09f9c90) ||
186+
(r >= 0xf09fa490 && r <= 0xf09fa7af) ||
187+
(r >= 0xf0a08080 && r <= 0xf180807f) {
183188
l++
184189
}
190+
// vfmt on
185191
}
186192
else {}
187193
}

‎vlib/v2/token/position.v‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import sync
88
// TODO: finish fileset / file / base pos etc
99

1010
// compact encoding of a source position within a file set
11-
type Pos = int
11+
pub type Pos = int
1212

1313
pub struct Position {
1414
pub:

0 commit comments

Comments
 (0)