parser: remove __type (#6946)

pull/6947/head
Daniel Däschle 2020-11-25 14:27:15 +01:00 committed by GitHub
parent 35a0fe79f9
commit 8446433bcf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 0 additions and 60 deletions

View File

@ -435,9 +435,6 @@ pub fn (mut p Parser) top_stmt() ast.Stmt {
.key_type {
return p.type_decl()
}
.key___type {
return p.union_sum_type_decl()
}
else {
p.error('wrong pub keyword usage')
return ast.Stmt{}
@ -480,9 +477,6 @@ pub fn (mut p Parser) top_stmt() ast.Stmt {
.key_type {
return p.type_decl()
}
.key___type {
return p.union_sum_type_decl()
}
.key_enum {
return p.enum_decl()
}
@ -1902,58 +1896,6 @@ $pubfn (mut e $enum_name) toggle(flag $enum_name) { unsafe{ *e = int(*e) ^ (
}
}
fn (mut p Parser) union_sum_type_decl() ast.TypeDecl {
start_pos := p.tok.position()
is_pub := p.tok.kind == .key_pub
if is_pub {
p.next()
}
p.check(.key___type)
end_pos := p.tok.position()
decl_pos := start_pos.extend(end_pos)
name := p.check_name()
if name.len == 1 && name[0].is_capital() {
p.error_with_pos('single letter capital names are reserved for generic template types.',
decl_pos)
}
p.check(.assign)
mut sum_variants := []table.Type{}
first_type := p.parse_type() // need to parse the first type before we can check if it's `type A = X | Y`
if p.tok.kind == .pipe {
p.next()
sum_variants << first_type
// type SumType = A | B | c
for {
variant_type := p.parse_type()
sum_variants << variant_type
if p.tok.kind != .pipe {
break
}
p.check(.pipe)
}
prepend_mod_name := p.prepend_mod(name)
p.table.register_type_symbol(table.TypeSymbol{
kind: .sum_type
name: prepend_mod_name
source_name: prepend_mod_name
mod: p.mod
info: table.SumType{
variants: sum_variants
}
is_public: is_pub
})
return ast.SumTypeDecl{
name: name
is_pub: is_pub
sub_types: sum_variants
pos: decl_pos
}
}
// just for this implementation
p.error_with_pos('wrong union sum type declaration', decl_pos)
return ast.TypeDecl{}
}
fn (mut p Parser) type_decl() ast.TypeDecl {
start_pos := p.tok.position()
is_pub := p.tok.kind == .key_pub

View File

@ -121,7 +121,6 @@ pub enum Kind {
key_struct
key_true
key_type
key___type // type
key_typeof
key_orelse
key_union
@ -265,7 +264,6 @@ fn build_token_str() []string {
s[Kind.key_lock] = 'lock'
s[Kind.key_rlock] = 'rlock'
s[Kind.key_type] = 'type'
s[Kind.key___type] = '__type'
s[Kind.key_for] = 'for'
s[Kind.key_fn] = 'fn'
s[Kind.key_true] = 'true'