all: update assoc syntax (#8274)
parent
12897d1e2b
commit
dbf84520f1
|
@ -846,7 +846,9 @@ jobs:
|
||||||
- name: Install zzuf
|
- name: Install zzuf
|
||||||
run: sudo apt install -qq zzuf
|
run: sudo apt install -qq zzuf
|
||||||
- name: Build local v
|
- name: Build local v
|
||||||
run: make -j4
|
run: |
|
||||||
|
make -j4
|
||||||
|
./v -g cmd/tools/vtest-parser.v
|
||||||
- name: Run test-parser over fuzzed files
|
- name: Run test-parser over fuzzed files
|
||||||
run: |
|
run: |
|
||||||
zzuf -R '\x00-\x20\x7f-\xff' -r0.01 < examples/hello_world.v > examples/hello_world_fuzz.v
|
zzuf -R '\x00-\x20\x7f-\xff' -r0.01 < examples/hello_world.v > examples/hello_world_fuzz.v
|
||||||
|
|
|
@ -16,7 +16,7 @@ mut:
|
||||||
board Board
|
board Board
|
||||||
undo []Undo
|
undo []Undo
|
||||||
atickers [4][4]int
|
atickers [4][4]int
|
||||||
state GameState = .play
|
state GameState = .play
|
||||||
tile_format TileFormat = .normal
|
tile_format TileFormat = .normal
|
||||||
moves int
|
moves int
|
||||||
perf &Perf = 0
|
perf &Perf = 0
|
||||||
|
@ -47,7 +47,7 @@ struct Theme {
|
||||||
}
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
themes = [
|
themes = [
|
||||||
&Theme{
|
&Theme{
|
||||||
bg_color: gx.rgb(250, 248, 239)
|
bg_color: gx.rgb(250, 248, 239)
|
||||||
padding_color: gx.rgb(143, 130, 119)
|
padding_color: gx.rgb(143, 130, 119)
|
||||||
|
@ -55,18 +55,18 @@ const (
|
||||||
game_over_color: gx.rgb(190, 50, 50)
|
game_over_color: gx.rgb(190, 50, 50)
|
||||||
text_color: gx.black
|
text_color: gx.black
|
||||||
tile_colors: [
|
tile_colors: [
|
||||||
gx.rgb(205, 193, 180), // Empty / 0 tile
|
gx.rgb(205, 193, 180), /* Empty / 0 tile */
|
||||||
gx.rgb(238, 228, 218), // 2
|
gx.rgb(238, 228, 218), /* 2 */
|
||||||
gx.rgb(237, 224, 200), // 4
|
gx.rgb(237, 224, 200), /* 4 */
|
||||||
gx.rgb(242, 177, 121), // 8
|
gx.rgb(242, 177, 121), /* 8 */
|
||||||
gx.rgb(245, 149, 99), // 16
|
gx.rgb(245, 149, 99), /* 16 */
|
||||||
gx.rgb(246, 124, 95), // 32
|
gx.rgb(246, 124, 95), /* 32 */
|
||||||
gx.rgb(246, 94, 59), // 64
|
gx.rgb(246, 94, 59), /* 64 */
|
||||||
gx.rgb(237, 207, 114), // 128
|
gx.rgb(237, 207, 114), /* 128 */
|
||||||
gx.rgb(237, 204, 97), // 256
|
gx.rgb(237, 204, 97), /* 256 */
|
||||||
gx.rgb(237, 200, 80), // 512
|
gx.rgb(237, 200, 80), /* 512 */
|
||||||
gx.rgb(237, 197, 63), // 1024
|
gx.rgb(237, 197, 63), /* 1024 */
|
||||||
gx.rgb(237, 194, 46), // 2048
|
gx.rgb(237, 194, 46), /* 2048 */
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
&Theme{
|
&Theme{
|
||||||
|
@ -149,7 +149,7 @@ struct Undo {
|
||||||
}
|
}
|
||||||
|
|
||||||
struct TileLine {
|
struct TileLine {
|
||||||
ypos int
|
ypos int
|
||||||
mut:
|
mut:
|
||||||
field [5]int
|
field [5]int
|
||||||
points int
|
points int
|
||||||
|
@ -351,7 +351,8 @@ fn (mut b Board) is_game_over() bool {
|
||||||
if (x > 0 && fidx == b.field[y][x - 1]) ||
|
if (x > 0 && fidx == b.field[y][x - 1]) ||
|
||||||
(x < 4 - 1 && fidx == b.field[y][x + 1]) ||
|
(x < 4 - 1 && fidx == b.field[y][x + 1]) ||
|
||||||
(y > 0 && fidx == b.field[y - 1][x]) ||
|
(y > 0 && fidx == b.field[y - 1][x]) ||
|
||||||
(y < 4 - 1 && fidx == b.field[y + 1][x]) {
|
(y < 4 - 1 && fidx == b.field[y + 1][x])
|
||||||
|
{
|
||||||
// there are remaining merges
|
// there are remaining merges
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
@ -623,8 +624,8 @@ fn (app &App) draw() {
|
||||||
app.gg.draw_text(ww / 2, (m * 4 / 10) + ypad, 'Game Over', app.label_format(.game_over))
|
app.gg.draw_text(ww / 2, (m * 4 / 10) + ypad, 'Game Over', app.label_format(.game_over))
|
||||||
f := app.label_format(.tile)
|
f := app.label_format(.tile)
|
||||||
msg := $if android { 'Tap to restart' } $else { 'Press `r` to restart' }
|
msg := $if android { 'Tap to restart' } $else { 'Press `r` to restart' }
|
||||||
app.gg.draw_text(ww / 2, (m * 6 / 10) + ypad, msg, {
|
app.gg.draw_text(ww / 2, (m * 6 / 10) + ypad, msg, gx.TextCfg{
|
||||||
f |
|
...f
|
||||||
color: gx.white
|
color: gx.white
|
||||||
size: f.size * 3 / 4
|
size: f.size * 3 / 4
|
||||||
})
|
})
|
||||||
|
@ -649,7 +650,8 @@ fn (app &App) draw_tiles() {
|
||||||
toffset := app.ui.tile_size + app.ui.padding_size
|
toffset := app.ui.tile_size + app.ui.padding_size
|
||||||
tiles_size := min(app.ui.window_width, app.ui.window_height) - app.ui.border_size * 2
|
tiles_size := min(app.ui.window_width, app.ui.window_height) - app.ui.border_size * 2
|
||||||
// Draw the padding around the tiles
|
// Draw the padding around the tiles
|
||||||
app.gg.draw_rounded_rect(xstart, ystart, tiles_size / 2, tiles_size / 2, tiles_size / 24, app.theme.padding_color)
|
app.gg.draw_rounded_rect(xstart, ystart, tiles_size / 2, tiles_size / 2, tiles_size / 24,
|
||||||
|
app.theme.padding_color)
|
||||||
// Draw the actual tiles
|
// Draw the actual tiles
|
||||||
for y in 0 .. 4 {
|
for y in 0 .. 4 {
|
||||||
for x in 0 .. 4 {
|
for x in 0 .. 4 {
|
||||||
|
@ -670,8 +672,8 @@ fn (app &App) draw_tiles() {
|
||||||
xpos := xoffset + tw / 2
|
xpos := xoffset + tw / 2
|
||||||
ypos := yoffset + th / 2
|
ypos := yoffset + th / 2
|
||||||
mut fmt := app.label_format(.tile)
|
mut fmt := app.label_format(.tile)
|
||||||
fmt = {
|
fmt = gx.TextCfg{
|
||||||
fmt |
|
...fmt
|
||||||
size: int(f32(fmt.size - 1) / animation_length * anim_size)
|
size: int(f32(fmt.size - 1) / animation_length * anim_size)
|
||||||
}
|
}
|
||||||
match app.tile_format {
|
match app.tile_format {
|
||||||
|
@ -685,16 +687,16 @@ fn (app &App) draw_tiles() {
|
||||||
app.gg.draw_text(xpos, ypos, '2', fmt)
|
app.gg.draw_text(xpos, ypos, '2', fmt)
|
||||||
fs2 := int(f32(fmt.size) * 0.67)
|
fs2 := int(f32(fmt.size) * 0.67)
|
||||||
app.gg.draw_text(xpos + app.ui.tile_size / 10, ypos - app.ui.tile_size / 8,
|
app.gg.draw_text(xpos + app.ui.tile_size / 10, ypos - app.ui.tile_size / 8,
|
||||||
'$tidx', {
|
'$tidx', gx.TextCfg{
|
||||||
fmt |
|
...fmt
|
||||||
size: fs2
|
size: fs2
|
||||||
align: gx.HorizontalAlign.left
|
align: gx.HorizontalAlign.left
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
.shifts {
|
.shifts {
|
||||||
fs2 := int(f32(fmt.size) * 0.6)
|
fs2 := int(f32(fmt.size) * 0.6)
|
||||||
app.gg.draw_text(xpos, ypos, '2<<${tidx - 1}', {
|
app.gg.draw_text(xpos, ypos, '2<<${tidx - 1}', gx.TextCfg{
|
||||||
fmt |
|
...fmt
|
||||||
size: fs2
|
size: fs2
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -951,7 +953,7 @@ fn main() {
|
||||||
window_title_ = 'canvas'
|
window_title_ = 'canvas'
|
||||||
}
|
}
|
||||||
app.perf = &Perf{}
|
app.perf = &Perf{}
|
||||||
app.gg = gg.new_context({
|
app.gg = gg.new_context(
|
||||||
bg_color: app.theme.bg_color
|
bg_color: app.theme.bg_color
|
||||||
width: default_window_width
|
width: default_window_width
|
||||||
height: default_window_height
|
height: default_window_height
|
||||||
|
@ -963,6 +965,6 @@ fn main() {
|
||||||
init_fn: init
|
init_fn: init
|
||||||
user_data: app
|
user_data: app
|
||||||
font_path: font_path
|
font_path: font_path
|
||||||
})
|
)
|
||||||
app.gg.run()
|
app.gg.run()
|
||||||
}
|
}
|
||||||
|
|
|
@ -190,17 +190,17 @@ fn event(event &tui.Event, x voidptr) {
|
||||||
match event.code {
|
match event.code {
|
||||||
.f1, ._1 {
|
.f1, ._1 {
|
||||||
oevent := *event
|
oevent := *event
|
||||||
nevent := { oevent | button: tui.MouseButton.left, x: app.mouse_pos.x , y: app.mouse_pos.y }
|
nevent := tui.Event{ ...oevent, button: tui.MouseButton.left, x: app.mouse_pos.x , y: app.mouse_pos.y }
|
||||||
app.paint(nevent)
|
app.paint(nevent)
|
||||||
}
|
}
|
||||||
.f2, ._2 {
|
.f2, ._2 {
|
||||||
oevent := *event
|
oevent := *event
|
||||||
nevent := { oevent | button: tui.MouseButton.right, x: app.mouse_pos.x , y: app.mouse_pos.y }
|
nevent := tui.Event{ ...oevent, button: tui.MouseButton.right, x: app.mouse_pos.x , y: app.mouse_pos.y }
|
||||||
app.paint(nevent)
|
app.paint(nevent)
|
||||||
}
|
}
|
||||||
.space {
|
.space {
|
||||||
oevent := *event
|
oevent := *event
|
||||||
nevent := { oevent | button: tui.MouseButton.middle, x: app.mouse_pos.x , y: app.mouse_pos.y }
|
nevent := tui.Event{ ...oevent, button: tui.MouseButton.middle, x: app.mouse_pos.x , y: app.mouse_pos.y }
|
||||||
app.paint(nevent)
|
app.paint(nevent)
|
||||||
}
|
}
|
||||||
.j, .down {
|
.j, .down {
|
||||||
|
|
|
@ -88,8 +88,8 @@ pub fn (mut c Client) send(config Mail) ? {
|
||||||
c.send_mailfrom(from) or { return error('Sending mailfrom failed') }
|
c.send_mailfrom(from) or { return error('Sending mailfrom failed') }
|
||||||
c.send_mailto(config.to) or { return error('Sending mailto failed') }
|
c.send_mailto(config.to) or { return error('Sending mailto failed') }
|
||||||
c.send_data() or { return error('Sending mail data failed') }
|
c.send_data() or { return error('Sending mail data failed') }
|
||||||
c.send_body({
|
c.send_body(Mail{
|
||||||
config |
|
...config
|
||||||
from: from
|
from: from
|
||||||
}) or { return error('Sending mail body failed') }
|
}) or { return error('Sending mail body failed') }
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,24 +44,23 @@ fn test_smtp() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
assert true
|
assert true
|
||||||
// client.send({ send_cfg | body_type: .html, body: '<html><h1>HTML V email!</h1></html>' }) or { assert false return }
|
client.send(smtp.Mail{
|
||||||
client.send({
|
...send_cfg
|
||||||
send_cfg |
|
|
||||||
from: 'alexander@vlang.io'
|
from: 'alexander@vlang.io'
|
||||||
}) or {
|
}) or {
|
||||||
assert false
|
assert false
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
client.send({
|
client.send(smtp.Mail{
|
||||||
send_cfg |
|
...send_cfg
|
||||||
cc: 'alexander@vlang.io,joe@vlang.io'
|
cc: 'alexander@vlang.io,joe@vlang.io'
|
||||||
bcc: 'spytheman@vlang.io'
|
bcc: 'spytheman@vlang.io'
|
||||||
}) or {
|
}) or {
|
||||||
assert false
|
assert false
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
client.send({
|
client.send(smtp.Mail{
|
||||||
send_cfg |
|
...send_cfg
|
||||||
date: time.now().add_days(1000)
|
date: time.now().add_days(1000)
|
||||||
}) or {
|
}) or {
|
||||||
assert false
|
assert false
|
||||||
|
|
|
@ -274,8 +274,8 @@ fn single_char(buf string) &Event {
|
||||||
// special handling for `ctrl + letter`
|
// special handling for `ctrl + letter`
|
||||||
|
|
||||||
// TODO: Fix assoc in V and remove this workaround :/
|
// TODO: Fix assoc in V and remove this workaround :/
|
||||||
// 1 ... 26 { event = { event | code: KeyCode(96 | ch), modifiers: ctrl } }
|
// 1 ... 26 { event = Event{ ...event, code: KeyCode(96 | ch), modifiers: ctrl } }
|
||||||
// 65 ... 90 { event = { event | code: KeyCode(32 | ch), modifiers: shift } }
|
// 65 ... 90 { event = Event{ ...event, code: KeyCode(32 | ch), modifiers: shift } }
|
||||||
|
|
||||||
|
|
||||||
// The bit `or`s here are really just `+`'s, just written in this way for a tiny performance improvement
|
// The bit `or`s here are really just `+`'s, just written in this way for a tiny performance improvement
|
||||||
|
@ -330,7 +330,6 @@ fn escape_sequence(buf_ string) (&Event, int) {
|
||||||
|
|
||||||
if buf.len == 1 {
|
if buf.len == 1 {
|
||||||
c := single_char(buf)
|
c := single_char(buf)
|
||||||
// return { c | modifiers: c.modifiers | alt }, 2
|
|
||||||
|
|
||||||
return &Event{
|
return &Event{
|
||||||
typ: c.typ
|
typ: c.typ
|
||||||
|
|
|
@ -158,8 +158,8 @@ pub fn new_time(t Time) Time {
|
||||||
tm_year: t.year - 1900
|
tm_year: t.year - 1900
|
||||||
}
|
}
|
||||||
utime := u64(make_unix_time(tt))
|
utime := u64(make_unix_time(tt))
|
||||||
return {
|
return Time{
|
||||||
t |
|
...t
|
||||||
unix: utime
|
unix: utime
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3648,9 +3648,9 @@ fn (mut c Checker) comptime_call(mut node ast.ComptimeCall) table.Type {
|
||||||
}
|
}
|
||||||
if node.is_vweb {
|
if node.is_vweb {
|
||||||
// TODO assoc parser bug
|
// TODO assoc parser bug
|
||||||
pref := *c.pref
|
pref_ := *c.pref
|
||||||
pref2 := {
|
pref2 := pref.Preferences{
|
||||||
pref |
|
...pref_
|
||||||
is_vweb: true
|
is_vweb: true
|
||||||
}
|
}
|
||||||
mut c2 := new_checker(c.table, pref2)
|
mut c2 := new_checker(c.table, pref2)
|
||||||
|
|
|
@ -40,12 +40,14 @@ fn test_all() {
|
||||||
os.chdir(vroot)
|
os.chdir(vroot)
|
||||||
checker_dir := 'vlib/v/checker/tests'
|
checker_dir := 'vlib/v/checker/tests'
|
||||||
parser_dir := 'vlib/v/parser/tests'
|
parser_dir := 'vlib/v/parser/tests'
|
||||||
|
scanner_dir := 'vlib/v/scanner/tests'
|
||||||
module_dir := '$checker_dir/modules'
|
module_dir := '$checker_dir/modules'
|
||||||
global_dir := '$checker_dir/globals'
|
global_dir := '$checker_dir/globals'
|
||||||
run_dir := '$checker_dir/run'
|
run_dir := '$checker_dir/run'
|
||||||
//
|
//
|
||||||
checker_tests := get_tests_in_dir(checker_dir, false)
|
checker_tests := get_tests_in_dir(checker_dir, false)
|
||||||
parser_tests := get_tests_in_dir(parser_dir, false)
|
parser_tests := get_tests_in_dir(parser_dir, false)
|
||||||
|
scanner_tests := get_tests_in_dir(scanner_dir, false)
|
||||||
global_tests := get_tests_in_dir(global_dir, false)
|
global_tests := get_tests_in_dir(global_dir, false)
|
||||||
module_tests := get_tests_in_dir(module_dir, true)
|
module_tests := get_tests_in_dir(module_dir, true)
|
||||||
run_tests := get_tests_in_dir(run_dir, false)
|
run_tests := get_tests_in_dir(run_dir, false)
|
||||||
|
@ -53,6 +55,7 @@ fn test_all() {
|
||||||
mut tasks := []TaskDescription{}
|
mut tasks := []TaskDescription{}
|
||||||
tasks.add(vexe, parser_dir, '-prod', '.out', parser_tests, false)
|
tasks.add(vexe, parser_dir, '-prod', '.out', parser_tests, false)
|
||||||
tasks.add(vexe, checker_dir, '-prod', '.out', checker_tests, false)
|
tasks.add(vexe, checker_dir, '-prod', '.out', checker_tests, false)
|
||||||
|
tasks.add(vexe, scanner_dir, '-prod', '.out', scanner_tests, false)
|
||||||
tasks.add(vexe, checker_dir, '-d mysymbol run', '.mysymbol.run.out', ['custom_comptime_define_error.vv'],
|
tasks.add(vexe, checker_dir, '-d mysymbol run', '.mysymbol.run.out', ['custom_comptime_define_error.vv'],
|
||||||
false)
|
false)
|
||||||
tasks.add(vexe, checker_dir, '-d mydebug run', '.mydebug.run.out', ['custom_comptime_define_if_flag.vv'],
|
tasks.add(vexe, checker_dir, '-d mydebug run', '.mydebug.run.out', ['custom_comptime_define_if_flag.vv'],
|
||||||
|
|
|
@ -369,13 +369,11 @@ fn (mut p Parser) infix_expr(left ast.Expr) ast.Expr {
|
||||||
p.or_is_handled = true
|
p.or_is_handled = true
|
||||||
p.register_auto_import('sync')
|
p.register_auto_import('sync')
|
||||||
}
|
}
|
||||||
// mut typ := p.
|
|
||||||
// println('infix op=$op.str()')
|
|
||||||
precedence := p.tok.precedence()
|
precedence := p.tok.precedence()
|
||||||
mut pos := p.tok.position()
|
mut pos := p.tok.position()
|
||||||
if left.position().line_nr < pos.line_nr {
|
if left.position().line_nr < pos.line_nr {
|
||||||
pos = {
|
pos = token.Position{
|
||||||
pos |
|
...pos
|
||||||
line_nr: left.position().line_nr
|
line_nr: left.position().line_nr
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -212,12 +212,12 @@ fn (mut s Scanner) ident_bin_number() string {
|
||||||
mut first_wrong_digit := `\0`
|
mut first_wrong_digit := `\0`
|
||||||
start_pos := s.pos
|
start_pos := s.pos
|
||||||
s.pos += 2 // skip '0b'
|
s.pos += 2 // skip '0b'
|
||||||
if s.text[s.pos] == num_sep {
|
if s.pos < s.text.len && s.text[s.pos] == num_sep {
|
||||||
s.error('separator `_` is only valid between digits in a numeric literal')
|
s.error('separator `_` is only valid between digits in a numeric literal')
|
||||||
}
|
}
|
||||||
for s.pos < s.text.len {
|
for s.pos < s.text.len {
|
||||||
c := s.text[s.pos]
|
c := s.text[s.pos]
|
||||||
if c == num_sep && s.text[s.pos + 1] == num_sep {
|
if c == num_sep && s.text[s.pos - 1] == num_sep {
|
||||||
s.error('cannot use `_` consecutively')
|
s.error('cannot use `_` consecutively')
|
||||||
}
|
}
|
||||||
if !c.is_bin_digit() && c != num_sep {
|
if !c.is_bin_digit() && c != num_sep {
|
||||||
|
@ -232,6 +232,7 @@ fn (mut s Scanner) ident_bin_number() string {
|
||||||
s.pos++
|
s.pos++
|
||||||
}
|
}
|
||||||
if s.text[s.pos - 1] == num_sep {
|
if s.text[s.pos - 1] == num_sep {
|
||||||
|
s.pos--
|
||||||
s.error('cannot use `_` at the end of a numeric literal')
|
s.error('cannot use `_` at the end of a numeric literal')
|
||||||
} else if start_pos + 2 == s.pos {
|
} else if start_pos + 2 == s.pos {
|
||||||
s.pos-- // adjust error position
|
s.pos-- // adjust error position
|
||||||
|
@ -254,12 +255,12 @@ fn (mut s Scanner) ident_hex_number() string {
|
||||||
return '0x'
|
return '0x'
|
||||||
}
|
}
|
||||||
s.pos += 2 // skip '0x'
|
s.pos += 2 // skip '0x'
|
||||||
if s.text[s.pos] == num_sep {
|
if s.pos < s.text.len && s.text[s.pos] == num_sep {
|
||||||
s.error('separator `_` is only valid between digits in a numeric literal')
|
s.error('separator `_` is only valid between digits in a numeric literal')
|
||||||
}
|
}
|
||||||
for s.pos < s.text.len {
|
for s.pos < s.text.len {
|
||||||
c := s.text[s.pos]
|
c := s.text[s.pos]
|
||||||
if c == num_sep && s.text[s.pos + 1] == num_sep {
|
if c == num_sep && s.text[s.pos - 1] == num_sep {
|
||||||
s.error('cannot use `_` consecutively')
|
s.error('cannot use `_` consecutively')
|
||||||
}
|
}
|
||||||
if !c.is_hex_digit() && c != num_sep {
|
if !c.is_hex_digit() && c != num_sep {
|
||||||
|
@ -274,6 +275,7 @@ fn (mut s Scanner) ident_hex_number() string {
|
||||||
s.pos++
|
s.pos++
|
||||||
}
|
}
|
||||||
if s.text[s.pos - 1] == num_sep {
|
if s.text[s.pos - 1] == num_sep {
|
||||||
|
s.pos--
|
||||||
s.error('cannot use `_` at the end of a numeric literal')
|
s.error('cannot use `_` at the end of a numeric literal')
|
||||||
} else if start_pos + 2 == s.pos {
|
} else if start_pos + 2 == s.pos {
|
||||||
s.pos-- // adjust error position
|
s.pos-- // adjust error position
|
||||||
|
@ -293,12 +295,12 @@ fn (mut s Scanner) ident_oct_number() string {
|
||||||
mut first_wrong_digit := `\0`
|
mut first_wrong_digit := `\0`
|
||||||
start_pos := s.pos
|
start_pos := s.pos
|
||||||
s.pos += 2 // skip '0o'
|
s.pos += 2 // skip '0o'
|
||||||
if s.text[s.pos] == num_sep {
|
if s.pos < s.text.len && s.text[s.pos] == num_sep {
|
||||||
s.error('separator `_` is only valid between digits in a numeric literal')
|
s.error('separator `_` is only valid between digits in a numeric literal')
|
||||||
}
|
}
|
||||||
for s.pos < s.text.len {
|
for s.pos < s.text.len {
|
||||||
c := s.text[s.pos]
|
c := s.text[s.pos]
|
||||||
if c == num_sep && s.text[s.pos + 1] == num_sep {
|
if c == num_sep && s.text[s.pos - 1] == num_sep {
|
||||||
s.error('cannot use `_` consecutively')
|
s.error('cannot use `_` consecutively')
|
||||||
}
|
}
|
||||||
if !c.is_oct_digit() && c != num_sep {
|
if !c.is_oct_digit() && c != num_sep {
|
||||||
|
@ -313,6 +315,7 @@ fn (mut s Scanner) ident_oct_number() string {
|
||||||
s.pos++
|
s.pos++
|
||||||
}
|
}
|
||||||
if s.text[s.pos - 1] == num_sep {
|
if s.text[s.pos - 1] == num_sep {
|
||||||
|
s.pos--
|
||||||
s.error('cannot use `_` at the end of a numeric literal')
|
s.error('cannot use `_` at the end of a numeric literal')
|
||||||
} else if start_pos + 2 == s.pos {
|
} else if start_pos + 2 == s.pos {
|
||||||
s.pos-- // adjust error position
|
s.pos-- // adjust error position
|
||||||
|
@ -334,7 +337,7 @@ fn (mut s Scanner) ident_dec_number() string {
|
||||||
// scan integer part
|
// scan integer part
|
||||||
for s.pos < s.text.len {
|
for s.pos < s.text.len {
|
||||||
c := s.text[s.pos]
|
c := s.text[s.pos]
|
||||||
if c == num_sep && s.text[s.pos + 1] == num_sep {
|
if c == num_sep && s.text[s.pos - 1] == num_sep {
|
||||||
s.error('cannot use `_` consecutively')
|
s.error('cannot use `_` consecutively')
|
||||||
}
|
}
|
||||||
if !c.is_digit() && c != num_sep {
|
if !c.is_digit() && c != num_sep {
|
||||||
|
@ -349,6 +352,7 @@ fn (mut s Scanner) ident_dec_number() string {
|
||||||
s.pos++
|
s.pos++
|
||||||
}
|
}
|
||||||
if s.text[s.pos - 1] == num_sep {
|
if s.text[s.pos - 1] == num_sep {
|
||||||
|
s.pos--
|
||||||
s.error('cannot use `_` at the end of a numeric literal')
|
s.error('cannot use `_` at the end of a numeric literal')
|
||||||
}
|
}
|
||||||
mut call_method := false // true for, e.g., 5.str(), 5.5.str(), 5e5.str()
|
mut call_method := false // true for, e.g., 5.str(), 5.5.str(), 5e5.str()
|
||||||
|
@ -554,12 +558,12 @@ fn (mut s Scanner) text_scan() token.Token {
|
||||||
} else {
|
} else {
|
||||||
s.is_started = true
|
s.is_started = true
|
||||||
}
|
}
|
||||||
if s.pos >= s.text.len {
|
|
||||||
return s.end_of_file()
|
|
||||||
}
|
|
||||||
if !s.is_inside_string {
|
if !s.is_inside_string {
|
||||||
s.skip_whitespace()
|
s.skip_whitespace()
|
||||||
}
|
}
|
||||||
|
if s.pos >= s.text.len {
|
||||||
|
return s.end_of_file()
|
||||||
|
}
|
||||||
// End of $var, start next string
|
// End of $var, start next string
|
||||||
if s.is_inter_end {
|
if s.is_inter_end {
|
||||||
if s.text[s.pos] == s.quote {
|
if s.text[s.pos] == s.quote {
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
vlib/v/scanner/tests/bin_consecutively_separator_err.vv:2:9: error: separator `_` is only valid between digits in a numeric literal
|
||||||
|
1 | fn main() {
|
||||||
|
2 | _ := 0b_20
|
||||||
|
| ^
|
||||||
|
3 | }
|
|
@ -0,0 +1,3 @@
|
||||||
|
fn main() {
|
||||||
|
_ := 0b_20
|
||||||
|
}
|
|
@ -0,0 +1,5 @@
|
||||||
|
vlib/v/scanner/tests/bin_separator_in_front_err.vv:2:9: error: separator `_` is only valid between digits in a numeric literal
|
||||||
|
1 | fn main() {
|
||||||
|
2 | _ := 0b_20
|
||||||
|
| ^
|
||||||
|
3 | }
|
|
@ -0,0 +1,3 @@
|
||||||
|
fn main() {
|
||||||
|
_ := 0b_20
|
||||||
|
}
|
|
@ -0,0 +1,5 @@
|
||||||
|
vlib/v/scanner/tests/dec_consecutively_separator_err.vv:2:7: error: undefined ident: `_20`
|
||||||
|
1 | fn main() {
|
||||||
|
2 | _ := _20
|
||||||
|
| ~~~
|
||||||
|
3 | }
|
|
@ -0,0 +1,3 @@
|
||||||
|
fn main() {
|
||||||
|
_ := _20
|
||||||
|
}
|
|
@ -0,0 +1,5 @@
|
||||||
|
vlib/v/scanner/tests/hex_consecutively_separator_err.vv:2:9: error: separator `_` is only valid between digits in a numeric literal
|
||||||
|
1 | fn main() {
|
||||||
|
2 | _ := 0x_20
|
||||||
|
| ^
|
||||||
|
3 | }
|
|
@ -0,0 +1,3 @@
|
||||||
|
fn main() {
|
||||||
|
_ := 0x_20
|
||||||
|
}
|
|
@ -0,0 +1,5 @@
|
||||||
|
vlib/v/scanner/tests/hex_separator_in_front_err.vv:2:9: error: separator `_` is only valid between digits in a numeric literal
|
||||||
|
1 | fn main() {
|
||||||
|
2 | _ := 0o_20
|
||||||
|
| ^
|
||||||
|
3 | }
|
|
@ -0,0 +1,3 @@
|
||||||
|
fn main() {
|
||||||
|
_ := 0o_20
|
||||||
|
}
|
|
@ -0,0 +1,5 @@
|
||||||
|
vlib/v/scanner/tests/oct_consecutively_separator_err.vv:2:9: error: separator `_` is only valid between digits in a numeric literal
|
||||||
|
1 | fn main() {
|
||||||
|
2 | _ := 0o_20
|
||||||
|
| ^
|
||||||
|
3 | }
|
|
@ -0,0 +1,3 @@
|
||||||
|
fn main() {
|
||||||
|
_ := 0o_20
|
||||||
|
}
|
|
@ -0,0 +1,5 @@
|
||||||
|
vlib/v/scanner/tests/oct_separator_in_front_err.vv:2:9: error: separator `_` is only valid between digits in a numeric literal
|
||||||
|
1 | fn main() {
|
||||||
|
2 | _ := 0o_20
|
||||||
|
| ^
|
||||||
|
3 | }
|
|
@ -0,0 +1,3 @@
|
||||||
|
fn main() {
|
||||||
|
_ := 0o_20
|
||||||
|
}
|
|
@ -355,8 +355,8 @@ pub fn (mut t Table) register_type_symbol(typ TypeSymbol) int {
|
||||||
.placeholder {
|
.placeholder {
|
||||||
// override placeholder
|
// override placeholder
|
||||||
// println('overriding type placeholder `$typ.name`')
|
// println('overriding type placeholder `$typ.name`')
|
||||||
t.types[existing_idx] = {
|
t.types[existing_idx] = TypeSymbol{
|
||||||
typ |
|
...typ
|
||||||
methods: ex_type.methods
|
methods: ex_type.methods
|
||||||
}
|
}
|
||||||
return existing_idx
|
return existing_idx
|
||||||
|
@ -368,8 +368,8 @@ pub fn (mut t Table) register_type_symbol(typ TypeSymbol) int {
|
||||||
if existing_idx >= string_type_idx && existing_idx <= map_type_idx {
|
if existing_idx >= string_type_idx && existing_idx <= map_type_idx {
|
||||||
if existing_idx == string_type_idx {
|
if existing_idx == string_type_idx {
|
||||||
// existing_type := t.types[existing_idx]
|
// existing_type := t.types[existing_idx]
|
||||||
t.types[existing_idx] = {
|
t.types[existing_idx] = TypeSymbol{
|
||||||
typ |
|
...typ
|
||||||
kind: ex_type.kind
|
kind: ex_type.kind
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -84,7 +84,7 @@ fn test_assign_multi_expr() {
|
||||||
// test practical complex expressions
|
// test practical complex expressions
|
||||||
val3 := Object { name: 'initial', value: 19 }
|
val3 := Object { name: 'initial', value: 19 }
|
||||||
mut q, mut r, mut s := if true {
|
mut q, mut r, mut s := if true {
|
||||||
1 + 1, 'awe' + 'some', { val3 | name: 'ok' }
|
1 + 1, 'awe' + 'some', Object{ ...val3, name: 'ok' }
|
||||||
} else {
|
} else {
|
||||||
0, '0', Object {}
|
0, '0', Object {}
|
||||||
}
|
}
|
||||||
|
@ -97,7 +97,7 @@ fn test_assign_multi_expr() {
|
||||||
q, r, s = if false {
|
q, r, s = if false {
|
||||||
0, '0', Object {}
|
0, '0', Object {}
|
||||||
} else {
|
} else {
|
||||||
5, '55', { val3 | value: 555 }
|
5, '55', Object{ ...val3, value: 555 }
|
||||||
}
|
}
|
||||||
assert q == 5
|
assert q == 5
|
||||||
assert r == '55'
|
assert r == '55'
|
||||||
|
|
|
@ -8,8 +8,8 @@ fn new_st() MyStruct {
|
||||||
|
|
||||||
fn get_st() MyStruct {
|
fn get_st() MyStruct {
|
||||||
r := new_st()
|
r := new_st()
|
||||||
return {
|
return MyStruct{
|
||||||
r |
|
...r
|
||||||
s: '6'
|
s: '6'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -164,8 +164,8 @@ fn test_assoc_with_vars() {
|
||||||
def2 := Def{
|
def2 := Def{
|
||||||
a: 12
|
a: 12
|
||||||
}
|
}
|
||||||
merged := {
|
merged := Def{
|
||||||
def2 |
|
...def2
|
||||||
a: 42
|
a: 42
|
||||||
}
|
}
|
||||||
assert merged.a == 42
|
assert merged.a == 42
|
||||||
|
@ -181,7 +181,7 @@ const (
|
||||||
fn test_assoc_with_constants() {
|
fn test_assoc_with_constants() {
|
||||||
println(1)
|
println(1)
|
||||||
/*
|
/*
|
||||||
QTODO
|
TODO:
|
||||||
merged := { const_def | a: 42 }
|
merged := { const_def | a: 42 }
|
||||||
assert merged.a == 42
|
assert merged.a == 42
|
||||||
assert merged.b == 7
|
assert merged.b == 7
|
||||||
|
|
|
@ -17,8 +17,8 @@ pub fn (pos Position) str() string {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn (pos Position) extend(end Position) Position {
|
pub fn (pos Position) extend(end Position) Position {
|
||||||
return {
|
return Position{
|
||||||
pos |
|
...pos
|
||||||
len: end.pos - pos.pos + end.len
|
len: end.pos - pos.pos + end.len
|
||||||
last_line: end.last_line
|
last_line: end.last_line
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue