From 9922910d09191bb1033306ccbc92ee6d6d096573 Mon Sep 17 00:00:00 2001 From: Mike Gerwitz Date: Tue, 1 Nov 2022 16:23:51 -0400 Subject: [PATCH] tamer: nir::NirSymbolTy (Display): Add impl Add initial descriptions and consolodate some of the types. There'll be more to come; this is just to get `Display` derives working for types that'll be using it. I'd like to see where this description manifests itself before I decide how user-friendly I'd like it to be. DEV-13156 --- tamer/src/nir.rs | 50 +++++++++++++++++++++++++++++++++++++++--- tamer/src/nir/parse.rs | 14 ++++++------ 2 files changed, 54 insertions(+), 10 deletions(-) diff --git a/tamer/src/nir.rs b/tamer/src/nir.rs index 6f9cf1fc..0d258a6c 100644 --- a/tamer/src/nir.rs +++ b/tamer/src/nir.rs @@ -173,7 +173,6 @@ impl Display for SugaredNir { pub enum NirSymbolTy { AnyIdent, BooleanLiteral, - CalcIdent, ClassIdent, ClassIdentList, ConstIdent, @@ -190,19 +189,64 @@ pub enum NirSymbolTy { ParamName, ParamType, PkgPath, - PkgTitle, ShortDimNumLiteral, StringLiteral, SymbolTableKey, TexMathLiteral, Title, TplMetaIdent, - TplName, + TplIdent, TplParamIdent, TypeIdent, ValueIdent, } +impl Display for NirSymbolTy { + fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { + use NirSymbolTy::*; + + match self { + AnyIdent => write!(f, "any identifier"), + BooleanLiteral => write!( + f, + "boolean literal {fmt_true} or {fmt_false}", + fmt_true = TtQuote::wrap("true"), + fmt_false = TtQuote::wrap("false"), + ), + ClassIdent => write!(f, "classification identifier"), + ClassIdentList => { + write!(f, "space-delimited list of classification identifiers") + } + ConstIdent => write!(f, "constant identifier"), + DescLiteral => write!(f, "description literal"), + Dim => write!(f, "dimension declaration"), + DynNodeLiteral => write!(f, "dynamic node literal"), + FuncIdent => write!(f, "function identifier"), + IdentDtype => write!(f, "identifier primitive datatype"), + IdentType => write!(f, "identifier type"), + MapTransformLiteral => write!(f, "map transformation literal"), + NumLiteral => write!(f, "numeric literal"), + ParamDefault => write!(f, "param default"), + ParamIdent => write!(f, "param identifier"), + ParamName => write!(f, "param name"), + ParamType => write!(f, "param type"), + PkgPath => write!(f, "package path"), + ShortDimNumLiteral => { + write!(f, "short-hand dimensionalized numeric literal") + } + StringLiteral => write!(f, "string literal"), + SymbolTableKey => write!(f, "symbol table key name"), + TexMathLiteral => write!(f, "TeX math literal"), + Title => write!(f, "title"), + TplMetaIdent => write!(f, "template metadata identifier"), + TplIdent => write!(f, "template name"), + TplParamIdent => write!(f, "template param identifier"), + TypeIdent => write!(f, "type identifier"), + ValueIdent => write!(f, "value identifier"), + } + } +} + /// A ([`SymbolId`], [`Span`]) pair in an attribute value context that may /// require desugaring and interpretation within the context of a template /// application. diff --git a/tamer/src/nir/parse.rs b/tamer/src/nir/parse.rs index 71cc7c4f..d08af9e1 100644 --- a/tamer/src/nir/parse.rs +++ b/tamer/src/nir/parse.rs @@ -230,7 +230,7 @@ ele_parse! { _xmlns_lv: (QN_XMLNS_LV?) => Option>, _id: (QN_ID?) => Option>, - _title: (QN_TITLE?) => Option>, + _title: (QN_TITLE?) => Option>, _desc: (QN_DESC?) => Option>, // TODO: When can we get rid of this? _core: (QN_CORE?) => Option>, @@ -403,7 +403,7 @@ ele_parse! { @ { _class: (QN_CLASS?) => Option>, _no: (QN_NO?) => Option>, - _yields: (QN_YIELDS) => N<{CalcIdent}>, + _yields: (QN_YIELDS) => N<{ValueIdent}>, _desc: (QN_DESC?) => Option>, _sym: (QN_SYM?) => Option>, @@ -656,8 +656,8 @@ ele_parse! { SumExpr := QN_C_SUM { @ { _of: (QN_OF?) => Option>, - _generates: (QN_GENERATES?) => Option>, - _index: (QN_INDEX?) => Option>, + _generates: (QN_GENERATES?) => Option>, + _index: (QN_INDEX?) => Option>, _desc: (QN_DESC?) => Option>, _label: (QN_LABEL?) => Option>, _sym: (QN_SYM?) => Option>, @@ -677,8 +677,8 @@ ele_parse! { ProductExpr := QN_C_PRODUCT { @ { _of: (QN_OF?) => Option>, - _generates: (QN_GENERATES?) => Option>, - _index: (QN_INDEX?) => Option>, + _generates: (QN_GENERATES?) => Option>, + _index: (QN_INDEX?) => Option>, _desc: (QN_DESC?) => Option>, _label: (QN_LABEL?) => Option>, _dot: (QN_DOT?) => Option>, @@ -1376,7 +1376,7 @@ ele_parse! { /// Templates are applied using [`ApplyTemplate`] or [`TplApplyShort`]. TemplateStmt := QN_TEMPLATE { @ { - _name: (QN_NAME) => N<{TplName}>, + _name: (QN_NAME) => N<{TplIdent}>, _desc: (QN_DESC) => N<{DescLiteral}>, } => SugaredNir::Todo,