44//
55// Copyright (c) 2018, Olof Kraigher olof.kraigher@gmail.com
66
7- use super :: common:: check_end_identifier_mismatch;
8- use super :: common:: ParseResult ;
7+ use super :: common:: { check_end_identifier_mismatch, ParseResult } ;
98use super :: interface_declaration:: { parse_generic_interface_list, parse_port_interface_list} ;
10- use super :: tokens:: { Kind :: * , TokenSpan , TokenStream } ;
9+ use super :: tokens:: { Kind :: * , TokenSpan } ;
1110use crate :: ast:: WithDecl ;
1211use crate :: ast:: { ComponentDeclaration , InterfaceDeclaration } ;
13- use crate :: data:: { Diagnostic , DiagnosticHandler } ;
12+ use crate :: data:: Diagnostic ;
13+ use vhdl_lang:: syntax:: parser:: ParsingContext ;
1414
1515pub fn parse_optional_generic_list (
16- stream : & TokenStream ,
17- diagnostics : & mut dyn DiagnosticHandler ,
16+ ctx : & mut ParsingContext < ' _ > ,
1817) -> ParseResult < Option < Vec < InterfaceDeclaration > > > {
1918 let mut list = None ;
2019 loop {
21- let token = stream. peek_expect ( ) ?;
20+ let token = ctx . stream . peek_expect ( ) ?;
2221 match token. kind {
2322 Generic => {
24- stream. skip ( ) ;
25- let new_list = parse_generic_interface_list ( stream , diagnostics ) ?;
26- stream. expect_kind ( SemiColon ) ?;
23+ ctx . stream . skip ( ) ;
24+ let new_list = parse_generic_interface_list ( ctx ) ?;
25+ ctx . stream . expect_kind ( SemiColon ) ?;
2726 if list. is_some ( ) {
28- diagnostics. push ( Diagnostic :: syntax_error ( token, "Duplicate generic clause" ) ) ;
27+ ctx. diagnostics
28+ . push ( Diagnostic :: syntax_error ( token, "Duplicate generic clause" ) ) ;
2929 } else {
3030 list = Some ( new_list) ;
3131 }
@@ -38,28 +38,28 @@ pub fn parse_optional_generic_list(
3838}
3939
4040pub fn parse_optional_port_list (
41- stream : & TokenStream ,
42- diagnostics : & mut dyn DiagnosticHandler ,
41+ ctx : & mut ParsingContext < ' _ > ,
4342) -> ParseResult < Option < Vec < InterfaceDeclaration > > > {
4443 let mut list = None ;
4544 loop {
46- let token = stream. peek_expect ( ) ?;
45+ let token = ctx . stream . peek_expect ( ) ?;
4746 match token. kind {
4847 Port => {
49- stream. skip ( ) ;
50- let new_list = parse_port_interface_list ( stream , diagnostics ) ?;
51- stream. expect_kind ( SemiColon ) ?;
48+ ctx . stream . skip ( ) ;
49+ let new_list = parse_port_interface_list ( ctx ) ?;
50+ ctx . stream . expect_kind ( SemiColon ) ?;
5251 if list. is_some ( ) {
53- diagnostics. push ( Diagnostic :: syntax_error ( token, "Duplicate port clause" ) ) ;
52+ ctx. diagnostics
53+ . push ( Diagnostic :: syntax_error ( token, "Duplicate port clause" ) ) ;
5454 } else {
5555 list = Some ( new_list) ;
5656 }
5757 }
5858 Generic => {
59- stream. skip ( ) ;
60- parse_generic_interface_list ( stream , diagnostics ) ?;
61- stream. expect_kind ( SemiColon ) ?;
62- diagnostics. push ( Diagnostic :: syntax_error (
59+ ctx . stream . skip ( ) ;
60+ parse_generic_interface_list ( ctx ) ?;
61+ ctx . stream . expect_kind ( SemiColon ) ?;
62+ ctx . diagnostics . push ( Diagnostic :: syntax_error (
6363 token,
6464 "Generic clause must come before port clause" ,
6565 ) ) ;
@@ -72,23 +72,22 @@ pub fn parse_optional_port_list(
7272}
7373
7474pub fn parse_component_declaration (
75- stream : & TokenStream ,
76- diagnostics : & mut dyn DiagnosticHandler ,
75+ ctx : & mut ParsingContext < ' _ > ,
7776) -> ParseResult < ComponentDeclaration > {
78- let start_token = stream. expect_kind ( Component ) ?;
79- let ident = WithDecl :: new ( stream. expect_ident ( ) ?) ;
80- stream. pop_if_kind ( Is ) ;
77+ let start_token = ctx . stream . expect_kind ( Component ) ?;
78+ let ident = WithDecl :: new ( ctx . stream . expect_ident ( ) ?) ;
79+ ctx . stream . pop_if_kind ( Is ) ;
8180
82- let generic_list = parse_optional_generic_list ( stream , diagnostics ) ?;
83- let port_list = parse_optional_port_list ( stream , diagnostics ) ?;
84- stream. expect_kind ( End ) ?;
85- stream. expect_kind ( Component ) ?;
86- let end_ident = stream. pop_optional_ident ( ) ;
87- let end_token = stream. expect_kind ( SemiColon ) ?;
81+ let generic_list = parse_optional_generic_list ( ctx ) ?;
82+ let port_list = parse_optional_port_list ( ctx ) ?;
83+ ctx . stream . expect_kind ( End ) ?;
84+ ctx . stream . expect_kind ( Component ) ?;
85+ let end_ident = ctx . stream . pop_optional_ident ( ) ;
86+ let end_token = ctx . stream . expect_kind ( SemiColon ) ?;
8887
8988 Ok ( ComponentDeclaration {
9089 span : TokenSpan :: new ( start_token, end_token) ,
91- end_ident_pos : check_end_identifier_mismatch ( & ident. tree , end_ident, diagnostics ) ,
90+ end_ident_pos : check_end_identifier_mismatch ( ctx , & ident. tree , end_ident) ,
9291 ident,
9392 generic_list : generic_list. unwrap_or_default ( ) ,
9493 port_list : port_list. unwrap_or_default ( ) ,
0 commit comments