use crate::tokenizer::TokenReference;
use derive_more::Display;
use full_moon_derive::{Node, Visit};
#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};
#[derive(Clone, Debug, Display, PartialEq, Eq, Node, Visit)]
#[cfg_attr(feature = "serde", derive(Deserialize, Serialize))]
#[display(fmt = "{}{}", "goto_token", "label_name")]
pub struct Goto {
pub(crate) goto_token: TokenReference,
pub(crate) label_name: TokenReference,
}
impl Goto {
pub fn new(label_name: TokenReference) -> Self {
Self {
goto_token: TokenReference::symbol("goto").unwrap(),
label_name,
}
}
pub fn goto_token(&self) -> &TokenReference {
&self.goto_token
}
pub fn label_name(&self) -> &TokenReference {
&self.label_name
}
pub fn with_goto_token(self, goto_token: TokenReference) -> Self {
Self { goto_token, ..self }
}
pub fn with_label_name(self, label_name: TokenReference) -> Self {
Self { label_name, ..self }
}
}
#[derive(Clone, Debug, Display, PartialEq, Eq, Node, Visit)]
#[cfg_attr(feature = "serde", derive(Deserialize, Serialize))]
#[display(fmt = "{}{}{}", "left_colons", "name", "right_colons")]
pub struct Label {
pub(crate) left_colons: TokenReference,
pub(crate) name: TokenReference,
pub(crate) right_colons: TokenReference,
}
impl Label {
pub fn new(name: TokenReference) -> Self {
Self {
left_colons: TokenReference::symbol("::").unwrap(),
name,
right_colons: TokenReference::symbol("::").unwrap(),
}
}
pub fn left_colons(&self) -> &TokenReference {
&self.left_colons
}
pub fn name(&self) -> &TokenReference {
&self.name
}
pub fn right_colons(&self) -> &TokenReference {
&self.right_colons
}
pub fn with_left_colons(self, left_colons: TokenReference) -> Self {
Self {
left_colons,
..self
}
}
pub fn with_name(self, name: TokenReference) -> Self {
Self { name, ..self }
}
pub fn with_right_colons(self, right_colons: TokenReference) -> Self {
Self {
right_colons,
..self
}
}
}