parser: use Parser.builtin_mod instead of checking p.mod (#8137)

pull/8159/head
Nick Treleaven 2021-01-17 04:31:41 +00:00 committed by GitHub
parent 8ee67d1c1c
commit 5185a59ac7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 4 additions and 6 deletions

View File

@ -254,7 +254,7 @@ fn (mut p Parser) fn_decl() ast.FnDecl {
pos := p.tok.position()
// TODO high order fn
name = if language == .js { p.check_js_name() } else { p.check_name() }
if language == .v && !p.pref.translated && util.contains_capital(name) && p.mod != 'builtin' {
if language == .v && !p.pref.translated && util.contains_capital(name) && !p.builtin_mod {
p.error_with_pos('function names cannot contain uppercase letters, use snake_case instead',
pos)
return ast.FnDecl{
@ -270,7 +270,7 @@ fn (mut p Parser) fn_decl() ast.FnDecl {
}
}
// cannot redefine buildin function
if !is_method && p.mod != 'builtin' && name in builtin_functions {
if !is_method && !p.builtin_mod && name in builtin_functions {
p.error_with_pos('cannot redefine builtin function `$name`', pos)
return ast.FnDecl{
scope: 0

View File

@ -250,7 +250,7 @@ pub fn (mut p Parser) parse_any_type(language table.Language, is_ptr bool, check
name = p.expr_mod + '.' + name
} else if name in p.imported_symbols {
name = p.imported_symbols[name]
} else if p.mod != 'builtin' && name.len > 1 && name !in p.table.type_idxs {
} else if !p.builtin_mod && name.len > 1 && name !in p.table.type_idxs {
// `Foo` in module `mod` means `mod.Foo`
name = p.mod + '.' + name
}

View File

@ -65,9 +65,7 @@ fn (mut p Parser) struct_decl() ast.StructDecl {
p.error('`$p.tok.lit` lacks body')
return ast.StructDecl{}
}
if language == .v &&
p.mod != 'builtin' && name.len > 0 && !name[0].is_capital() && !p.pref.translated
{
if language == .v && !p.builtin_mod && name.len > 0 && !name[0].is_capital() && !p.pref.translated {
p.error_with_pos('struct name `$name` must begin with capital letter', name_pos)
return ast.StructDecl{}
}