From ec3ef23d5ec3529406d8102f0e2792e957c4ba67 Mon Sep 17 00:00:00 2001 From: Tristan Gingold Date: Thu, 11 Jan 2018 06:41:07 +0100 Subject: parser: improve recovery on missing 'entity' in entity aspects. --- src/vhdl/parse.adb | 46 ++++++++++++++++++++++++++++++++-------------- 1 file changed, 32 insertions(+), 14 deletions(-) (limited to 'src/vhdl') diff --git a/src/vhdl/parse.adb b/src/vhdl/parse.adb index 93e8cfd07..fc00c431b 100644 --- a/src/vhdl/parse.adb +++ b/src/vhdl/parse.adb @@ -8511,6 +8511,34 @@ package body Parse is Set_Component_Name (Res, Parse_Name); end Parse_Component_Specification; + -- precond : next token + -- postcond: next token + function Parse_Entity_Aspect_Entity return Iir + is + Res : Iir; + begin + Res := Create_Iir (Iir_Kind_Entity_Aspect_Entity); + Set_Location (Res); + + if Current_Token = Tok_Entity then + -- Eat 'entity' (but only if present). + Scan; + end if; + + Expect (Tok_Identifier); + Set_Entity_Name (Res, Parse_Name (False)); + + -- Optional architecture + if Current_Token = Tok_Left_Paren then + Scan_Expect (Tok_Identifier); + Set_Architecture (Res, Current_Text); + Scan_Expect (Tok_Right_Paren); + Scan; + end if; + + return Res; + end Parse_Entity_Aspect_Entity; + -- precond : next token -- postcond: next token -- @@ -8524,16 +8552,7 @@ package body Parse is begin case Current_Token is when Tok_Entity => - Res := Create_Iir (Iir_Kind_Entity_Aspect_Entity); - Set_Location (Res); - Scan_Expect (Tok_Identifier); - Set_Entity_Name (Res, Parse_Name (False)); - if Current_Token = Tok_Left_Paren then - Scan_Expect (Tok_Identifier); - Set_Architecture (Res, Current_Text); - Scan_Expect (Tok_Right_Paren); - Scan; - end if; + Res := Parse_Entity_Aspect_Entity; when Tok_Configuration => Res := Create_Iir (Iir_Kind_Entity_Aspect_Configuration); Set_Location (Res); @@ -8544,10 +8563,9 @@ package body Parse is Set_Location (Res); Scan; when others => - -- FIXME: if the token is an identifier, try as if the 'entity' - -- keyword is missing. - Error_Msg_Parse - ("'entity', 'configuration' or 'open' keyword expected"); + Error_Msg_Parse ("'entity', 'configuration' or 'open' expected"); + -- Assume 'entity' is missing (common case). + Res := Parse_Entity_Aspect_Entity; end case; return Res; end Parse_Entity_Aspect; -- cgit v1.2.3