use std::{fmt, iter::FromIterator};
#[cfg(feature = "serde")]
use rserde::{Deserialize, Serialize};
pub use lang_util::{
node::{Node, NodeDisplay},
position::NodeSpan,
FileId, NodeContent, NodeContentDisplay, SmolStr, TextRange, TextSize,
};
macro_rules! impl_node_content {
(
$(#[$m:meta])* $v:vis type $t:ident = Node<$tdata:ident>;
) => {
impl NodeContent for $tdata {}
$(#[$m])* $v type $t = Node<$tdata>;
impl From<Node<$tdata>> for $tdata {
fn from(node: Node<$tdata>) -> Self {
node.content
}
}
};
}
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Hash, NodeContentDisplay)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "serde", serde(crate = "rserde"))]
#[lang_util(display(leaf))]
pub struct IdentifierData(#[lang_util(display(extra))] pub SmolStr);
impl_node_content! {
pub type Identifier = Node<IdentifierData>;
}
impl IdentifierData {
pub fn as_rs_ident(&self) -> Option<&str> {
if self.0.starts_with('#') & self.0.ends_with(')') {
let s = self.0[1..self.0.len() - 1].trim();
Some(s[1..].trim())
} else {
None
}
}
pub fn as_str(&self) -> &str {
self.0.as_str()
}
}
impl From<&str> for IdentifierData {
fn from(ident: &str) -> Self {
Self(ident.into())
}
}
impl fmt::Display for IdentifierData {
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
self.0.fmt(f)
}
}
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Hash, NodeContentDisplay)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "serde", serde(crate = "rserde"))]
#[lang_util(display(leaf))]
pub struct TypeNameData(pub SmolStr);
impl_node_content! {
pub type TypeName = Node<TypeNameData>;
}
impl TypeNameData {
pub fn as_str(&self) -> &str {
self.0.as_str()
}
}
impl From<IdentifierData> for TypeNameData {
fn from(ident: IdentifierData) -> Self {
Self(ident.0)
}
}
impl From<&str> for TypeNameData {
fn from(ident: &str) -> Self {
Self(ident.into())
}
}
impl fmt::Display for TypeNameData {
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
self.0.fmt(f)
}
}
#[derive(Clone, Debug, PartialEq, Eq, NodeContentDisplay)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "serde", serde(crate = "rserde"))]
pub enum PathData {
Absolute(String),
Relative(String),
}
impl_node_content! {
pub type Path = Node<PathData>;
}
#[derive(Clone, Debug, PartialEq, NodeContentDisplay)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "serde", serde(crate = "rserde"))]
pub enum TypeSpecifierNonArrayData {
#[lang_util(display(extra = "void"))]
Void,
#[lang_util(display(extra = "bool"))]
Bool,
#[lang_util(display(extra = "int"))]
Int,
#[lang_util(display(extra = "uint"))]
UInt,
#[lang_util(display(extra = "float"))]
Float,
#[lang_util(display(extra = "double"))]
Double,
#[lang_util(display(extra = "vec2"))]
Vec2,
#[lang_util(display(extra = "vec3"))]
Vec3,
#[lang_util(display(extra = "vec4"))]
Vec4,
#[lang_util(display(extra = "dvec2"))]
DVec2,
#[lang_util(display(extra = "dvec3"))]
DVec3,
#[lang_util(display(extra = "dvec4"))]
DVec4,
#[lang_util(display(extra = "bvec2"))]
BVec2,
#[lang_util(display(extra = "bvec3"))]
BVec3,
#[lang_util(display(extra = "bvec4"))]
BVec4,
#[lang_util(display(extra = "ivec2"))]
IVec2,
#[lang_util(display(extra = "ivec3"))]
IVec3,
#[lang_util(display(extra = "ivec4"))]
IVec4,
#[lang_util(display(extra = "uvec2"))]
UVec2,
#[lang_util(display(extra = "uvec3"))]
UVec3,
#[lang_util(display(extra = "uvec4"))]
UVec4,
#[lang_util(display(extra = "mat2"))]
Mat2,
#[lang_util(display(extra = "mat3"))]
Mat3,
#[lang_util(display(extra = "mat4"))]
Mat4,
#[lang_util(display(extra = "mat2x2"))]
Mat22,
#[lang_util(display(extra = "mat2x3"))]
Mat23,
#[lang_util(display(extra = "mat2x4"))]
Mat24,
#[lang_util(display(extra = "mat3x2"))]
Mat32,
#[lang_util(display(extra = "mat3x3"))]
Mat33,
#[lang_util(display(extra = "mat3x4"))]
Mat34,
#[lang_util(display(extra = "mat4x2"))]
Mat42,
#[lang_util(display(extra = "mat4x3"))]
Mat43,
#[lang_util(display(extra = "mat4x4"))]
Mat44,
#[lang_util(display(extra = "dmat2"))]
DMat2,
#[lang_util(display(extra = "dmat3"))]
DMat3,
#[lang_util(display(extra = "dmat4"))]
DMat4,
#[lang_util(display(extra = "dmat2x2"))]
DMat22,
#[lang_util(display(extra = "dmat2x3"))]
DMat23,
#[lang_util(display(extra = "dmat2x4"))]
DMat24,
#[lang_util(display(extra = "dmat3x2"))]
DMat32,
#[lang_util(display(extra = "dmat3x3"))]
DMat33,
#[lang_util(display(extra = "dmat3x4"))]
DMat34,
#[lang_util(display(extra = "dmat4x2"))]
DMat42,
#[lang_util(display(extra = "dmat4x3"))]
DMat43,
#[lang_util(display(extra = "dmat4x4"))]
DMat44,
#[lang_util(display(extra = "sampler1D"))]
Sampler1D,
#[lang_util(display(extra = "image1D"))]
Image1D,
#[lang_util(display(extra = "sampler2D"))]
Sampler2D,
#[lang_util(display(extra = "image2D"))]
Image2D,
#[lang_util(display(extra = "sampler3D"))]
Sampler3D,
#[lang_util(display(extra = "image3D"))]
Image3D,
#[lang_util(display(extra = "samplerCube"))]
SamplerCube,
#[lang_util(display(extra = "imageCube"))]
ImageCube,
#[lang_util(display(extra = "sampler2DRect"))]
Sampler2DRect,
#[lang_util(display(extra = "image2DRect"))]
Image2DRect,
#[lang_util(display(extra = "sampler1DArray"))]
Sampler1DArray,
#[lang_util(display(extra = "image1DArray"))]
Image1DArray,
#[lang_util(display(extra = "sampler2DArray"))]
Sampler2DArray,
#[lang_util(display(extra = "image2DArray"))]
Image2DArray,
#[lang_util(display(extra = "samplerBuffer"))]
SamplerBuffer,
#[lang_util(display(extra = "imageBuffer"))]
ImageBuffer,
#[lang_util(display(extra = "sampler2DMS"))]
Sampler2DMs,
#[lang_util(display(extra = "image2DMS"))]
Image2DMs,
#[lang_util(display(extra = "sampler2DMSArray"))]
Sampler2DMsArray,
#[lang_util(display(extra = "image2DMSArray"))]
Image2DMsArray,
#[lang_util(display(extra = "samplerCubeArray"))]
SamplerCubeArray,
#[lang_util(display(extra = "imageCubeArray"))]
ImageCubeArray,
#[lang_util(display(extra = "sampler1DShadow"))]
Sampler1DShadow,
#[lang_util(display(extra = "sampler2DShadow"))]
Sampler2DShadow,
#[lang_util(display(extra = "sampler2DRectShadow"))]
Sampler2DRectShadow,
#[lang_util(display(extra = "sampler1DArrayShadow"))]
Sampler1DArrayShadow,
#[lang_util(display(extra = "sampler2DArrayShadow"))]
Sampler2DArrayShadow,
#[lang_util(display(extra = "samplerCubeShadow"))]
SamplerCubeShadow,
#[lang_util(display(extra = "samplerCubeArrayShadow"))]
SamplerCubeArrayShadow,
#[lang_util(display(extra = "isampler1D"))]
ISampler1D,
#[lang_util(display(extra = "iimage1D"))]
IImage1D,
#[lang_util(display(extra = "isampler2D"))]
ISampler2D,
#[lang_util(display(extra = "iimage2D"))]
IImage2D,
#[lang_util(display(extra = "isampler3D"))]
ISampler3D,
#[lang_util(display(extra = "iimage3D"))]
IImage3D,
#[lang_util(display(extra = "isamplerCube"))]
ISamplerCube,
#[lang_util(display(extra = "iimageCube"))]
IImageCube,
#[lang_util(display(extra = "isampler2DRect"))]
ISampler2DRect,
#[lang_util(display(extra = "iimage2DRect"))]
IImage2DRect,
#[lang_util(display(extra = "isampler1DArray"))]
ISampler1DArray,
#[lang_util(display(extra = "iimage1DArray"))]
IImage1DArray,
#[lang_util(display(extra = "isampler2DArray"))]
ISampler2DArray,
#[lang_util(display(extra = "iimage2DArray"))]
IImage2DArray,
#[lang_util(display(extra = "isamplerBuffer"))]
ISamplerBuffer,
#[lang_util(display(extra = "iimageBuffer"))]
IImageBuffer,
#[lang_util(display(extra = "isampler2DMS"))]
ISampler2DMs,
#[lang_util(display(extra = "iimage2DMS"))]
IImage2DMs,
#[lang_util(display(extra = "isampler2DMSArray"))]
ISampler2DMsArray,
#[lang_util(display(extra = "iimage2DMSArray"))]
IImage2DMsArray,
#[lang_util(display(extra = "isamplerCubeArray"))]
ISamplerCubeArray,
#[lang_util(display(extra = "iimageCubeArray"))]
IImageCubeArray,
#[lang_util(display(extra = "atomic_uint"))]
AtomicUInt,
#[lang_util(display(extra = "usampler1D"))]
USampler1D,
#[lang_util(display(extra = "uimage1D"))]
UImage1D,
#[lang_util(display(extra = "usampler2D"))]
USampler2D,
#[lang_util(display(extra = "uimage2D"))]
UImage2D,
#[lang_util(display(extra = "usampler3D"))]
USampler3D,
#[lang_util(display(extra = "uimage3D"))]
UImage3D,
#[lang_util(display(extra = "usamplerCube"))]
USamplerCube,
#[lang_util(display(extra = "uimageCube"))]
UImageCube,
#[lang_util(display(extra = "usampler2DRect"))]
USampler2DRect,
#[lang_util(display(extra = "uimage2DRect"))]
UImage2DRect,
#[lang_util(display(extra = "usampler1DArray"))]
USampler1DArray,
#[lang_util(display(extra = "uimage1DArray"))]
UImage1DArray,
#[lang_util(display(extra = "usampler2DArray"))]
USampler2DArray,
#[lang_util(display(extra = "uimage2DArray"))]
UImage2DArray,
#[lang_util(display(extra = "usamplerBuffer"))]
USamplerBuffer,
#[lang_util(display(extra = "uimageBuffer"))]
UImageBuffer,
#[lang_util(display(extra = "usampler2DMS"))]
USampler2DMs,
#[lang_util(display(extra = "uimage2DMS"))]
UImage2DMs,
#[lang_util(display(extra = "usampler2DMSArray"))]
USampler2DMsArray,
#[lang_util(display(extra = "uimage2DMSArray"))]
UImage2DMsArray,
#[lang_util(display(extra = "usamplerCubeArray"))]
USamplerCubeArray,
#[lang_util(display(extra = "uimageCubeArray"))]
UImageCubeArray,
#[lang_util(display(extra = "texture1D"))]
Texture1D,
#[lang_util(display(extra = "texture2D"))]
Texture2D,
#[lang_util(display(extra = "texture3D"))]
Texture3D,
#[lang_util(display(extra = "textureCube"))]
TextureCube,
#[lang_util(display(extra = "texture2DRect"))]
Texture2DRect,
#[lang_util(display(extra = "texture1DArray"))]
Texture1DArray,
#[lang_util(display(extra = "texture2DArray"))]
Texture2DArray,
#[lang_util(display(extra = "textureBuffer"))]
TextureBuffer,
#[lang_util(display(extra = "texture2DMS"))]
Texture2DMs,
#[lang_util(display(extra = "texture2DMSArray"))]
Texture2DMsArray,
#[lang_util(display(extra = "textureCubeArray"))]
TextureCubeArray,
#[lang_util(display(extra = "itexture1D"))]
ITexture1D,
#[lang_util(display(extra = "itexture2D"))]
ITexture2D,
#[lang_util(display(extra = "itexture3D"))]
ITexture3D,
#[lang_util(display(extra = "itextureCube"))]
ITextureCube,
#[lang_util(display(extra = "itexture2DRect"))]
ITexture2DRect,
#[lang_util(display(extra = "itexture1DArray"))]
ITexture1DArray,
#[lang_util(display(extra = "itexture2DArray"))]
ITexture2DArray,
#[lang_util(display(extra = "itextureBuffer"))]
ITextureBuffer,
#[lang_util(display(extra = "itexture2DMS"))]
ITexture2DMs,
#[lang_util(display(extra = "itexture2DMSArray"))]
ITexture2DMsArray,
#[lang_util(display(extra = "itextureCubeArray"))]
ITextureCubeArray,
#[lang_util(display(extra = "sampler"))]
Sampler,
#[lang_util(display(extra = "samplerShadow"))]
SamplerShadow,
#[lang_util(display(extra = "subpassInput"))]
SubpassInput,
#[lang_util(display(extra = "isubpassInput"))]
ISubpassInput,
#[lang_util(display(extra = "usubpassInput"))]
USubpassInput,
#[lang_util(display(extra = "subpassInputMS"))]
SubpassInputMs,
#[lang_util(display(extra = "isubpassInputMS"))]
ISubpassInputMs,
#[lang_util(display(extra = "usubpassInputMS"))]
USubpassInputMs,
#[lang_util(display(extra = "struct"))]
Struct(StructSpecifier),
TypeName(TypeName),
}
impl_node_content! {
pub type TypeSpecifierNonArray = Node<TypeSpecifierNonArrayData>;
}
impl From<TypeName> for TypeSpecifierNonArrayData {
fn from(tn: TypeName) -> Self {
Self::TypeName(tn)
}
}
#[derive(Clone, Debug, PartialEq, NodeContentDisplay)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "serde", serde(crate = "rserde"))]
pub struct TypeSpecifierData {
pub ty: TypeSpecifierNonArray,
pub array_specifier: Option<ArraySpecifier>,
}
impl_node_content! {
pub type TypeSpecifier = Node<TypeSpecifierData>;
}
impl From<TypeSpecifierNonArray> for TypeSpecifierData {
fn from(ty: TypeSpecifierNonArray) -> Self {
Self {
ty,
array_specifier: None,
}
}
}
impl From<TypeSpecifierNonArrayData> for TypeSpecifierData {
fn from(ty: TypeSpecifierNonArrayData) -> Self {
Self {
ty: ty.into(),
array_specifier: None,
}
}
}
#[derive(Clone, Debug, PartialEq, NodeContentDisplay)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "serde", serde(crate = "rserde"))]
pub struct StructSpecifierData {
pub name: Option<TypeName>,
pub fields: Vec<StructFieldSpecifier>,
}
impl_node_content! {
pub type StructSpecifier = Node<StructSpecifierData>;
}
#[derive(Clone, Debug, PartialEq, NodeContentDisplay)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "serde", serde(crate = "rserde"))]
pub struct StructFieldSpecifierData {
pub qualifier: Option<TypeQualifier>,
pub ty: TypeSpecifier,
pub identifiers: Vec<ArrayedIdentifier>, }
impl_node_content! {
pub type StructFieldSpecifier = Node<StructFieldSpecifierData>;
}
#[derive(Clone, Debug, PartialEq, NodeContentDisplay)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "serde", serde(crate = "rserde"))]
pub struct ArrayedIdentifierData {
pub ident: Identifier,
pub array_spec: Option<ArraySpecifier>,
}
impl_node_content! {
pub type ArrayedIdentifier = Node<ArrayedIdentifierData>;
}
impl ArrayedIdentifierData {
pub fn new<I, AS>(ident: I, array_spec: AS) -> Self
where
I: Into<Identifier>,
AS: Into<Option<ArraySpecifier>>,
{
Self {
ident: ident.into(),
array_spec: array_spec.into(),
}
}
}
impl From<&str> for ArrayedIdentifierData {
fn from(ident: &str) -> Self {
Self {
ident: IdentifierData::from(ident).into(),
array_spec: None,
}
}
}
#[derive(Clone, Debug, PartialEq, NodeContentDisplay)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "serde", serde(crate = "rserde"))]
pub struct TypeQualifierData {
pub qualifiers: Vec<TypeQualifierSpec>,
}
impl_node_content! {
pub type TypeQualifier = Node<TypeQualifierData>;
}
#[derive(Clone, Debug, PartialEq, NodeContentDisplay)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "serde", serde(crate = "rserde"))]
pub enum TypeQualifierSpecData {
Storage(StorageQualifier),
Layout(LayoutQualifier),
Precision(PrecisionQualifier),
Interpolation(InterpolationQualifier),
Invariant,
Precise,
}
impl_node_content! {
pub type TypeQualifierSpec = Node<TypeQualifierSpecData>;
}
#[derive(Clone, Debug, PartialEq, NodeContentDisplay)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "serde", serde(crate = "rserde"))]
pub enum StorageQualifierData {
#[lang_util(display(extra = "const"))]
Const,
#[lang_util(display(extra = "inout"))]
InOut,
#[lang_util(display(extra = "in"))]
In,
#[lang_util(display(extra = "out"))]
Out,
#[lang_util(display(extra = "centroid"))]
Centroid,
#[lang_util(display(extra = "patch"))]
Patch,
#[lang_util(display(extra = "sample"))]
Sample,
#[lang_util(display(extra = "uniform"))]
Uniform,
#[lang_util(display(extra = "buffer"))]
Buffer,
#[lang_util(display(extra = "shared"))]
Shared,
#[lang_util(display(extra = "coherent"))]
Coherent,
#[lang_util(display(extra = "volatile"))]
Volatile,
#[lang_util(display(extra = "restrict"))]
Restrict,
#[lang_util(display(extra = "readonly"))]
ReadOnly,
#[lang_util(display(extra = "writeonly"))]
WriteOnly,
#[lang_util(display(extra = "attribute"))]
Attribute,
#[lang_util(display(extra = "varying"))]
Varying,
#[lang_util(display(extra = "subroutine"))]
Subroutine(Vec<TypeSpecifier>),
}
impl_node_content! {
pub type StorageQualifier = Node<StorageQualifierData>;
}
#[derive(Clone, Debug, PartialEq, NodeContentDisplay)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "serde", serde(crate = "rserde"))]
pub struct LayoutQualifierData {
pub ids: Vec<LayoutQualifierSpec>,
}
impl_node_content! {
pub type LayoutQualifier = Node<LayoutQualifierData>;
}
#[derive(Clone, Debug, PartialEq, NodeContentDisplay)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "serde", serde(crate = "rserde"))]
pub enum LayoutQualifierSpecData {
Identifier(Identifier, Option<Box<Expr>>),
#[lang_util(display(extra = "shared"))]
Shared,
}
impl_node_content! {
pub type LayoutQualifierSpec = Node<LayoutQualifierSpecData>;
}
#[derive(Clone, Debug, PartialEq, Eq, NodeContentDisplay)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "serde", serde(crate = "rserde"))]
pub enum PrecisionQualifierData {
#[lang_util(display(extra = "high"))]
High,
#[lang_util(display(extra = "medium"))]
Medium,
#[lang_util(display(extra = "low"))]
Low,
}
impl_node_content! {
pub type PrecisionQualifier = Node<PrecisionQualifierData>;
}
#[derive(Clone, Debug, PartialEq, Eq, NodeContentDisplay)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "serde", serde(crate = "rserde"))]
pub enum InterpolationQualifierData {
#[lang_util(display(extra = "smooth"))]
Smooth,
#[lang_util(display(extra = "flat"))]
Flat,
#[lang_util(display(extra = "noperspective"))]
NoPerspective,
}
impl_node_content! {
pub type InterpolationQualifier = Node<InterpolationQualifierData>;
}
#[derive(Clone, Debug, PartialEq, NodeContentDisplay)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "serde", serde(crate = "rserde"))]
pub struct FullySpecifiedTypeData {
pub qualifier: Option<TypeQualifier>,
pub ty: TypeSpecifier,
}
impl_node_content! {
pub type FullySpecifiedType = Node<FullySpecifiedTypeData>;
}
impl FullySpecifiedTypeData {
pub fn new(ty: TypeSpecifierNonArray) -> Self {
Self {
qualifier: None,
ty: TypeSpecifierData {
ty,
array_specifier: None,
}
.into(),
}
}
}
impl From<TypeSpecifierNonArrayData> for FullySpecifiedTypeData {
fn from(ty: TypeSpecifierNonArrayData) -> Self {
Self::new(ty.into())
}
}
#[derive(Clone, Debug, PartialEq, NodeContentDisplay)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "serde", serde(crate = "rserde"))]
pub struct ArraySpecifierData {
pub dimensions: Vec<ArraySpecifierDimension>,
}
impl_node_content! {
pub type ArraySpecifier = Node<ArraySpecifierData>;
}
#[derive(Clone, Debug, PartialEq, NodeContentDisplay)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "serde", serde(crate = "rserde"))]
pub enum ArraySpecifierDimensionData {
Unsized,
ExplicitlySized(Box<Expr>),
}
impl_node_content! {
pub type ArraySpecifierDimension = Node<ArraySpecifierDimensionData>;
}
#[derive(Clone, Debug, PartialEq, NodeContentDisplay)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "serde", serde(crate = "rserde"))]
pub enum DeclarationData {
FunctionPrototype(FunctionPrototype),
InitDeclaratorList(InitDeclaratorList),
Precision(PrecisionQualifier, TypeSpecifier),
Block(Block),
Invariant(Identifier),
TypeOnly(TypeQualifier),
}
impl_node_content! {
pub type Declaration = Node<DeclarationData>;
}
#[derive(Clone, Debug, PartialEq, NodeContentDisplay)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "serde", serde(crate = "rserde"))]
pub struct BlockData {
pub qualifier: TypeQualifier,
pub name: Identifier,
pub fields: Vec<StructFieldSpecifier>,
pub identifier: Option<ArrayedIdentifier>,
}
impl_node_content! {
pub type Block = Node<BlockData>;
}
#[derive(Clone, Debug, PartialEq, NodeContentDisplay)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "serde", serde(crate = "rserde"))]
pub enum FunIdentifierData {
TypeSpecifier(Box<TypeSpecifier>),
Expr(Box<Expr>),
}
impl_node_content! {
pub type FunIdentifier = Node<FunIdentifierData>;
}
impl FunIdentifierData {
pub fn ident(i: impl Into<IdentifierData>) -> Self {
Self::Expr(Box::new(ExprData::Variable(i.into().into()).into()))
}
pub fn as_ident(&self) -> Option<&Identifier> {
match self {
Self::Expr(expr) => match &***expr {
ExprData::Variable(ident) => Some(ident),
_ => None,
},
_ => None,
}
}
pub fn as_ident_mut(&mut self) -> Option<&mut Identifier> {
match self {
Self::Expr(expr) => match &mut ***expr {
ExprData::Variable(ident) => Some(ident),
_ => None,
},
_ => None,
}
}
pub fn as_rs_ident(&self) -> Option<&str> {
if let Some(ident) = self.as_ident() {
ident.as_rs_ident()
} else {
None
}
}
}
#[derive(Clone, Debug, PartialEq, NodeContentDisplay)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "serde", serde(crate = "rserde"))]
pub struct FunctionPrototypeData {
pub ty: FullySpecifiedType,
pub name: Identifier,
pub parameters: Vec<FunctionParameterDeclaration>,
}
impl_node_content! {
pub type FunctionPrototype = Node<FunctionPrototypeData>;
}
#[derive(Clone, Debug, PartialEq, NodeContentDisplay)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "serde", serde(crate = "rserde"))]
pub enum FunctionParameterDeclarationData {
Named(Option<TypeQualifier>, FunctionParameterDeclarator),
Unnamed(Option<TypeQualifier>, TypeSpecifier),
}
impl_node_content! {
pub type FunctionParameterDeclaration = Node<FunctionParameterDeclarationData>;
}
#[derive(Clone, Debug, PartialEq, NodeContentDisplay)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "serde", serde(crate = "rserde"))]
pub struct FunctionParameterDeclaratorData {
pub ty: TypeSpecifier,
pub ident: ArrayedIdentifier,
}
impl_node_content! {
pub type FunctionParameterDeclarator = Node<FunctionParameterDeclaratorData>;
}
#[derive(Clone, Debug, PartialEq, NodeContentDisplay)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "serde", serde(crate = "rserde"))]
pub struct InitDeclaratorListData {
pub head: SingleDeclaration,
pub tail: Vec<SingleDeclarationNoType>,
}
impl_node_content! {
pub type InitDeclaratorList = Node<InitDeclaratorListData>;
}
#[derive(Clone, Debug, PartialEq, NodeContentDisplay)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "serde", serde(crate = "rserde"))]
pub struct SingleDeclarationData {
pub ty: FullySpecifiedType,
pub name: Option<Identifier>,
pub array_specifier: Option<ArraySpecifier>,
pub initializer: Option<Initializer>,
}
impl_node_content! {
pub type SingleDeclaration = Node<SingleDeclarationData>;
}
#[derive(Clone, Debug, PartialEq, NodeContentDisplay)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "serde", serde(crate = "rserde"))]
pub struct SingleDeclarationNoTypeData {
pub ident: ArrayedIdentifier,
pub initializer: Option<Initializer>,
}
impl_node_content! {
pub type SingleDeclarationNoType = Node<SingleDeclarationNoTypeData>;
}
#[derive(Clone, Debug, PartialEq, NodeContentDisplay)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "serde", serde(crate = "rserde"))]
pub enum InitializerData {
Simple(Box<Expr>),
List(Vec<Initializer>),
}
impl_node_content! {
pub type Initializer = Node<InitializerData>;
}
impl From<ExprData> for InitializerData {
fn from(e: ExprData) -> Self {
Self::Simple(Box::new(e.into()))
}
}
impl From<Expr> for InitializerData {
fn from(e: Expr) -> Self {
Self::Simple(Box::new(e))
}
}
#[derive(Clone, Debug, PartialEq, NodeContentDisplay)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "serde", serde(crate = "rserde"))]
pub enum ExprData {
Variable(Identifier),
IntConst(i32),
UIntConst(u32),
BoolConst(bool),
FloatConst(f32),
DoubleConst(f64),
Unary(UnaryOp, Box<Expr>),
Binary(BinaryOp, Box<Expr>, Box<Expr>),
Ternary(Box<Expr>, Box<Expr>, Box<Expr>),
Assignment(Box<Expr>, AssignmentOp, Box<Expr>),
Bracket(Box<Expr>, Box<Expr>),
FunCall(FunIdentifier, Vec<Expr>),
Dot(Box<Expr>, Identifier),
PostInc(Box<Expr>),
PostDec(Box<Expr>),
Comma(Box<Expr>, Box<Expr>),
}
impl_node_content! {
pub type Expr = Node<ExprData>;
}
impl ExprData {
pub fn variable(name: impl Into<IdentifierData>) -> Self {
Self::Variable(name.into().into())
}
pub fn as_rs_ident(&self) -> Option<&str> {
match self {
Self::Variable(ident) => ident.as_rs_ident(),
_ => None,
}
}
}
impl From<i32> for ExprData {
fn from(x: i32) -> ExprData {
Self::IntConst(x)
}
}
impl From<u32> for ExprData {
fn from(x: u32) -> ExprData {
Self::UIntConst(x)
}
}
impl From<bool> for ExprData {
fn from(x: bool) -> ExprData {
Self::BoolConst(x)
}
}
impl From<f32> for ExprData {
fn from(x: f32) -> ExprData {
Self::FloatConst(x)
}
}
impl From<f64> for ExprData {
fn from(x: f64) -> ExprData {
Self::DoubleConst(x)
}
}
#[derive(Clone, Debug, PartialEq, Eq, NodeContentDisplay)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "serde", serde(crate = "rserde"))]
pub enum UnaryOpData {
#[lang_util(display(extra = "++"))]
Inc,
#[lang_util(display(extra = "--"))]
Dec,
#[lang_util(display(extra = "+"))]
Add,
#[lang_util(display(extra = "-"))]
Minus,
#[lang_util(display(extra = "!"))]
Not,
#[lang_util(display(extra = "~"))]
Complement,
}
impl_node_content! {
pub type UnaryOp = Node<UnaryOpData>;
}
#[derive(Clone, Debug, PartialEq, Eq, NodeContentDisplay)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "serde", serde(crate = "rserde"))]
pub enum BinaryOpData {
#[lang_util(display(extra = "||"))]
Or,
#[lang_util(display(extra = "^^"))]
Xor,
#[lang_util(display(extra = "&&"))]
And,
#[lang_util(display(extra = "|"))]
BitOr,
#[lang_util(display(extra = "^"))]
BitXor,
#[lang_util(display(extra = "&"))]
BitAnd,
#[lang_util(display(extra = "=="))]
Equal,
#[lang_util(display(extra = "!="))]
NonEqual,
#[lang_util(display(extra = "<"))]
Lt,
#[lang_util(display(extra = ">"))]
Gt,
#[lang_util(display(extra = "<="))]
Lte,
#[lang_util(display(extra = ">="))]
Gte,
#[lang_util(display(extra = "<<"))]
LShift,
#[lang_util(display(extra = ">>"))]
RShift,
#[lang_util(display(extra = "+"))]
Add,
#[lang_util(display(extra = "-"))]
Sub,
#[lang_util(display(extra = "*"))]
Mult,
#[lang_util(display(extra = "/"))]
Div,
#[lang_util(display(extra = "%"))]
Mod,
}
impl_node_content! {
pub type BinaryOp = Node<BinaryOpData>;
}
#[derive(Clone, Debug, PartialEq, Eq, NodeContentDisplay)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "serde", serde(crate = "rserde"))]
pub enum AssignmentOpData {
#[lang_util(display(extra = "="))]
Equal,
#[lang_util(display(extra = "*"))]
Mult,
#[lang_util(display(extra = "/="))]
Div,
#[lang_util(display(extra = "%="))]
Mod,
#[lang_util(display(extra = "+="))]
Add,
#[lang_util(display(extra = "-="))]
Sub,
#[lang_util(display(extra = "<<="))]
LShift,
#[lang_util(display(extra = ">>="))]
RShift,
#[lang_util(display(extra = "&="))]
And,
#[lang_util(display(extra = "^="))]
Xor,
#[lang_util(display(extra = "|="))]
Or,
}
impl_node_content! {
pub type AssignmentOp = Node<AssignmentOpData>;
}
#[derive(Clone, Debug, PartialEq, NodeContentDisplay)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "serde", serde(crate = "rserde"))]
pub struct TranslationUnit(pub Vec<ExternalDeclaration>);
impl NodeContent for TranslationUnit {}
#[derive(Clone, Debug, PartialEq, NodeContentDisplay)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "serde", serde(crate = "rserde"))]
pub enum ExternalDeclarationData {
Preprocessor(Preprocessor),
FunctionDefinition(FunctionDefinition),
Declaration(Declaration),
}
impl_node_content! {
pub type ExternalDeclaration = Node<ExternalDeclarationData>;
}
#[derive(Clone, Debug, PartialEq, NodeContentDisplay)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "serde", serde(crate = "rserde"))]
pub struct FunctionDefinitionData {
pub prototype: FunctionPrototype,
pub statement: CompoundStatement,
}
impl_node_content! {
pub type FunctionDefinition = Node<FunctionDefinitionData>;
}
#[derive(Clone, Debug, PartialEq, NodeContentDisplay)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "serde", serde(crate = "rserde"))]
pub struct CompoundStatementData {
pub statement_list: Vec<Statement>,
}
impl_node_content! {
pub type CompoundStatement = Node<CompoundStatementData>;
}
impl FromIterator<Statement> for CompoundStatementData {
fn from_iter<T>(iter: T) -> Self
where
T: IntoIterator<Item = Statement>,
{
Self {
statement_list: iter.into_iter().collect(),
}
}
}
#[derive(Clone, Debug, PartialEq, NodeContentDisplay)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "serde", serde(crate = "rserde"))]
pub enum StatementData {
Declaration(Declaration),
Expression(ExprStatement),
Selection(SelectionStatement),
Switch(SwitchStatement),
CaseLabel(CaseLabel),
Iteration(IterationStatement),
Jump(JumpStatement),
Compound(CompoundStatement),
}
impl_node_content! {
pub type Statement = Node<StatementData>;
}
impl StatementData {
pub fn declare_var<T, N, A, I>(ty: T, name: N, array_specifier: A, initializer: I) -> Self
where
T: Into<FullySpecifiedTypeData>,
N: Into<IdentifierData>,
A: Into<Option<ArraySpecifier>>,
I: Into<Option<Initializer>>,
{
Self::Declaration(
DeclarationData::InitDeclaratorList(
InitDeclaratorListData {
head: SingleDeclarationData {
ty: ty.into().into(),
name: Some(name.into().into()),
array_specifier: array_specifier.into(),
initializer: initializer.into(),
}
.into(),
tail: Vec::new(),
}
.into(),
)
.into(),
)
}
}
#[derive(Clone, Debug, PartialEq, NodeContentDisplay)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "serde", serde(crate = "rserde"))]
pub struct ExprStatementData(pub Option<Expr>);
impl_node_content! {
pub type ExprStatement = Node<ExprStatementData>;
}
#[derive(Clone, Debug, PartialEq, NodeContentDisplay)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "serde", serde(crate = "rserde"))]
pub struct SelectionStatementData {
pub cond: Box<Expr>,
pub rest: SelectionRestStatement,
}
impl_node_content! {
pub type SelectionStatement = Node<SelectionStatementData>;
}
#[derive(Clone, Debug, PartialEq, NodeContentDisplay)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "serde", serde(crate = "rserde"))]
pub enum ConditionData {
Expr(Expr),
Assignment(Box<FullySpecifiedType>, Identifier, Initializer),
}
impl_node_content! {
pub type Condition = Node<ConditionData>;
}
#[derive(Clone, Debug, PartialEq, NodeContentDisplay)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "serde", serde(crate = "rserde"))]
pub enum SelectionRestStatementData {
Statement(Box<Statement>),
Else(Box<Statement>, Box<Statement>),
}
impl_node_content! {
pub type SelectionRestStatement = Node<SelectionRestStatementData>;
}
#[derive(Clone, Debug, PartialEq, NodeContentDisplay)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "serde", serde(crate = "rserde"))]
pub struct SwitchStatementData {
pub head: Box<Expr>,
pub body: Vec<Statement>,
}
impl_node_content! {
pub type SwitchStatement = Node<SwitchStatementData>;
}
#[derive(Clone, Debug, PartialEq, NodeContentDisplay)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "serde", serde(crate = "rserde"))]
pub enum CaseLabelData {
Case(Box<Expr>),
Def,
}
impl_node_content! {
pub type CaseLabel = Node<CaseLabelData>;
}
#[derive(Clone, Debug, PartialEq, NodeContentDisplay)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "serde", serde(crate = "rserde"))]
pub enum IterationStatementData {
#[lang_util(display(extra = "while"))]
While(Condition, Box<Statement>),
#[lang_util(display(extra = "do"))]
DoWhile(Box<Statement>, Box<Expr>),
#[lang_util(display(extra = "for"))]
For(ForInitStatement, ForRestStatement, Box<Statement>),
}
impl_node_content! {
pub type IterationStatement = Node<IterationStatementData>;
}
#[derive(Clone, Debug, PartialEq, NodeContentDisplay)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "serde", serde(crate = "rserde"))]
pub enum ForInitStatementData {
Expression(Option<Expr>),
Declaration(Box<Declaration>),
}
impl_node_content! {
pub type ForInitStatement = Node<ForInitStatementData>;
}
#[derive(Clone, Debug, PartialEq, NodeContentDisplay)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "serde", serde(crate = "rserde"))]
pub struct ForRestStatementData {
pub condition: Option<Condition>,
pub post_expr: Option<Box<Expr>>,
}
impl_node_content! {
pub type ForRestStatement = Node<ForRestStatementData>;
}
#[derive(Clone, Debug, PartialEq, NodeContentDisplay)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "serde", serde(crate = "rserde"))]
pub enum JumpStatementData {
#[lang_util(display(extra = "continue"))]
Continue,
#[lang_util(display(extra = "break"))]
Break,
#[lang_util(display(extra = "return"))]
Return(Option<Box<Expr>>),
#[lang_util(display(extra = "discard"))]
Discard,
}
impl_node_content! {
pub type JumpStatement = Node<JumpStatementData>;
}
#[derive(Clone, Debug, PartialEq, Eq, NodeContentDisplay)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "serde", serde(crate = "rserde"))]
pub enum PreprocessorData {
#[lang_util(display(extra = "#define"))]
Define(PreprocessorDefine),
#[lang_util(display(extra = "#else"))]
Else,
#[lang_util(display(extra = "#elseif"))]
ElseIf(PreprocessorElseIf),
#[lang_util(display(extra = "#endif"))]
EndIf,
#[lang_util(display(extra = "#error"))]
Error(PreprocessorError),
#[lang_util(display(extra = "#if"))]
If(PreprocessorIf),
#[lang_util(display(extra = "#ifdef"))]
IfDef(PreprocessorIfDef),
#[lang_util(display(extra = "#ifndef"))]
IfNDef(PreprocessorIfNDef),
#[lang_util(display(extra = "#include"))]
Include(PreprocessorInclude),
#[lang_util(display(extra = "#line"))]
Line(PreprocessorLine),
#[lang_util(display(extra = "#pragma"))]
Pragma(PreprocessorPragma),
#[lang_util(display(extra = "#undef"))]
Undef(PreprocessorUndef),
#[lang_util(display(extra = "#version"))]
Version(PreprocessorVersion),
#[lang_util(display(extra = "#extension"))]
Extension(PreprocessorExtension),
}
impl_node_content! {
pub type Preprocessor = Node<PreprocessorData>;
}
#[derive(Clone, Debug, PartialEq, Eq, NodeContentDisplay)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "serde", serde(crate = "rserde"))]
pub enum PreprocessorDefineData {
ObjectLike {
ident: Identifier,
value: String,
},
FunctionLike {
ident: Identifier,
args: Vec<Identifier>,
value: String,
},
}
impl_node_content! {
pub type PreprocessorDefine = Node<PreprocessorDefineData>;
}
#[derive(Clone, Debug, PartialEq, Eq, NodeContentDisplay)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "serde", serde(crate = "rserde"))]
pub struct PreprocessorElseIfData {
#[lang_util(display(extra))]
pub condition: String,
}
impl_node_content! {
pub type PreprocessorElseIf = Node<PreprocessorElseIfData>;
}
#[derive(Clone, Debug, PartialEq, Eq, NodeContentDisplay)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "serde", serde(crate = "rserde"))]
pub struct PreprocessorErrorData {
#[lang_util(display(extra))]
pub message: String,
}
impl_node_content! {
pub type PreprocessorError = Node<PreprocessorErrorData>;
}
#[derive(Clone, Debug, PartialEq, Eq, NodeContentDisplay)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "serde", serde(crate = "rserde"))]
pub struct PreprocessorIfData {
#[lang_util(display(extra))]
pub condition: String,
}
impl_node_content! {
pub type PreprocessorIf = Node<PreprocessorIfData>;
}
#[derive(Clone, Debug, PartialEq, Eq, NodeContentDisplay)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "serde", serde(crate = "rserde"))]
pub struct PreprocessorIfDefData {
#[lang_util(display(extra))]
pub ident: Identifier,
}
impl_node_content! {
pub type PreprocessorIfDef = Node<PreprocessorIfDefData>;
}
#[derive(Clone, Debug, PartialEq, Eq, NodeContentDisplay)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "serde", serde(crate = "rserde"))]
pub struct PreprocessorIfNDefData {
#[lang_util(display(extra))]
pub ident: Identifier,
}
impl_node_content! {
pub type PreprocessorIfNDef = Node<PreprocessorIfNDefData>;
}
#[derive(Clone, Debug, PartialEq, Eq, NodeContentDisplay)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "serde", serde(crate = "rserde"))]
pub struct PreprocessorIncludeData {
pub path: Path,
}
impl_node_content! {
pub type PreprocessorInclude = Node<PreprocessorIncludeData>;
}
#[derive(Clone, Debug, PartialEq, Eq, NodeContentDisplay)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "serde", serde(crate = "rserde"))]
pub struct PreprocessorLineData {
#[lang_util(display(extra))]
pub line: u32,
pub source_string_number: Option<u32>,
}
impl_node_content! {
pub type PreprocessorLine = Node<PreprocessorLineData>;
}
#[derive(Clone, Debug, PartialEq, Eq, NodeContentDisplay)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "serde", serde(crate = "rserde"))]
pub struct PreprocessorPragmaData {
#[lang_util(display(extra))]
pub command: String,
}
impl_node_content! {
pub type PreprocessorPragma = Node<PreprocessorPragmaData>;
}
#[derive(Clone, Debug, PartialEq, Eq, NodeContentDisplay)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "serde", serde(crate = "rserde"))]
pub struct PreprocessorUndefData {
#[lang_util(display(extra))]
pub name: Identifier,
}
impl_node_content! {
pub type PreprocessorUndef = Node<PreprocessorUndefData>;
}
#[derive(Clone, Debug, PartialEq, Eq, NodeContentDisplay)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "serde", serde(crate = "rserde"))]
pub struct PreprocessorVersionData {
#[lang_util(display(extra))]
pub version: u16,
pub profile: Option<PreprocessorVersionProfile>,
}
impl_node_content! {
pub type PreprocessorVersion = Node<PreprocessorVersionData>;
}
#[derive(Clone, Debug, PartialEq, Eq, NodeContentDisplay)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "serde", serde(crate = "rserde"))]
pub enum PreprocessorVersionProfileData {
#[lang_util(display(extra = "core"))]
Core,
#[lang_util(display(extra = "compatibility"))]
Compatibility,
#[lang_util(display(extra = "es"))]
Es,
}
impl_node_content! {
pub type PreprocessorVersionProfile = Node<PreprocessorVersionProfileData>;
}
#[derive(Clone, Debug, PartialEq, Eq, NodeContentDisplay)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "serde", serde(crate = "rserde"))]
pub struct PreprocessorExtensionData {
pub name: PreprocessorExtensionName,
pub behavior: Option<PreprocessorExtensionBehavior>,
}
impl_node_content! {
pub type PreprocessorExtension = Node<PreprocessorExtensionData>;
}
#[derive(Clone, Debug, PartialEq, Eq, NodeContentDisplay)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "serde", serde(crate = "rserde"))]
pub enum PreprocessorExtensionNameData {
#[lang_util(display(extra = "all"))]
All,
Specific(SmolStr),
}
impl_node_content! {
pub type PreprocessorExtensionName = Node<PreprocessorExtensionNameData>;
}
#[derive(Clone, Debug, PartialEq, Eq, NodeContentDisplay)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "serde", serde(crate = "rserde"))]
pub enum PreprocessorExtensionBehaviorData {
#[lang_util(display(extra = "require"))]
Require,
#[lang_util(display(extra = "enable"))]
Enable,
#[lang_util(display(extra = "warn"))]
Warn,
#[lang_util(display(extra = "disable"))]
Disable,
}
impl_node_content! {
pub type PreprocessorExtensionBehavior = Node<PreprocessorExtensionBehaviorData>;
}
#[derive(Debug, Clone, PartialEq, Eq, NodeContentDisplay)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "serde", serde(crate = "rserde"))]
pub enum CommentData {
Single(String),
Multi(String),
}
impl_node_content! {
pub type Comment = Node<CommentData>;
}
impl CommentData {
pub fn text(&self) -> &str {
match self {
Self::Single(s) => s,
Self::Multi(s) => s,
}
}
pub fn is_single(&self) -> bool {
matches!(self, Self::Multi(_))
}
pub fn is_multi(&self) -> bool {
matches!(self, Self::Multi(_))
}
}