parser: snake_case check; array: mutable array test
parent
4c6db7a64e
commit
46aed151ab
|
@ -313,6 +313,27 @@ fn test_mut_slice() {
|
||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn double_up(a mut []int) {
|
||||||
|
for i := 0; i < a.len; i++ {
|
||||||
|
a[i] = a[i]*2
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn double_up_v2(a mut []int) {
|
||||||
|
for i, val in a {
|
||||||
|
a[i] = a[i]*2 // or val*2, doesn't matter
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn test_mut_arg() {
|
||||||
|
mut arr := [1,2,3,4,5,6,7,8,9,10]
|
||||||
|
double_up(mut arr)
|
||||||
|
assert arr.str() == '[2, 4, 6, 8, 10, 12, 14, 16, 18, 20]'
|
||||||
|
arr = [1,2,3,4,5,6,7,8,9,10]
|
||||||
|
double_up_v2(mut arr)
|
||||||
|
assert arr.str() == '[2, 4, 6, 8, 10, 12, 14, 16, 18, 20]'
|
||||||
|
}
|
||||||
|
|
||||||
fn test_clone() {
|
fn test_clone() {
|
||||||
nums := [1, 2, 3, 4, 100]
|
nums := [1, 2, 3, 4, 100]
|
||||||
nums2 := nums.clone()
|
nums2 := nums.clone()
|
||||||
|
|
|
@ -6,6 +6,7 @@ module parser
|
||||||
import (
|
import (
|
||||||
v.ast
|
v.ast
|
||||||
v.table
|
v.table
|
||||||
|
v.scanner
|
||||||
)
|
)
|
||||||
|
|
||||||
pub fn (p mut Parser) call_expr(is_c bool, mod string) ast.CallExpr {
|
pub fn (p mut Parser) call_expr(is_c bool, mod string) ast.CallExpr {
|
||||||
|
@ -103,6 +104,9 @@ fn (p mut Parser) fn_decl() ast.FnDecl {
|
||||||
if p.tok.kind == .name {
|
if p.tok.kind == .name {
|
||||||
// TODO high order fn
|
// TODO high order fn
|
||||||
name = p.check_name()
|
name = p.check_name()
|
||||||
|
if !is_c && !p.pref.translated && scanner.contains_capital(name) {
|
||||||
|
p.error('function names cannot contain uppercase letters, use snake_case instead')
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if p.tok.kind in [.plus, .minus, .mul, .div, .mod] {
|
if p.tok.kind in [.plus, .minus, .mul, .div, .mod] {
|
||||||
name = p.tok.kind.str() // op_to_fn_name()
|
name = p.tok.kind.str() // op_to_fn_name()
|
||||||
|
|
|
@ -59,7 +59,7 @@ pub fn formated_error(kind string /*error or warn*/, emsg string, filepath strin
|
||||||
mut source_context := ''
|
mut source_context := ''
|
||||||
//
|
//
|
||||||
final_position := if emanager.support_color {
|
final_position := if emanager.support_color {
|
||||||
term.bold(term.white(position))
|
term.bold(position) // term.white(position))
|
||||||
} else {
|
} else {
|
||||||
position
|
position
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue