cl-ast: Add doc comments for every node
This improves the rustdoc output somewhat
This commit is contained in:
parent
4a52d2bc6a
commit
a036ce260d
@ -17,6 +17,7 @@ use cl_structures::span::*;
|
|||||||
pub mod ast_impl;
|
pub mod ast_impl;
|
||||||
pub mod format;
|
pub mod format;
|
||||||
|
|
||||||
|
/// Whether a binding ([Static] or [Let]) or reference is mutable or not
|
||||||
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
|
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
|
||||||
pub enum Mutability {
|
pub enum Mutability {
|
||||||
#[default]
|
#[default]
|
||||||
@ -24,6 +25,7 @@ pub enum Mutability {
|
|||||||
Mut,
|
Mut,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Whether an [Item] is visible outside of the current [Module]
|
||||||
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
|
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
|
||||||
pub enum Visibility {
|
pub enum Visibility {
|
||||||
#[default]
|
#[default]
|
||||||
@ -31,6 +33,7 @@ pub enum Visibility {
|
|||||||
Public,
|
Public,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// A list of [Item]s
|
||||||
#[derive(Clone, Debug, Default, PartialEq, Eq)]
|
#[derive(Clone, Debug, Default, PartialEq, Eq)]
|
||||||
pub struct File {
|
pub struct File {
|
||||||
pub items: Vec<Item>,
|
pub items: Vec<Item>,
|
||||||
@ -42,12 +45,14 @@ pub struct Attrs {
|
|||||||
pub meta: Vec<Meta>,
|
pub meta: Vec<Meta>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// A metadata decorator
|
||||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||||
pub struct Meta {
|
pub struct Meta {
|
||||||
pub name: Identifier,
|
pub name: Identifier,
|
||||||
pub kind: MetaKind,
|
pub kind: MetaKind,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Information attached to [Meta]data
|
||||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||||
pub enum MetaKind {
|
pub enum MetaKind {
|
||||||
Plain,
|
Plain,
|
||||||
@ -56,7 +61,7 @@ pub enum MetaKind {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Items
|
// Items
|
||||||
/// Stores an [ItemKind] and associated metadata
|
/// Anything that can appear at the top level of a [File]
|
||||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||||
pub struct Item {
|
pub struct Item {
|
||||||
pub extents: Span,
|
pub extents: Span,
|
||||||
@ -65,36 +70,37 @@ pub struct Item {
|
|||||||
pub kind: ItemKind,
|
pub kind: ItemKind,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Stores a concrete Item
|
/// What kind of [Item] is this?
|
||||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||||
pub enum ItemKind {
|
pub enum ItemKind {
|
||||||
// TODO: Import declaration ("use") item
|
// TODO: Import declaration ("use") item
|
||||||
// TODO: Trait declaration ("trait") item?
|
// TODO: Trait declaration ("trait") item?
|
||||||
|
/// A [module](Module)
|
||||||
|
Module(Module),
|
||||||
/// A [type alias](Alias)
|
/// A [type alias](Alias)
|
||||||
Alias(Alias),
|
Alias(Alias),
|
||||||
|
/// An [enumerated type](Enum), with a discriminant and optional data
|
||||||
|
Enum(Enum),
|
||||||
|
/// A [structure](Struct)
|
||||||
|
Struct(Struct),
|
||||||
/// A [constant](Const)
|
/// A [constant](Const)
|
||||||
Const(Const),
|
Const(Const),
|
||||||
/// A [static](Static) variable
|
/// A [static](Static) variable
|
||||||
Static(Static),
|
Static(Static),
|
||||||
/// A [module](Module)
|
|
||||||
Module(Module),
|
|
||||||
/// A [function definition](Function)
|
/// A [function definition](Function)
|
||||||
Function(Function),
|
Function(Function),
|
||||||
/// A [structure](Struct)
|
|
||||||
Struct(Struct),
|
|
||||||
/// An [enumerated type](Enum)
|
|
||||||
Enum(Enum),
|
|
||||||
/// An [implementation](Impl)
|
/// An [implementation](Impl)
|
||||||
Impl(Impl),
|
Impl(Impl),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// An alias to another [Ty]
|
||||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||||
pub struct Alias {
|
pub struct Alias {
|
||||||
pub to: Identifier,
|
pub to: Identifier,
|
||||||
pub from: Option<Box<Ty>>,
|
pub from: Option<Box<Ty>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Stores a `const` value
|
/// A compile-time constant
|
||||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||||
pub struct Const {
|
pub struct Const {
|
||||||
pub name: Identifier,
|
pub name: Identifier,
|
||||||
@ -102,7 +108,7 @@ pub struct Const {
|
|||||||
pub init: Box<Expr>,
|
pub init: Box<Expr>,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Stores a `static` variable
|
/// A `static` variable
|
||||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||||
pub struct Static {
|
pub struct Static {
|
||||||
pub mutable: Mutability,
|
pub mutable: Mutability,
|
||||||
@ -111,20 +117,21 @@ pub struct Static {
|
|||||||
pub init: Box<Expr>,
|
pub init: Box<Expr>,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Stores a collection of [Items](Item)
|
/// An ordered collection of [Items](Item)
|
||||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||||
pub struct Module {
|
pub struct Module {
|
||||||
pub name: Identifier,
|
pub name: Identifier,
|
||||||
pub kind: ModuleKind,
|
pub kind: ModuleKind,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// The contents of a [Module], if they're in the same file
|
||||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||||
pub enum ModuleKind {
|
pub enum ModuleKind {
|
||||||
Inline(File),
|
Inline(File),
|
||||||
Outline,
|
Outline,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Contains code, and the interface to that code
|
/// Code, and the interface to that code
|
||||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||||
pub struct Function {
|
pub struct Function {
|
||||||
pub name: Identifier,
|
pub name: Identifier,
|
||||||
@ -133,6 +140,7 @@ pub struct Function {
|
|||||||
pub rety: Option<Box<Ty>>,
|
pub rety: Option<Box<Ty>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// A single parameter for a [Function]
|
||||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||||
pub struct Param {
|
pub struct Param {
|
||||||
pub mutability: Mutability,
|
pub mutability: Mutability,
|
||||||
@ -140,12 +148,14 @@ pub struct Param {
|
|||||||
pub ty: Box<Ty>,
|
pub ty: Box<Ty>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// A user-defined product type
|
||||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||||
pub struct Struct {
|
pub struct Struct {
|
||||||
pub name: Identifier,
|
pub name: Identifier,
|
||||||
pub kind: StructKind,
|
pub kind: StructKind,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Either a [Struct]'s [StructMember]s or tuple [Ty]pes, if present.
|
||||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||||
pub enum StructKind {
|
pub enum StructKind {
|
||||||
Empty,
|
Empty,
|
||||||
@ -153,6 +163,7 @@ pub enum StructKind {
|
|||||||
Struct(Vec<StructMember>),
|
Struct(Vec<StructMember>),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// The [Visibility], [Identifier], and [Ty]pe of a single [Struct] member
|
||||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||||
pub struct StructMember {
|
pub struct StructMember {
|
||||||
pub vis: Visibility,
|
pub vis: Visibility,
|
||||||
@ -160,12 +171,14 @@ pub struct StructMember {
|
|||||||
pub ty: Ty,
|
pub ty: Ty,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// A user-defined sum type
|
||||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||||
pub struct Enum {
|
pub struct Enum {
|
||||||
pub name: Identifier,
|
pub name: Identifier,
|
||||||
pub kind: EnumKind,
|
pub kind: EnumKind,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// An [Enum]'s [Variant]s, if it has a variant block
|
||||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||||
pub enum EnumKind {
|
pub enum EnumKind {
|
||||||
/// Represents an enum with no variants
|
/// Represents an enum with no variants
|
||||||
@ -173,12 +186,14 @@ pub enum EnumKind {
|
|||||||
Variants(Vec<Variant>),
|
Variants(Vec<Variant>),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// A single [Enum] variant
|
||||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||||
pub struct Variant {
|
pub struct Variant {
|
||||||
pub name: Identifier,
|
pub name: Identifier,
|
||||||
pub kind: VariantKind,
|
pub kind: VariantKind,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Whether the [Variant] has a C-like constant value, a tuple, or [StructMember]s
|
||||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||||
pub enum VariantKind {
|
pub enum VariantKind {
|
||||||
Plain,
|
Plain,
|
||||||
@ -187,6 +202,7 @@ pub enum VariantKind {
|
|||||||
Struct(Vec<StructMember>),
|
Struct(Vec<StructMember>),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Sub-[items](Item) (associated functions, etc.) for a [Ty]
|
||||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||||
pub struct Impl {
|
pub struct Impl {
|
||||||
pub target: Ty,
|
pub target: Ty,
|
||||||
@ -200,13 +216,14 @@ pub enum ImplKind {
|
|||||||
Trait { impl_trait: Path, for_type: Box<Ty> },
|
Trait { impl_trait: Path, for_type: Box<Ty> },
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # Static Type Information
|
/// A type expression
|
||||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||||
pub struct Ty {
|
pub struct Ty {
|
||||||
pub extents: Span,
|
pub extents: Span,
|
||||||
pub kind: TyKind,
|
pub kind: TyKind,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Information about a [Ty]pe expression
|
||||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||||
pub enum TyKind {
|
pub enum TyKind {
|
||||||
Never,
|
Never,
|
||||||
@ -218,29 +235,34 @@ pub enum TyKind {
|
|||||||
Fn(TyFn),
|
Fn(TyFn),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// A tuple of [Ty]pes
|
||||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||||
pub struct TyTuple {
|
pub struct TyTuple {
|
||||||
pub types: Vec<Ty>,
|
pub types: Vec<Ty>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// A [Ty]pe-reference expression as (number of `&`, [Path])
|
||||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||||
pub struct TyRef {
|
pub struct TyRef {
|
||||||
pub count: u16,
|
pub count: u16,
|
||||||
pub to: Path,
|
pub to: Path,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// The args and return value for a function pointer [Ty]pe
|
||||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||||
pub struct TyFn {
|
pub struct TyFn {
|
||||||
pub args: TyTuple,
|
pub args: TyTuple,
|
||||||
pub rety: Option<Box<Ty>>,
|
pub rety: Option<Box<Ty>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Path
|
/// A path to an [Item] in the [Module] tree
|
||||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||||
pub struct Path {
|
pub struct Path {
|
||||||
pub absolute: bool,
|
pub absolute: bool,
|
||||||
pub parts: Vec<PathPart>,
|
pub parts: Vec<PathPart>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// A single component of a [Path]
|
||||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||||
pub enum PathPart {
|
pub enum PathPart {
|
||||||
SuperKw,
|
SuperKw,
|
||||||
@ -249,10 +271,11 @@ pub enum PathPart {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Capture token?
|
// TODO: Capture token?
|
||||||
|
/// A name
|
||||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||||
pub struct Identifier(pub String);
|
pub struct Identifier(pub String);
|
||||||
|
|
||||||
/// Stores an abstract statement, and associated metadata
|
/// An abstract statement, and associated metadata
|
||||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||||
pub struct Stmt {
|
pub struct Stmt {
|
||||||
pub extents: Span,
|
pub extents: Span,
|
||||||
@ -260,12 +283,14 @@ pub struct Stmt {
|
|||||||
pub semi: Semi,
|
pub semi: Semi,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Whether or not a [Stmt] is followed by a semicolon
|
||||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||||
pub enum Semi {
|
pub enum Semi {
|
||||||
Terminated,
|
Terminated,
|
||||||
Unterminated,
|
Unterminated,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Whether the [Stmt] is a [Let], [Item], or [Expr] statement
|
||||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||||
pub enum StmtKind {
|
pub enum StmtKind {
|
||||||
Empty,
|
Empty,
|
||||||
@ -274,6 +299,7 @@ pub enum StmtKind {
|
|||||||
Expr(Box<Expr>),
|
Expr(Box<Expr>),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// A local variable declaration [Stmt]
|
||||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||||
pub struct Let {
|
pub struct Let {
|
||||||
pub mutable: Mutability,
|
pub mutable: Mutability,
|
||||||
@ -282,13 +308,14 @@ pub struct Let {
|
|||||||
pub init: Option<Box<Expr>>,
|
pub init: Option<Box<Expr>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Stores an abstract expression, and associated metadata
|
/// An expression, the beating heart of the language
|
||||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||||
pub struct Expr {
|
pub struct Expr {
|
||||||
pub extents: Span,
|
pub extents: Span,
|
||||||
pub kind: ExprKind,
|
pub kind: ExprKind,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Any of the different [Expr]essions
|
||||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||||
pub enum ExprKind {
|
pub enum ExprKind {
|
||||||
/// An [Assign]ment expression: [`Expr`] ([`AssignKind`] [`Expr`])\+
|
/// An [Assign]ment expression: [`Expr`] ([`AssignKind`] [`Expr`])\+
|
||||||
@ -336,6 +363,7 @@ pub enum ExprKind {
|
|||||||
Continue(Continue),
|
Continue(Continue),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// An [Assign]ment expression: [`Expr`] ([`AssignKind`] [`Expr`])\+
|
||||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||||
pub struct Assign {
|
pub struct Assign {
|
||||||
pub head: Box<Expr>,
|
pub head: Box<Expr>,
|
||||||
@ -359,12 +387,14 @@ pub enum AssignKind {
|
|||||||
Rem,
|
Rem,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// A [Binary] expression: [`Expr`] ([`BinaryKind`] [`Expr`])\+
|
||||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||||
pub struct Binary {
|
pub struct Binary {
|
||||||
pub head: Box<Expr>,
|
pub head: Box<Expr>,
|
||||||
pub tail: Vec<(BinaryKind, Expr)>,
|
pub tail: Vec<(BinaryKind, Expr)>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// A [Binary] operator
|
||||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||||
pub enum BinaryKind {
|
pub enum BinaryKind {
|
||||||
Lt,
|
Lt,
|
||||||
@ -391,12 +421,14 @@ pub enum BinaryKind {
|
|||||||
Dot,
|
Dot,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// A [Unary] expression: [`UnaryKind`]\* [`Expr`]
|
||||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||||
pub struct Unary {
|
pub struct Unary {
|
||||||
pub ops: Vec<UnaryKind>,
|
pub ops: Vec<UnaryKind>,
|
||||||
pub tail: Box<Expr>,
|
pub tail: Box<Expr>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// A [Unary] operator
|
||||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||||
pub enum UnaryKind {
|
pub enum UnaryKind {
|
||||||
Deref,
|
Deref,
|
||||||
@ -408,6 +440,7 @@ pub enum UnaryKind {
|
|||||||
Tilde,
|
Tilde,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// A [Member] access expression: [`Expr`] (`.` [`Expr`])+
|
||||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||||
pub struct Member {
|
pub struct Member {
|
||||||
pub head: Box<Expr>,
|
pub head: Box<Expr>,
|
||||||
@ -419,24 +452,27 @@ pub enum MemberKind {
|
|||||||
Dot,
|
Dot,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// A [Call] expression, with arguments: a(foo, bar)
|
||||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||||
pub struct Call {
|
pub struct Call {
|
||||||
pub callee: Box<Expr>,
|
pub callee: Box<Expr>,
|
||||||
pub args: Vec<Tuple>,
|
pub args: Vec<Tuple>,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Index operator: Member (`[` Expr `]`)*
|
/// A repeated [Index] expression: a[10, 20, 30][40, 50, 60]
|
||||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||||
pub struct Index {
|
pub struct Index {
|
||||||
pub head: Box<Expr>,
|
pub head: Box<Expr>,
|
||||||
pub indices: Vec<Indices>,
|
pub indices: Vec<Indices>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// A single [Index] expression: a[10, 20, 30]
|
||||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||||
pub struct Indices {
|
pub struct Indices {
|
||||||
pub exprs: Vec<Expr>,
|
pub exprs: Vec<Expr>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// A [Literal]: 0x42, 1e123, 2.4, "Hello"
|
||||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||||
pub enum Literal {
|
pub enum Literal {
|
||||||
Bool(bool),
|
Bool(bool),
|
||||||
@ -445,17 +481,21 @@ pub enum Literal {
|
|||||||
String(String),
|
String(String),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// An [Array] literal: `[` [`Expr`] (`,` [`Expr`])\* `]`
|
||||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||||
pub struct Array {
|
pub struct Array {
|
||||||
pub values: Vec<Expr>,
|
pub values: Vec<Expr>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// An Array literal constructed with [repeat syntax](ArrayRep)
|
||||||
|
/// `[` [Expr] `;` [Literal] `]`
|
||||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||||
pub struct ArrayRep {
|
pub struct ArrayRep {
|
||||||
pub value: Box<Expr>,
|
pub value: Box<Expr>,
|
||||||
pub repeat: Box<Expr>,
|
pub repeat: Box<Expr>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// An address-of expression: `&` `mut`? [`Expr`]
|
||||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||||
pub struct AddrOf {
|
pub struct AddrOf {
|
||||||
pub count: usize,
|
pub count: usize,
|
||||||
@ -463,21 +503,25 @@ pub struct AddrOf {
|
|||||||
pub expr: Box<Expr>,
|
pub expr: Box<Expr>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// A [Block] expression: `{` [`Stmt`]\* [`Expr`]? `}`
|
||||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||||
pub struct Block {
|
pub struct Block {
|
||||||
pub stmts: Vec<Stmt>,
|
pub stmts: Vec<Stmt>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// A [Grouping](Group) expression `(` [`Expr`] `)`
|
||||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||||
pub struct Group {
|
pub struct Group {
|
||||||
pub expr: Box<Expr>,
|
pub expr: Box<Expr>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// A [Tuple] expression: `(` [`Expr`] (`,` [`Expr`])+ `)`
|
||||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||||
pub struct Tuple {
|
pub struct Tuple {
|
||||||
pub exprs: Vec<Expr>,
|
pub exprs: Vec<Expr>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// A [While] expression: `while` [`Expr`] [`Block`] [`Else`]?
|
||||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||||
pub struct While {
|
pub struct While {
|
||||||
pub cond: Box<Expr>,
|
pub cond: Box<Expr>,
|
||||||
@ -485,6 +529,7 @@ pub struct While {
|
|||||||
pub fail: Else,
|
pub fail: Else,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// An [If] expression: `if` [`Expr`] [`Block`] [`Else`]?
|
||||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||||
pub struct If {
|
pub struct If {
|
||||||
pub cond: Box<Expr>,
|
pub cond: Box<Expr>,
|
||||||
@ -492,6 +537,7 @@ pub struct If {
|
|||||||
pub fail: Else,
|
pub fail: Else,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// A [For] expression: `for` Pattern `in` [`Expr`] [`Block`] [`Else`]?
|
||||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||||
pub struct For {
|
pub struct For {
|
||||||
pub bind: Identifier, // TODO: Patterns?
|
pub bind: Identifier, // TODO: Patterns?
|
||||||
@ -500,20 +546,24 @@ pub struct For {
|
|||||||
pub fail: Else,
|
pub fail: Else,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// The (optional) `else` clause of a [While], [If], or [For] expression
|
||||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||||
pub struct Else {
|
pub struct Else {
|
||||||
pub body: Option<Box<Expr>>,
|
pub body: Option<Box<Expr>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// A [Break] expression: `break` [`Expr`]?
|
||||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||||
pub struct Break {
|
pub struct Break {
|
||||||
pub body: Option<Box<Expr>>,
|
pub body: Option<Box<Expr>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// A [Return] expression `return` [`Expr`]?
|
||||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||||
pub struct Return {
|
pub struct Return {
|
||||||
pub body: Option<Box<Expr>>,
|
pub body: Option<Box<Expr>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// A continue expression: `continue`
|
||||||
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
|
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
|
||||||
pub struct Continue;
|
pub struct Continue;
|
||||||
|
Loading…
Reference in New Issue
Block a user