v2: add formatting workarounds, to make v run cmd/v2/v2.v --skip-imports -d vlib/v2/tests/syntax.v_ run

This commit is contained in:
Delyan Angelov 2025-07-03 09:46:01 +03:00
parent c989f9bb78
commit 7e35d40661
No known key found for this signature in database
GPG Key ID: 66886C0F12D595ED
4 changed files with 35 additions and 23 deletions

View File

@ -25,8 +25,7 @@ const rune_maps_utl = -2 // NOTE: this should *NOT* be used anywhere in rune_map
// It is represented that way, instead of the more natural array of structs, to save on the .c encoding used for the initialisation.
// 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.
// Given that xz can compress it to ~1.8KB, it could be probably represented in an even more compact way...
const rune_maps = [
i32(0xB5), 0xB5, 743, 0,
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
0xC0, 0xD6, 0, 32,
0xD8, 0xDE, 0, 32,
0xE0, 0xF6, -32, 0,

View File

@ -2166,10 +2166,13 @@ pub fn (str string) is_hex() bool {
}
for i < str.len {
if (str[i] < `0` || str[i] > `9`) && ((str[i] < `a` || str[i] > `f`)
&& (str[i] < `A` || str[i] > `F`)) {
// TODO: remove this workaround for v2's parser
// vfmt off
if (str[i] < `0` || str[i] > `9`) &&
((str[i] < `a` || str[i] > `f`) && (str[i] < `A` || str[i] > `F`)) {
return false
}
// vfmt on
i++
}
@ -2885,8 +2888,11 @@ pub fn (s string) camel_to_snake() string {
c := s[i]
c_is_upper := c.is_capital()
// Cases: `aBcd == a_bcd` || `ABcd == ab_cd`
if ((c_is_upper && !prev_is_upper)
|| (!c_is_upper && prev_is_upper && s[i - 2].is_capital())) && c != `_` {
// TODO: remove this workaround for v2's parser
// vfmt off
if ((c_is_upper && !prev_is_upper) ||
(!c_is_upper && prev_is_upper && s[i - 2].is_capital())) &&
c != `_` {
unsafe {
if b[pos - 1] != `_` {
b[pos] = `_`
@ -2894,6 +2900,7 @@ pub fn (s string) camel_to_snake() string {
}
}
}
// vfmt on
lower_c := if c_is_upper { c + 32 } else { c }
unsafe {
b[pos] = lower_c

View File

@ -146,10 +146,12 @@ pub fn utf8_str_visible_length(s string) int {
// diacritical marks extended
// diacritical marks supplement
// diacritical marks for symbols
if (r >= 0xe1aab0 && r <= 0xe1ac7f)
|| (r >= 0xe1b780 && r <= 0xe1b87f)
|| (r >= 0xe28390 && r <= 0xe2847f)
|| (r >= 0xefb8a0 && r <= 0xefb8af) {
// TODO: remove this workaround for v2's parser
// vfmt off
if (r >= 0xe1aab0 && r <= 0xe1ac7f) ||
(r >= 0xe1b780 && r <= 0xe1b87f) ||
(r >= 0xe28390 && r <= 0xe2847f) ||
(r >= 0xefb8a0 && r <= 0xefb8af) {
// diacritical marks
l--
}
@ -157,17 +159,18 @@ pub fn utf8_str_visible_length(s string) int {
// CJK Unified Ideographics
// Hangru
// CJK
else if (r >= 0xe18480 && r <= 0xe1859f)
|| (r >= 0xe2ba80 && r <= 0xe2bf95)
|| (r >= 0xe38080 && r <= 0xe4b77f)
|| (r >= 0xe4b880 && r <= 0xea807f)
|| (r >= 0xeaa5a0 && r <= 0xeaa79f)
|| (r >= 0xeab080 && r <= 0xed9eaf)
|| (r >= 0xefa480 && r <= 0xefac7f)
|| (r >= 0xefb8b8 && r <= 0xefb9af) {
else if (r >= 0xe18480 && r <= 0xe1859f) ||
(r >= 0xe2ba80 && r <= 0xe2bf95) ||
(r >= 0xe38080 && r <= 0xe4b77f) ||
(r >= 0xe4b880 && r <= 0xea807f) ||
(r >= 0xeaa5a0 && r <= 0xeaa79f) ||
(r >= 0xeab080 && r <= 0xed9eaf) ||
(r >= 0xefa480 && r <= 0xefac7f) ||
(r >= 0xefb8b8 && r <= 0xefb9af) {
// half marks
l++
}
// vfmt on
}
4 {
r := u64((u32(c) << 24) | unsafe {
@ -176,12 +179,15 @@ pub fn utf8_str_visible_length(s string) int {
// Enclosed Ideographic Supplement
// Emoji
// CJK Unified Ideographs Extension B-G
if (r >= 0x0f9f8880 && r <= 0xf09f8a8f)
|| (r >= 0xf09f8c80 && r <= 0xf09f9c90)
|| (r >= 0xf09fa490 && r <= 0xf09fa7af)
|| (r >= 0xf0a08080 && r <= 0xf180807f) {
// TODO: remove this workaround for v2's parser
// vfmt off
if (r >= 0x0f9f8880 && r <= 0xf09f8a8f) ||
(r >= 0xf09f8c80 && r <= 0xf09f9c90) ||
(r >= 0xf09fa490 && r <= 0xf09fa7af) ||
(r >= 0xf0a08080 && r <= 0xf180807f) {
l++
}
// vfmt on
}
else {}
}

View File

@ -8,7 +8,7 @@ import sync
// TODO: finish fileset / file / base pos etc
// compact encoding of a source position within a file set
type Pos = int
pub type Pos = int
pub struct Position {
pub: