mirror of
https://github.com/vlang/v.git
synced 2025-09-08 14:51:53 -04:00
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:
parent
c989f9bb78
commit
7e35d40661
@ -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.
|
// 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.
|
// 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...
|
// Given that xz can compress it to ~1.8KB, it could be probably represented in an even more compact way...
|
||||||
const rune_maps = [
|
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
|
||||||
i32(0xB5), 0xB5, 743, 0,
|
|
||||||
0xC0, 0xD6, 0, 32,
|
0xC0, 0xD6, 0, 32,
|
||||||
0xD8, 0xDE, 0, 32,
|
0xD8, 0xDE, 0, 32,
|
||||||
0xE0, 0xF6, -32, 0,
|
0xE0, 0xF6, -32, 0,
|
||||||
|
@ -2166,10 +2166,13 @@ pub fn (str string) is_hex() bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for i < str.len {
|
for i < str.len {
|
||||||
if (str[i] < `0` || str[i] > `9`) && ((str[i] < `a` || str[i] > `f`)
|
// TODO: remove this workaround for v2's parser
|
||||||
&& (str[i] < `A` || str[i] > `F`)) {
|
// vfmt off
|
||||||
|
if (str[i] < `0` || str[i] > `9`) &&
|
||||||
|
((str[i] < `a` || str[i] > `f`) && (str[i] < `A` || str[i] > `F`)) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
// vfmt on
|
||||||
i++
|
i++
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2885,8 +2888,11 @@ pub fn (s string) camel_to_snake() string {
|
|||||||
c := s[i]
|
c := s[i]
|
||||||
c_is_upper := c.is_capital()
|
c_is_upper := c.is_capital()
|
||||||
// Cases: `aBcd == a_bcd` || `ABcd == ab_cd`
|
// Cases: `aBcd == a_bcd` || `ABcd == ab_cd`
|
||||||
if ((c_is_upper && !prev_is_upper)
|
// TODO: remove this workaround for v2's parser
|
||||||
|| (!c_is_upper && prev_is_upper && s[i - 2].is_capital())) && c != `_` {
|
// vfmt off
|
||||||
|
if ((c_is_upper && !prev_is_upper) ||
|
||||||
|
(!c_is_upper && prev_is_upper && s[i - 2].is_capital())) &&
|
||||||
|
c != `_` {
|
||||||
unsafe {
|
unsafe {
|
||||||
if b[pos - 1] != `_` {
|
if b[pos - 1] != `_` {
|
||||||
b[pos] = `_`
|
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 }
|
lower_c := if c_is_upper { c + 32 } else { c }
|
||||||
unsafe {
|
unsafe {
|
||||||
b[pos] = lower_c
|
b[pos] = lower_c
|
||||||
|
@ -146,10 +146,12 @@ pub fn utf8_str_visible_length(s string) int {
|
|||||||
// diacritical marks extended
|
// diacritical marks extended
|
||||||
// diacritical marks supplement
|
// diacritical marks supplement
|
||||||
// diacritical marks for symbols
|
// diacritical marks for symbols
|
||||||
if (r >= 0xe1aab0 && r <= 0xe1ac7f)
|
// TODO: remove this workaround for v2's parser
|
||||||
|| (r >= 0xe1b780 && r <= 0xe1b87f)
|
// vfmt off
|
||||||
|| (r >= 0xe28390 && r <= 0xe2847f)
|
if (r >= 0xe1aab0 && r <= 0xe1ac7f) ||
|
||||||
|| (r >= 0xefb8a0 && r <= 0xefb8af) {
|
(r >= 0xe1b780 && r <= 0xe1b87f) ||
|
||||||
|
(r >= 0xe28390 && r <= 0xe2847f) ||
|
||||||
|
(r >= 0xefb8a0 && r <= 0xefb8af) {
|
||||||
// diacritical marks
|
// diacritical marks
|
||||||
l--
|
l--
|
||||||
}
|
}
|
||||||
@ -157,17 +159,18 @@ pub fn utf8_str_visible_length(s string) int {
|
|||||||
// CJK Unified Ideographics
|
// CJK Unified Ideographics
|
||||||
// Hangru
|
// Hangru
|
||||||
// CJK
|
// CJK
|
||||||
else if (r >= 0xe18480 && r <= 0xe1859f)
|
else if (r >= 0xe18480 && r <= 0xe1859f) ||
|
||||||
|| (r >= 0xe2ba80 && r <= 0xe2bf95)
|
(r >= 0xe2ba80 && r <= 0xe2bf95) ||
|
||||||
|| (r >= 0xe38080 && r <= 0xe4b77f)
|
(r >= 0xe38080 && r <= 0xe4b77f) ||
|
||||||
|| (r >= 0xe4b880 && r <= 0xea807f)
|
(r >= 0xe4b880 && r <= 0xea807f) ||
|
||||||
|| (r >= 0xeaa5a0 && r <= 0xeaa79f)
|
(r >= 0xeaa5a0 && r <= 0xeaa79f) ||
|
||||||
|| (r >= 0xeab080 && r <= 0xed9eaf)
|
(r >= 0xeab080 && r <= 0xed9eaf) ||
|
||||||
|| (r >= 0xefa480 && r <= 0xefac7f)
|
(r >= 0xefa480 && r <= 0xefac7f) ||
|
||||||
|| (r >= 0xefb8b8 && r <= 0xefb9af) {
|
(r >= 0xefb8b8 && r <= 0xefb9af) {
|
||||||
// half marks
|
// half marks
|
||||||
l++
|
l++
|
||||||
}
|
}
|
||||||
|
// vfmt on
|
||||||
}
|
}
|
||||||
4 {
|
4 {
|
||||||
r := u64((u32(c) << 24) | unsafe {
|
r := u64((u32(c) << 24) | unsafe {
|
||||||
@ -176,12 +179,15 @@ pub fn utf8_str_visible_length(s string) int {
|
|||||||
// Enclosed Ideographic Supplement
|
// Enclosed Ideographic Supplement
|
||||||
// Emoji
|
// Emoji
|
||||||
// CJK Unified Ideographs Extension B-G
|
// CJK Unified Ideographs Extension B-G
|
||||||
if (r >= 0x0f9f8880 && r <= 0xf09f8a8f)
|
// TODO: remove this workaround for v2's parser
|
||||||
|| (r >= 0xf09f8c80 && r <= 0xf09f9c90)
|
// vfmt off
|
||||||
|| (r >= 0xf09fa490 && r <= 0xf09fa7af)
|
if (r >= 0x0f9f8880 && r <= 0xf09f8a8f) ||
|
||||||
|| (r >= 0xf0a08080 && r <= 0xf180807f) {
|
(r >= 0xf09f8c80 && r <= 0xf09f9c90) ||
|
||||||
|
(r >= 0xf09fa490 && r <= 0xf09fa7af) ||
|
||||||
|
(r >= 0xf0a08080 && r <= 0xf180807f) {
|
||||||
l++
|
l++
|
||||||
}
|
}
|
||||||
|
// vfmt on
|
||||||
}
|
}
|
||||||
else {}
|
else {}
|
||||||
}
|
}
|
||||||
|
@ -8,7 +8,7 @@ import sync
|
|||||||
// TODO: finish fileset / file / base pos etc
|
// TODO: finish fileset / file / base pos etc
|
||||||
|
|
||||||
// compact encoding of a source position within a file set
|
// compact encoding of a source position within a file set
|
||||||
type Pos = int
|
pub type Pos = int
|
||||||
|
|
||||||
pub struct Position {
|
pub struct Position {
|
||||||
pub:
|
pub:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user