From 0a4a9a35c3665b364180a9e4791c8b8d7896264b Mon Sep 17 00:00:00 2001 From: Alexander Medvednikov Date: Tue, 16 Jul 2019 12:17:17 +0200 Subject: [PATCH] .key_type --- compiler/parser.v | 12 ++++++++---- compiler/token.v | 6 +++--- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/compiler/parser.v b/compiler/parser.v index ca1be91ada..c74e878648 100644 --- a/compiler/parser.v +++ b/compiler/parser.v @@ -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():') diff --git a/compiler/token.v b/compiler/token.v index e3e1071a15..309540f806 100644 --- a/compiler/token.v +++ b/compiler/token.v @@ -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 }