2023-04-10 12:16:21 -04:00
|
|
|
// Documentation represented on the ASG
|
|
|
|
//
|
|
|
|
// Copyright (C) 2014-2023 Ryan Specialty, LLC.
|
|
|
|
//
|
|
|
|
// This file is part of TAME.
|
|
|
|
//
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
//! Documentation on the ASG.
|
|
|
|
//!
|
|
|
|
//! TODO: Document TAME's stance on documentation and literate programming,
|
|
|
|
//! much of which hasn't been able to be realized over the years.
|
|
|
|
|
|
|
|
use super::prelude::*;
|
|
|
|
use crate::{
|
|
|
|
parse::{util::SPair, Token},
|
|
|
|
span::Span,
|
|
|
|
};
|
|
|
|
use std::fmt::Display;
|
|
|
|
|
|
|
|
/// Documentation string.
|
|
|
|
///
|
|
|
|
/// TODO: This presently serves as a subject line,
|
|
|
|
/// e.g. a description or label,
|
|
|
|
/// but will evolve in the future.
|
|
|
|
#[derive(Debug, PartialEq, Eq)]
|
|
|
|
pub enum Doc {
|
|
|
|
/// An (ideally) concise independent clause describing an object.
|
|
|
|
IndepClause(SPair),
|
2023-04-12 10:03:37 -04:00
|
|
|
|
|
|
|
/// Arbitrary text serving as documentation for sibling objects in a
|
|
|
|
/// literate style.
|
|
|
|
///
|
|
|
|
/// TAMER does not presently ascribe any semantic meaning to this text,
|
|
|
|
/// and it may even be entirely whitespace.
|
|
|
|
/// There are plans to improve upon this in the future.
|
|
|
|
///
|
|
|
|
/// The intent is for this text to be mixed with sibling objects,
|
|
|
|
/// in a style similar to that of literate programming.
|
|
|
|
Text(SPair),
|
2023-04-10 12:16:21 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Display for Doc {
|
|
|
|
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
|
|
|
write!(f, "documentation string")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Doc {
|
|
|
|
/// Document an object using what is ideally a concise independent
|
|
|
|
/// clause.
|
|
|
|
pub fn new_indep_clause(clause: SPair) -> Self {
|
|
|
|
Self::IndepClause(clause)
|
|
|
|
}
|
|
|
|
|
2023-04-12 10:03:37 -04:00
|
|
|
/// Arbitrary text serving as documentation for sibling objects in a
|
|
|
|
/// literate style.
|
|
|
|
pub fn new_text(text: SPair) -> Self {
|
|
|
|
Self::Text(text)
|
|
|
|
}
|
|
|
|
|
2023-04-10 12:16:21 -04:00
|
|
|
pub fn indep_clause(&self) -> Option<SPair> {
|
|
|
|
match self {
|
|
|
|
Self::IndepClause(spair) => Some(*spair),
|
2023-04-12 10:03:37 -04:00
|
|
|
Self::Text(_) => None,
|
2023-04-10 12:16:21 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn span(&self) -> Span {
|
|
|
|
match self {
|
2023-04-12 10:03:37 -04:00
|
|
|
Self::IndepClause(spair) | Self::Text(spair) => spair.span(),
|
2023-04-10 12:16:21 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
object_rel! {
|
|
|
|
/// Templates may expand into nearly any context,
|
|
|
|
/// and must therefore be able to contain just about anything.
|
|
|
|
Doc -> {
|
|
|
|
// empty
|
|
|
|
}
|
|
|
|
}
|