Fix package odin_parser bugs

This commit is contained in:
gingerBill
2019-02-09 22:34:27 +00:00
parent 4b7a09b92e
commit e16409f88a
2 changed files with 13 additions and 5 deletions
+12 -4
View File
@@ -545,7 +545,7 @@ parse_if_stmt :: proc(p: ^Parser) -> ^ast.If_Stmt {
if allow_token(p, token.Else) { if allow_token(p, token.Else) {
switch p.curr_tok.kind { switch p.curr_tok.kind {
case token.If: case token.If:
else_stmt = parse_when_stmt(p); else_stmt = parse_if_stmt(p);
case token.Open_Brace: case token.Open_Brace:
else_stmt = parse_block_stmt(p, false); else_stmt = parse_block_stmt(p, false);
case token.Do: case token.Do:
@@ -771,7 +771,7 @@ parse_switch_stmt :: proc(p: ^Parser) -> ^ast.Stmt {
} }
} }
parse_attribute :: proc(p: ^Parser, tok: token.Token, open_kind, close_kind: token.Kind) -> ^ast.Stmt { parse_attribute :: proc(p: ^Parser, tok: token.Token, open_kind, close_kind: token.Kind, docs: ^ast.Comment_Group) -> ^ast.Stmt {
elems: [dynamic]^ast.Expr; elems: [dynamic]^ast.Expr;
open, close: token.Token; open, close: token.Token;
@@ -815,8 +815,10 @@ parse_attribute :: proc(p: ^Parser, tok: token.Token, open_kind, close_kind: tok
decl := parse_stmt(p); decl := parse_stmt(p);
switch d in &decl.derived { switch d in &decl.derived {
case ast.Value_Decl: case ast.Value_Decl:
if d.docs == nil do d.docs = docs;
append(&d.attributes, attribute); append(&d.attributes, attribute);
case ast.Foreign_Block_Decl: case ast.Foreign_Block_Decl:
if d.docs == nil do d.docs = docs;
append(&d.attributes, attribute); append(&d.attributes, attribute);
case: case:
error(p, decl.pos, "expected a value or foreign declaration after an attribute"); error(p, decl.pos, "expected a value or foreign declaration after an attribute");
@@ -1089,8 +1091,9 @@ parse_stmt :: proc(p: ^Parser) -> ^ast.Stmt {
return ast.new(ast.Bad_Stmt, tok.pos, end_pos(p.prev_tok)); return ast.new(ast.Bad_Stmt, tok.pos, end_pos(p.prev_tok));
case token.At: case token.At:
docs := p.lead_comment;
tok := advance_token(p); tok := advance_token(p);
return parse_attribute(p, tok, token.Open_Paren, token.Close_Paren); return parse_attribute(p, tok, token.Open_Paren, token.Close_Paren, docs);
case token.Hash: case token.Hash:
tok := expect_token(p, token.Hash); tok := expect_token(p, token.Hash);
@@ -1729,6 +1732,10 @@ parse_results :: proc(p: ^Parser) -> (list: ^ast.Field_List, diverging: bool) {
string_to_calling_convention :: proc(s: string) -> ast.Proc_Calling_Convention { string_to_calling_convention :: proc(s: string) -> ast.Proc_Calling_Convention {
using ast.Proc_Calling_Convention; using ast.Proc_Calling_Convention;
if s[0] != '"' && s[0] != '`' {
return Invalid;
}
s = s[1:len(s)-1];
switch s { switch s {
case "odin": case "odin":
return Odin; return Odin;
@@ -1908,7 +1915,7 @@ parse_operand :: proc(p: ^Parser, lhs: bool) -> ^ast.Expr {
case token.Inline, token.No_Inline: case token.Inline, token.No_Inline:
tok := advance_token(p); tok := advance_token(p);
expr := parse_unary_expr(p, false); expr := parse_unary_expr(p, lhs);
pi := ast.Proc_Inlining.None; pi := ast.Proc_Inlining.None;
switch tok.kind { switch tok.kind {
@@ -1933,6 +1940,7 @@ parse_operand :: proc(p: ^Parser, lhs: bool) -> ^ast.Expr {
error(p, tok.pos, "'%s' must be followed by a procedure literal or call", tok.text); error(p, tok.pos, "'%s' must be followed by a procedure literal or call", tok.text);
return ast.new(ast.Bad_Expr, tok.pos, expr.end); return ast.new(ast.Bad_Expr, tok.pos, expr.end);
} }
return expr;
case token.Proc: case token.Proc:
tok := expect_token(p, token.Proc); tok := expect_token(p, token.Proc);
+1 -1
View File
@@ -557,7 +557,7 @@ scan :: proc(t: ^Tokenizer) -> token.Token {
} else { } else {
kind = switch3(t, token.And, token.And_Eq, '&', token.Cmp_And); kind = switch3(t, token.And, token.And_Eq, '&', token.Cmp_And);
} }
case '|': kind = switch3(t, token.Or, token.Or_Eq, '&', token.Cmp_Or); case '|': kind = switch3(t, token.Or, token.Or_Eq, '|', token.Cmp_Or);
case '~': kind = token.Xor; case '~': kind = token.Xor;
case '<': case '<':
if t.ch == '-' { if t.ch == '-' {