diff options
author | Tristan Gingold <tgingold@free.fr> | 2018-12-05 18:40:42 +0100 |
---|---|---|
committer | Tristan Gingold <tgingold@free.fr> | 2018-12-05 18:40:42 +0100 |
commit | dbd6431ddbcf8c7c1b882aaf0315860353421a49 (patch) | |
tree | e8998be978a8b475807eb5339c4b6228cdab251d | |
parent | 837eab3fa61abef9ce12aa66a2b12009970f18dc (diff) | |
download | ghdl-dbd6431ddbcf8c7c1b882aaf0315860353421a49.tar.gz ghdl-dbd6431ddbcf8c7c1b882aaf0315860353421a49.tar.bz2 ghdl-dbd6431ddbcf8c7c1b882aaf0315860353421a49.zip |
parse: strenghten
-rw-r--r-- | src/vhdl/parse.adb | 55 |
1 files changed, 43 insertions, 12 deletions
diff --git a/src/vhdl/parse.adb b/src/vhdl/parse.adb index 58c3833af..9c2d99793 100644 --- a/src/vhdl/parse.adb +++ b/src/vhdl/parse.adb @@ -128,6 +128,7 @@ package body Parse is procedure Expect_Scan (Token: Token_Type; Msg: String := "") is begin if Current_Token = Token then + -- Skip token. Scan; else Expect_Error (Token, Msg); @@ -209,6 +210,32 @@ package body Parse is end loop; end Resync_To_End_Of_Statement; + procedure Resync_To_End_Of_Declaration is + begin + loop + case Current_Token is + when Tok_Eof + | Tok_Semi_Colon => + exit; + when Tok_End + | Tok_Begin => + -- End of current block. + exit; + when Tok_Signal + | Tok_Variable + | Tok_Constant + | Tok_File + | Tok_Alias + | Tok_Type + | Tok_Subtype => + -- Start of a new declaration + exit; + when others => + Scan; + end case; + end loop; + end Resync_To_End_Of_Declaration; + -- Expect and scan ';' emit an error message using MSG if not present. procedure Scan_Semi_Colon (Msg : String) is begin @@ -1980,10 +2007,7 @@ package body Parse is -- Skip identifier or character. Scan; - exit when Current_Token = Tok_Right_Paren; - if Current_Token /= Tok_Comma then - Error_Msg_Parse ("')' or ',' is expected after an enum literal"); - end if; + exit when Current_Token /= Tok_Comma; -- Skip ','. Scan; @@ -1995,7 +2019,7 @@ package body Parse is end loop; -- Skip ')'. - Scan; + Expect_Scan (Tok_Right_Paren, "')' expected at end of enumeration type"); Set_Enumeration_Literal_List (Enum_Type, List_To_Flist (Enum_List)); @@ -3387,9 +3411,19 @@ package body Parse is end if; -- Eat class or ','. - Scan_Expect (Tok_Identifier); - Set_Identifier (Object, Current_Identifier); + Scan; + Set_Location (Object); + + if Current_Token = Tok_Identifier then + Set_Identifier (Object, Current_Identifier); + + -- Eat identifier. + Scan; + else + Expect (Tok_Identifier); + end if; + Set_Parent (Object, Parent); if Flag_Elocations then @@ -3399,9 +3433,6 @@ package body Parse is Sub_Chain_Append (First, Last, Object); - -- Eat identifier. - Scan; - exit when Current_Token = Tok_Colon; if Current_Token /= Tok_Comma then case Current_Token is @@ -3412,8 +3443,8 @@ package body Parse is Error_Msg_Parse ("',' or ':' is expected after identifier in " & Disp_Name (Kind)); - Eat_Tokens_Until_Semi_Colon; - return Null_Iir; + Resync_To_End_Of_Declaration; + return Object; end case; end if; Set_Has_Identifier_List (Object, True); |