leo_grammar/common/
self_keyword_or_identifier.rs

1// Copyright (C) 2019-2020 Aleo Systems Inc.
2// This file is part of the Leo library.
3
4// The Leo library is free software: you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published by
6// the Free Software Foundation, either version 3 of the License, or
7// (at your option) any later version.
8
9// The Leo library is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12// GNU General Public License for more details.
13
14// You should have received a copy of the GNU General Public License
15// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
16
17use crate::{
18    ast::Rule,
19    common::{Identifier, SelfKeyword},
20};
21
22use pest_ast::FromPest;
23use serde::Serialize;
24use std::fmt;
25
26#[derive(Clone, Debug, FromPest, PartialEq, Serialize)]
27#[pest_ast(rule(Rule::self_keyword_or_identifier))]
28pub enum SelfKeywordOrIdentifier<'ast> {
29    SelfKeyword(SelfKeyword<'ast>),
30    Identifier(Identifier<'ast>),
31}
32
33impl<'ast> fmt::Display for SelfKeywordOrIdentifier<'ast> {
34    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
35        match self {
36            SelfKeywordOrIdentifier::SelfKeyword(self_keyword) => write!(f, "{}", self_keyword),
37            SelfKeywordOrIdentifier::Identifier(identifier) => write!(f, "{}", identifier),
38        }
39    }
40}