vhdl_syntax 0.2.0

VHDL parser for lossless concrete syntax trees
Documentation
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this file,
// You can obtain one at http://mozilla.org/MPL/2.0/.
//
// Copyright (c)  2025, Lukas Scheller lukasscheller@icloud.com

use crate::parser::Parser;
use crate::syntax::node_kind::NodeKind::{GenericMapAspect, PortMapAspect};
use crate::tokens::Keyword as Kw;
use crate::tokens::TokenKind::*;

impl Parser {
    fn map_aspect(&mut self, kind: Kw) {
        let aspect = match kind {
            Kw::Generic => GenericMapAspect,
            Kw::Port => PortMapAspect,
            _ => unreachable!(),
        };
        self.node(aspect, |p| {
            p.expect_tokens([Keyword(kind), Keyword(Kw::Map), LeftPar]);
            p.association_list();
            p.expect_token(RightPar);
        });
    }

    fn opt_map_aspect(&mut self, kind: Kw) -> bool {
        if self.next_is(Keyword(kind)) && self.next_nth_is(Keyword(Kw::Map), 1) {
            self.map_aspect(kind);
            true
        } else {
            false
        }
    }

    pub(crate) fn port_map_aspect(&mut self) {
        self.map_aspect(Kw::Port)
    }

    pub(crate) fn opt_port_map_aspect(&mut self) -> bool {
        self.opt_map_aspect(Kw::Port)
    }

    pub(crate) fn generic_map_aspect(&mut self) {
        self.map_aspect(Kw::Generic)
    }

    pub(crate) fn opt_generic_map_aspect(&mut self) -> bool {
        self.opt_map_aspect(Kw::Generic)
    }
}