pub mod rti_connext;
use super::{Alternative, Production, ProductionId};
pub use rti_connext::RTI_CONNEXT;
#[derive(Debug, Clone, Copy)]
pub struct GrammarDelta {
pub name: &'static str,
pub additional_productions: &'static [Production],
pub alternative_extensions: &'static [AlternativeExtension],
}
#[derive(Debug, Clone, Copy)]
pub struct AlternativeExtension {
pub target: ProductionId,
pub extra_alternatives: &'static [Alternative],
}
#[cfg(test)]
mod tests {
#![allow(clippy::expect_used)]
use super::*;
use crate::grammar::{Symbol, TokenKind};
const fn alt(symbols: &'static [Symbol]) -> Alternative {
Alternative {
name: None,
symbols,
note: None,
}
}
const fn prod(id: u32, name: &'static str, alts: &'static [Alternative]) -> Production {
Production {
id: ProductionId(id),
name,
spec_ref: super::super::SpecRef {
doc: "TEST",
section: "0",
},
alternatives: alts,
ast_hint: None,
}
}
static EXTRA_PRODS: &[Production] = &[prod(
100,
"rti_extension",
&[alt(&[Symbol::Terminal(TokenKind::Keyword("rti_only"))])],
)];
static EXTRA_ALTS: &[Alternative] =
&[alt(&[Symbol::Terminal(TokenKind::Keyword("vendor_kw"))])];
static EXTENSIONS: &[AlternativeExtension] = &[AlternativeExtension {
target: ProductionId(0),
extra_alternatives: EXTRA_ALTS,
}];
static SAMPLE_DELTA: GrammarDelta = GrammarDelta {
name: "sample",
additional_productions: EXTRA_PRODS,
alternative_extensions: EXTENSIONS,
};
#[test]
fn delta_carries_name_and_additions() {
assert_eq!(SAMPLE_DELTA.name, "sample");
assert_eq!(SAMPLE_DELTA.additional_productions.len(), 1);
assert_eq!(SAMPLE_DELTA.alternative_extensions.len(), 1);
}
#[test]
fn additional_production_addressable() {
let p = SAMPLE_DELTA.additional_productions[0];
assert_eq!(p.name, "rti_extension");
assert_eq!(p.alternatives.len(), 1);
}
#[test]
fn alternative_extension_targets_specific_production() {
let ext = SAMPLE_DELTA.alternative_extensions[0];
assert_eq!(ext.target, ProductionId(0));
assert_eq!(ext.extra_alternatives.len(), 1);
}
#[test]
fn delta_is_copyable_and_clonable() {
let d = SAMPLE_DELTA;
let cloned = d;
assert_eq!(cloned.name, "sample");
}
}