mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
all: byte => u8
This commit is contained in:
@@ -104,20 +104,20 @@ fn (c Checker) check_number(num ast.Number) ? {
|
||||
is_float := lit_lower_case.all_before('e').contains('.')
|
||||
has_exponent_notation := lit_lower_case.contains('e')
|
||||
float_decimal_index := lit.index('.') or { -1 }
|
||||
// mut is_first_digit := byte(lit[0]).is_digit()
|
||||
mut ascii := byte(lit[0]).ascii_str()
|
||||
// mut is_first_digit := u8(lit[0]).is_digit()
|
||||
mut ascii := u8(lit[0]).ascii_str()
|
||||
is_sign_prefixed := lit[0] in [`+`, `-`]
|
||||
mut lit_sans_sign := lit
|
||||
if is_sign_prefixed { // +/- ...
|
||||
lit_sans_sign = lit[1..]
|
||||
hex_bin_oct = is_hex_bin_oct_prefixed(lit_sans_sign)
|
||||
if hex_bin_oct {
|
||||
ascii = byte(lit[0]).ascii_str()
|
||||
ascii = u8(lit[0]).ascii_str()
|
||||
return error(@MOD + '.' + @STRUCT + '.' + @FN +
|
||||
' numbers like "$lit" (hex, octal and binary) can not start with `$ascii` in ...${c.excerpt(num.pos)}...')
|
||||
}
|
||||
if lit.len > 1 && lit_sans_sign.starts_with('0') && !lit_sans_sign.starts_with('0.') {
|
||||
ascii = byte(lit_sans_sign[0]).ascii_str()
|
||||
ascii = u8(lit_sans_sign[0]).ascii_str()
|
||||
return error(@MOD + '.' + @STRUCT + '.' + @FN +
|
||||
' numbers like "$lit" can not start with `$ascii` in ...${c.excerpt(num.pos)}...')
|
||||
}
|
||||
@@ -198,7 +198,7 @@ fn (c Checker) check_number(num ast.Number) ? {
|
||||
}
|
||||
last := lit[lit.len - 1]
|
||||
if last in scanner.digit_extras {
|
||||
ascii = byte(last).ascii_str()
|
||||
ascii = u8(last).ascii_str()
|
||||
return error(@MOD + '.' + @STRUCT + '.' + @FN +
|
||||
' numbers like "$lit" (float) can not end with `$ascii` in ...${c.excerpt(num.pos)}...')
|
||||
}
|
||||
@@ -215,12 +215,12 @@ fn (c Checker) check_number(num ast.Number) ? {
|
||||
if r !in [`0`, `1`, `2`, `3`, `4`, `5`, `6`, `7`, `8`, `9`, `.`, `e`, `E`, `-`, `+`,
|
||||
`_`] {
|
||||
return error(@MOD + '.' + @STRUCT + '.' + @FN +
|
||||
' numbers like "$lit" (float) can not contain `${byte(r).ascii_str()}` in ...${c.excerpt(num.pos)}...')
|
||||
' numbers like "$lit" (float) can not contain `${u8(r).ascii_str()}` in ...${c.excerpt(num.pos)}...')
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if lit.len > 1 && lit.starts_with('0') && lit[1] !in [`b`, `o`, `x`] {
|
||||
ascii = byte(lit[0]).ascii_str()
|
||||
ascii = u8(lit[0]).ascii_str()
|
||||
return error(@MOD + '.' + @STRUCT + '.' + @FN +
|
||||
' numbers like "$lit" can not start with `$ascii` in ...${c.excerpt(num.pos)}...')
|
||||
}
|
||||
@@ -425,9 +425,9 @@ fn (c Checker) check_quoted_escapes(q ast.Quoted) ? {
|
||||
if ch == scanner.end_of_text {
|
||||
break
|
||||
}
|
||||
ch_byte := byte(ch)
|
||||
ch_byte := u8(ch)
|
||||
if ch == `\\` {
|
||||
next_ch := byte(s.at())
|
||||
next_ch := u8(s.at())
|
||||
|
||||
if next_ch == `\\` {
|
||||
s.next()
|
||||
@@ -452,7 +452,7 @@ fn (c Checker) check_quoted_escapes(q ast.Quoted) ? {
|
||||
if !(ch_ == ` ` || ch_ == `\t`) {
|
||||
st := s.state()
|
||||
return error(@MOD + '.' + @STRUCT + '.' + @FN +
|
||||
' invalid character `${byte(ch_).ascii_str()}` after `$escape` at ($st.line_nr,$st.col) in ...${c.excerpt(q.pos)}...')
|
||||
' invalid character `${u8(ch_).ascii_str()}` after `$escape` at ($st.line_nr,$st.col) in ...${c.excerpt(q.pos)}...')
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -558,7 +558,7 @@ pub fn (c Checker) check_comment(comment ast.Comment) ? {
|
||||
if ch == scanner.end_of_text {
|
||||
break
|
||||
}
|
||||
ch_byte := byte(ch)
|
||||
ch_byte := u8(ch)
|
||||
// Check for carrige return
|
||||
if ch_byte == 0x0D {
|
||||
st := s.state()
|
||||
@@ -569,7 +569,7 @@ pub fn (c Checker) check_comment(comment ast.Comment) ? {
|
||||
if util.is_illegal_ascii_control_character(ch_byte) {
|
||||
st := s.state()
|
||||
return error(@MOD + '.' + @STRUCT + '.' + @FN +
|
||||
' control character `$ch_byte.hex()` is not allowed ($st.line_nr,$st.col) "${byte(s.at()).ascii_str()}" near ...${s.excerpt(st.pos, 10)}...')
|
||||
' control character `$ch_byte.hex()` is not allowed ($st.line_nr,$st.col) "${u8(s.at()).ascii_str()}" near ...${s.excerpt(st.pos, 10)}...')
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -92,7 +92,7 @@ pub fn decode_quoted_escapes(mut q ast.Quoted) ? {
|
||||
if ch == scanner.end_of_text {
|
||||
break
|
||||
}
|
||||
ch_byte := byte(ch)
|
||||
ch_byte := u8(ch)
|
||||
|
||||
if eat_whitespace && ch_byte.is_space() {
|
||||
continue
|
||||
@@ -101,7 +101,7 @@ pub fn decode_quoted_escapes(mut q ast.Quoted) ? {
|
||||
|
||||
if ch == `\\` {
|
||||
ch_next := s.at()
|
||||
ch_next_byte := byte(ch_next)
|
||||
ch_next_byte := u8(ch_next)
|
||||
|
||||
if ch_next == `\\` {
|
||||
decoded_s += ch_next_byte.ascii_str()
|
||||
@@ -155,13 +155,13 @@ pub fn decode_quoted_escapes(mut q ast.Quoted) ? {
|
||||
escape := ch_byte.ascii_str() + ch_next_byte.ascii_str()
|
||||
// Decode unicode escapes
|
||||
if escape.to_lower() == '\\u' {
|
||||
is_valid_short := byte(s.peek(1)).is_hex_digit() && byte(s.peek(2)).is_hex_digit()
|
||||
&& byte(s.peek(3)).is_hex_digit() && byte(s.peek(4)).is_hex_digit()
|
||||
is_valid_short := u8(s.peek(1)).is_hex_digit() && u8(s.peek(2)).is_hex_digit()
|
||||
&& u8(s.peek(3)).is_hex_digit() && u8(s.peek(4)).is_hex_digit()
|
||||
|
||||
if is_valid_short {
|
||||
is_valid_long := byte(s.peek(5)).is_hex_digit()
|
||||
&& byte(s.peek(6)).is_hex_digit() && byte(s.peek(7)).is_hex_digit()
|
||||
&& byte(s.peek(8)).is_hex_digit()
|
||||
is_valid_long := u8(s.peek(5)).is_hex_digit()
|
||||
&& u8(s.peek(6)).is_hex_digit() && u8(s.peek(7)).is_hex_digit()
|
||||
&& u8(s.peek(8)).is_hex_digit()
|
||||
// If it's a long type Unicode (\UXXXXXXXX) with a maximum of 10 chars: '\' + 'U' + 8 hex characters
|
||||
// we pass in 10 characters from the `u`/`U` which is the longest possible sequence
|
||||
// of 9 chars plus one extra.
|
||||
|
@@ -100,7 +100,7 @@ pub fn (mut s Scanner) scan() ?token.Token {
|
||||
|
||||
for {
|
||||
c := s.next()
|
||||
byte_c := byte(c)
|
||||
byte_c := u8(c)
|
||||
if c == scanner.end_of_text {
|
||||
s.inc_line_number()
|
||||
util.printdbg(@MOD + '.' + @STRUCT + '.' + @FN, 'reached EOF')
|
||||
@@ -110,7 +110,7 @@ pub fn (mut s Scanner) scan() ?token.Token {
|
||||
ascii := byte_c.ascii_str()
|
||||
util.printdbg(@MOD + '.' + @STRUCT + '.' + @FN, 'current char "$ascii"')
|
||||
|
||||
if byte_c == byte(0x0) {
|
||||
if byte_c == u8(0x0) {
|
||||
s.reset()
|
||||
return error(@MOD + '.' + @STRUCT + '.' + @FN +
|
||||
' NULL control character `$c.hex()` is not allowed at ($s.line_nr,$s.col) "$ascii" near ...${s.excerpt(s.pos, 5)}...')
|
||||
@@ -132,7 +132,7 @@ pub fn (mut s Scanner) scan() ?token.Token {
|
||||
return s.new_token(.number, num, num.len)
|
||||
}
|
||||
|
||||
is_signed_number := is_sign && byte(s.at()).is_digit() && !byte(s.peek(-1)).is_digit()
|
||||
is_signed_number := is_sign && u8(s.at()).is_digit() && !u8(s.peek(-1)).is_digit()
|
||||
is_digit := byte_c.is_digit()
|
||||
if is_digit || is_signed_number {
|
||||
num := s.extract_number() ?
|
||||
@@ -158,8 +158,8 @@ pub fn (mut s Scanner) scan() ?token.Token {
|
||||
}
|
||||
// Date-Time in RFC 3339 is allowed to have a space between the date and time in supplement to the 'T'
|
||||
// so we allow space characters to slip through to the parser if the space is between two digits...
|
||||
// util.printdbg(@MOD + '.' + @STRUCT + '.' + @FN, '"'+byte(s.peek(-1)).ascii_str()+'" < "$ascii" > "'+byte(s.at()).ascii_str()+'"')
|
||||
if c == ` ` && byte(s.peek(-1)).is_digit() && byte(s.at()).is_digit() {
|
||||
// util.printdbg(@MOD + '.' + @STRUCT + '.' + @FN, '"'+u8(s.peek(-1)).ascii_str()+'" < "$ascii" > "'+u8(s.at()).ascii_str()+'"')
|
||||
if c == ` ` && u8(s.peek(-1)).is_digit() && u8(s.at()).is_digit() {
|
||||
util.printdbg(@MOD + '.' + @STRUCT + '.' + @FN, 'identified, what could be, a space between a RFC 3339 date and time ("$ascii") ($ascii.len)')
|
||||
return s.new_token(token.Kind.whitespace, ascii, ascii.len)
|
||||
}
|
||||
@@ -358,7 +358,7 @@ fn (mut s Scanner) ignore_line() ?string {
|
||||
util.printdbg(@MOD + '.' + @STRUCT + '.' + @FN, ' ignoring until EOL...')
|
||||
start := s.pos
|
||||
for c := s.at(); c != scanner.end_of_text && c != `\n`; c = s.at() {
|
||||
util.printdbg(@MOD + '.' + @STRUCT + '.' + @FN, 'skipping "${byte(c).ascii_str()} / $c"')
|
||||
util.printdbg(@MOD + '.' + @STRUCT + '.' + @FN, 'skipping "${u8(c).ascii_str()} / $c"')
|
||||
if s.at_crlf() {
|
||||
util.printdbg(@MOD + '.' + @STRUCT + '.' + @FN, 'letting `\\r\\n` slip through')
|
||||
break
|
||||
@@ -383,7 +383,7 @@ fn (mut s Scanner) extract_key() string {
|
||||
s.col--
|
||||
start := s.pos
|
||||
for s.pos < s.text.len {
|
||||
c := byte(s.at())
|
||||
c := u8(s.at())
|
||||
if !(util.is_key_char(c) || c.is_digit() || c in [`_`, `-`]) {
|
||||
break
|
||||
}
|
||||
@@ -403,7 +403,7 @@ fn (mut s Scanner) extract_string() ?string {
|
||||
// a byte that is the start of a string so we rewind it to start at the correct
|
||||
s.pos--
|
||||
s.col--
|
||||
quote := byte(s.at())
|
||||
quote := u8(s.at())
|
||||
start := s.pos
|
||||
mut lit := quote.ascii_str()
|
||||
|
||||
@@ -420,14 +420,14 @@ fn (mut s Scanner) extract_string() ?string {
|
||||
|
||||
if s.pos >= s.text.len {
|
||||
return error(@MOD + '.' + @STRUCT + '.' + @FN +
|
||||
' unfinished single-line string literal `$quote.ascii_str()` started at $start ($s.line_nr,$s.col) "${byte(s.at()).ascii_str()}" near ...${s.excerpt(s.pos, 5)}...')
|
||||
' unfinished single-line string literal `$quote.ascii_str()` started at $start ($s.line_nr,$s.col) "${u8(s.at()).ascii_str()}" near ...${s.excerpt(s.pos, 5)}...')
|
||||
}
|
||||
|
||||
c := byte(s.at())
|
||||
c := u8(s.at())
|
||||
util.printdbg(@MOD + '.' + @STRUCT + '.' + @FN, 'c: `$c.ascii_str()` / $c (quote type: $quote/$quote.ascii_str())')
|
||||
|
||||
// Check for escaped chars
|
||||
if c == byte(92) {
|
||||
if c == u8(92) {
|
||||
esc, skip := s.handle_escapes(quote, is_multiline)
|
||||
lit += esc
|
||||
if skip > 0 {
|
||||
@@ -439,7 +439,7 @@ fn (mut s Scanner) extract_string() ?string {
|
||||
// Check for control characters (allow TAB)
|
||||
if util.is_illegal_ascii_control_character(c) {
|
||||
return error(@MOD + '.' + @STRUCT + '.' + @FN +
|
||||
' control character `$c.hex()` is not allowed at $start ($s.line_nr,$s.col) "${byte(s.at()).ascii_str()}" near ...${s.excerpt(s.pos, 5)}...')
|
||||
' control character `$c.hex()` is not allowed at $start ($s.line_nr,$s.col) "${u8(s.at()).ascii_str()}" near ...${s.excerpt(s.pos, 5)}...')
|
||||
}
|
||||
|
||||
if c == quote {
|
||||
@@ -453,7 +453,7 @@ fn (mut s Scanner) extract_string() ?string {
|
||||
// Don't eat multiple lines in single-line mode
|
||||
if lit.contains('\n') {
|
||||
return error(@MOD + '.' + @STRUCT + '.' + @FN +
|
||||
' unfinished single-line string literal `$quote.ascii_str()` started at $start ($s.line_nr,$s.col) "${byte(s.at()).ascii_str()}" near ...${s.excerpt(s.pos, 5)}...')
|
||||
' unfinished single-line string literal `$quote.ascii_str()` started at $start ($s.line_nr,$s.col) "${u8(s.at()).ascii_str()}" near ...${s.excerpt(s.pos, 5)}...')
|
||||
}
|
||||
}
|
||||
return lit
|
||||
@@ -466,7 +466,7 @@ fn (mut s Scanner) extract_string() ?string {
|
||||
fn (mut s Scanner) extract_multiline_string() ?string {
|
||||
// extract_multiline_string is called from extract_string so we know the 3 first
|
||||
// characters is the quotes
|
||||
quote := byte(s.at())
|
||||
quote := u8(s.at())
|
||||
start := s.pos
|
||||
mut lit := quote.ascii_str() + quote.ascii_str() + quote.ascii_str()
|
||||
|
||||
@@ -482,10 +482,10 @@ fn (mut s Scanner) extract_multiline_string() ?string {
|
||||
|
||||
if s.pos >= s.text.len {
|
||||
return error(@MOD + '.' + @STRUCT + '.' + @FN +
|
||||
' unfinished multi-line string literal ($quote.ascii_str()$quote.ascii_str()$quote.ascii_str()) started at $start ($s.line_nr,$s.col) "${byte(s.at()).ascii_str()}" near ...${s.excerpt(s.pos, 5)}...')
|
||||
' unfinished multi-line string literal ($quote.ascii_str()$quote.ascii_str()$quote.ascii_str()) started at $start ($s.line_nr,$s.col) "${u8(s.at()).ascii_str()}" near ...${s.excerpt(s.pos, 5)}...')
|
||||
}
|
||||
|
||||
c := byte(s.at())
|
||||
c := u8(s.at())
|
||||
util.printdbg(@MOD + '.' + @STRUCT + '.' + @FN, 'c: `$c.ascii_str()` / $c (quote type: $quote/$quote.ascii_str())')
|
||||
|
||||
if c == `\n` {
|
||||
@@ -495,7 +495,7 @@ fn (mut s Scanner) extract_multiline_string() ?string {
|
||||
continue
|
||||
}
|
||||
// Check for escaped chars
|
||||
if c == byte(92) {
|
||||
if c == u8(92) {
|
||||
esc, skip := s.handle_escapes(quote, true)
|
||||
lit += esc
|
||||
if skip > 0 {
|
||||
@@ -507,7 +507,7 @@ fn (mut s Scanner) extract_multiline_string() ?string {
|
||||
// Check for control characters (allow TAB)
|
||||
if util.is_illegal_ascii_control_character(c) {
|
||||
return error(@MOD + '.' + @STRUCT + '.' + @FN +
|
||||
' control character `$c.hex()` is not allowed at $start ($s.line_nr,$s.col) "${byte(s.at()).ascii_str()}" near ...${s.excerpt(s.pos, 5)}...')
|
||||
' control character `$c.hex()` is not allowed at $start ($s.line_nr,$s.col) "${u8(s.at()).ascii_str()}" near ...${s.excerpt(s.pos, 5)}...')
|
||||
}
|
||||
|
||||
if c == quote {
|
||||
@@ -537,12 +537,12 @@ fn (mut s Scanner) extract_multiline_string() ?string {
|
||||
// handle_escapes returns any escape character sequence.
|
||||
// For escape sequence validation see `Checker.check_quoted_escapes`.
|
||||
fn (mut s Scanner) handle_escapes(quote byte, is_multiline bool) (string, int) {
|
||||
c := byte(s.at())
|
||||
c := u8(s.at())
|
||||
mut lit := c.ascii_str()
|
||||
is_literal_string := quote == `'`
|
||||
if !is_literal_string {
|
||||
if s.peek(1) == `u` && byte(s.peek(2)).is_hex_digit() && byte(s.peek(3)).is_hex_digit()
|
||||
&& byte(s.peek(4)).is_hex_digit() && byte(s.peek(5)).is_hex_digit() {
|
||||
if s.peek(1) == `u` && u8(s.peek(2)).is_hex_digit() && u8(s.peek(3)).is_hex_digit()
|
||||
&& u8(s.peek(4)).is_hex_digit() && u8(s.peek(5)).is_hex_digit() {
|
||||
lit += s.text[s.pos + 1..s.pos + 6] //.ascii_str()
|
||||
util.printdbg(@MOD + '.' + @STRUCT + '.' + @FN, 'gulp escaped unicode `$lit`')
|
||||
return lit, 5
|
||||
@@ -559,12 +559,12 @@ fn (mut s Scanner) handle_escapes(quote byte, is_multiline bool) (string, int) {
|
||||
}
|
||||
if is_literal_string {
|
||||
if s.peek(1) == quote {
|
||||
util.printdbg(@MOD + '.' + @STRUCT + '.' + @FN, 'ignore escape `$lit${byte(s.peek(1)).ascii_str()}` in literal string')
|
||||
util.printdbg(@MOD + '.' + @STRUCT + '.' + @FN, 'ignore escape `$lit${u8(s.peek(1)).ascii_str()}` in literal string')
|
||||
return '', 0
|
||||
}
|
||||
}
|
||||
|
||||
lit += byte(s.peek(1)).ascii_str()
|
||||
lit += u8(s.peek(1)).ascii_str()
|
||||
util.printdbg(@MOD + '.' + @STRUCT + '.' + @FN, 'gulp escaped `$lit`')
|
||||
return lit, 1
|
||||
}
|
||||
@@ -582,22 +582,22 @@ fn (mut s Scanner) extract_number() ?string {
|
||||
start := s.pos
|
||||
|
||||
mut c := s.at()
|
||||
is_digit := byte(c).is_digit()
|
||||
is_digit := u8(c).is_digit()
|
||||
if !(is_digit || c in [`+`, `-`]) {
|
||||
return error(@MOD + '.' + @STRUCT + '.' + @FN +
|
||||
' ${byte(c).ascii_str()} is not a number at ${s.excerpt(s.pos, 10)}')
|
||||
' ${u8(c).ascii_str()} is not a number at ${s.excerpt(s.pos, 10)}')
|
||||
}
|
||||
s.pos++
|
||||
s.col++
|
||||
for s.pos < s.text.len {
|
||||
c = s.at()
|
||||
// Handle signed exponent notation. I.e.: 3e2, 3E2, 3e-2, 3E+2, 3e0, 3.1e2, 3.1E2, -1E-1
|
||||
if c in [`e`, `E`] && s.peek(1) in [`+`, `-`] && byte(s.peek(2)).is_digit() {
|
||||
if c in [`e`, `E`] && s.peek(1) in [`+`, `-`] && u8(s.peek(2)).is_digit() {
|
||||
s.pos += 2
|
||||
s.col += 2
|
||||
}
|
||||
c = s.at()
|
||||
if !(byte(c).is_hex_digit() || c in scanner.digit_extras)
|
||||
if !(u8(c).is_hex_digit() || c in scanner.digit_extras)
|
||||
|| (c == `.` && s.is_left_of_assign) {
|
||||
break
|
||||
}
|
||||
@@ -622,7 +622,7 @@ fn (mut s Scanner) extract_nan_or_inf_number() ?string {
|
||||
mut c := s.at()
|
||||
if c !in [`+`, `-`, `n`, `i`] {
|
||||
return error(@MOD + '.' + @STRUCT + '.' + @FN +
|
||||
' ${byte(c).ascii_str()} is not a number at ${s.excerpt(s.pos, 10)}')
|
||||
' ${u8(c).ascii_str()} is not a number at ${s.excerpt(s.pos, 10)}')
|
||||
}
|
||||
s.pos++
|
||||
s.col++
|
||||
|
@@ -131,7 +131,7 @@ pub fn parse_dotted_key(key string) ?[]string {
|
||||
mut out := []string{}
|
||||
mut buf := ''
|
||||
mut in_string := false
|
||||
mut delim := byte(` `)
|
||||
mut delim := u8(` `)
|
||||
for ch in key {
|
||||
if ch in [`"`, `'`] {
|
||||
if !in_string {
|
||||
|
Reference in New Issue
Block a user