mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
scanner: enable 0oxx to handle octals
This commit is contained in:
parent
26fa833984
commit
adb1d3f8c9
@ -113,3 +113,10 @@ fn test_hex() {
|
|||||||
x := u64(10)
|
x := u64(10)
|
||||||
assert x.hex() == '0xa'
|
assert x.hex() == '0xa'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn test_oct() {
|
||||||
|
x1 := 0o12
|
||||||
|
assert x1 == 10
|
||||||
|
x2 := 012
|
||||||
|
assert x2 == 10
|
||||||
|
}
|
||||||
|
@ -122,7 +122,7 @@ fn filter_num_sep(txt byteptr, start int, end int) string {
|
|||||||
mut i := start
|
mut i := start
|
||||||
mut i1 := 0
|
mut i1 := 0
|
||||||
for i < end {
|
for i < end {
|
||||||
if txt[i] != num_sep {
|
if txt[i] != num_sep && txt[i] != `o` {
|
||||||
b[i1]=txt[i]
|
b[i1]=txt[i]
|
||||||
i1++
|
i1++
|
||||||
}
|
}
|
||||||
@ -172,17 +172,13 @@ fn (s mut Scanner) ident_hex_number() string {
|
|||||||
|
|
||||||
fn (s mut Scanner) ident_oct_number() string {
|
fn (s mut Scanner) ident_oct_number() string {
|
||||||
start_pos := s.pos
|
start_pos := s.pos
|
||||||
|
s.pos += 2 // skip '0o'
|
||||||
for {
|
for {
|
||||||
if s.pos >= s.text.len {
|
if s.pos >= s.text.len {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
c := s.text[s.pos]
|
c := s.text[s.pos]
|
||||||
if c.is_digit() {
|
|
||||||
if !c.is_oct_digit() && c != num_sep {
|
if !c.is_oct_digit() && c != num_sep {
|
||||||
s.error('malformed octal constant')
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
s.pos++
|
s.pos++
|
||||||
@ -253,12 +249,12 @@ fn (s mut Scanner) ident_number() string {
|
|||||||
if s.expect('0x', s.pos) {
|
if s.expect('0x', s.pos) {
|
||||||
return s.ident_hex_number()
|
return s.ident_hex_number()
|
||||||
}
|
}
|
||||||
|
if s.expect('0o', s.pos) {
|
||||||
|
return s.ident_oct_number()
|
||||||
|
}
|
||||||
if s.expect('0.', s.pos) || s.expect('0e', s.pos) {
|
if s.expect('0.', s.pos) || s.expect('0e', s.pos) {
|
||||||
return s.ident_dec_number()
|
return s.ident_dec_number()
|
||||||
}
|
}
|
||||||
if s.text[s.pos] == `0` {
|
|
||||||
return s.ident_oct_number()
|
|
||||||
}
|
|
||||||
return s.ident_dec_number()
|
return s.ident_dec_number()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -116,7 +116,7 @@ fn filter_num_sep(txt byteptr, start int, end int) string {
|
|||||||
mut i := start
|
mut i := start
|
||||||
mut i1 := 0
|
mut i1 := 0
|
||||||
for i < end {
|
for i < end {
|
||||||
if txt[i] != num_sep {
|
if txt[i] != num_sep && txt[i] != `o` {
|
||||||
b[i1] = txt[i]
|
b[i1] = txt[i]
|
||||||
i1++
|
i1++
|
||||||
}
|
}
|
||||||
@ -168,17 +168,13 @@ fn (s mut Scanner) ident_hex_number() string {
|
|||||||
|
|
||||||
fn (s mut Scanner) ident_oct_number() string {
|
fn (s mut Scanner) ident_oct_number() string {
|
||||||
start_pos := s.pos
|
start_pos := s.pos
|
||||||
|
s.pos += 2 // skip '0o'
|
||||||
for {
|
for {
|
||||||
if s.pos >= s.text.len {
|
if s.pos >= s.text.len {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
c := s.text[s.pos]
|
c := s.text[s.pos]
|
||||||
if c.is_digit() {
|
|
||||||
if !c.is_oct_digit() && c != num_sep {
|
if !c.is_oct_digit() && c != num_sep {
|
||||||
s.error('malformed octal constant')
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
s.pos++
|
s.pos++
|
||||||
@ -247,12 +243,12 @@ fn (s mut Scanner) ident_number() string {
|
|||||||
if s.expect('0x', s.pos) {
|
if s.expect('0x', s.pos) {
|
||||||
return s.ident_hex_number()
|
return s.ident_hex_number()
|
||||||
}
|
}
|
||||||
|
if s.expect('0o', s.pos) {
|
||||||
|
return s.ident_oct_number()
|
||||||
|
}
|
||||||
if s.expect('0.', s.pos) || s.expect('0e', s.pos) {
|
if s.expect('0.', s.pos) || s.expect('0e', s.pos) {
|
||||||
return s.ident_dec_number()
|
return s.ident_dec_number()
|
||||||
}
|
}
|
||||||
if s.text[s.pos] == `0` {
|
|
||||||
return s.ident_oct_number()
|
|
||||||
}
|
|
||||||
return s.ident_dec_number()
|
return s.ident_dec_number()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user