.key_type

pull/1177/head
Alexander Medvednikov 2019-07-16 12:17:17 +02:00
parent 961ffb1868
commit 0a4a9a35c3
2 changed files with 11 additions and 7 deletions

View File

@ -189,7 +189,7 @@ fn (p mut Parser) parse() {
}
case Token.func:
p.fn_decl()
case Token.typ:
case Token.key_type:
p.type_decl()
case Token.lsbr:
// `[` can only mean an [attribute] before a function
@ -401,7 +401,7 @@ fn (p mut Parser) const_decl() {
// `type myint int`
// `type onclickfn fn(voidptr) int`
fn (p mut Parser) type_decl() {
p.check(.typ)
p.check(.key_type)
name := p.check_name()
parent := p.get_type()
nt_pair := p.table.cgen_name_type_pair(name, parent)
@ -642,7 +642,12 @@ fn (p mut Parser) enum_decl(_enum_name string) {
// check_name checks for a name token and returns its literal
fn (p mut Parser) check_name() string {
if p.tok == .key_type {
p.check(.key_type)
return 'type'
}
name := p.lit
p.check(.name)
return name
}
@ -1569,9 +1574,8 @@ fn (p mut Parser) dot(str_typ string, method_ph int) string {
has_field := p.table.type_has_field(typ, field_name)
has_method := p.table.type_has_method(typ, field_name)
if !typ.is_c && !has_field && !has_method && !p.first_run() {
// println(typ.str())
if typ.name.starts_with('Option_') {
opt_type := typ.name.substr(7, typ.name.len)
opt_type := typ.name.right(7)
p.error('unhandled option type: $opt_type?')
}
println('error in dot():')

View File

@ -98,7 +98,7 @@ enum Token {
key_struct
key_switch
key_true
typ
key_type
//typeof
key_orelse
key_union
@ -189,7 +189,7 @@ fn build_token_str() []string {
s[Token.key_goto] = 'goto'
s[Token.key_const] = 'const'
s[Token.key_mut] = 'mut'
s[Token.typ] = 'type'
s[Token.key_type] = 'type'
s[Token.key_for] = 'for'
s[Token.key_switch] = 'switch'
//Tokens[MATCH] = 'match'
@ -242,7 +242,7 @@ fn (t Token) is_decl() bool {
//return t in [.key_enum, .key_interface, .func, .typ, .key_const,
//.key_import_const, .key_struct, .key_pub, .eof]
return t == .key_enum || t == .key_interface || t == .func ||
t == .key_struct || t == .typ ||
t == .key_struct || t == .key_type ||
t == .key_const || t == .key_import_const || t == .key_pub || t == .eof
}