feat: implement documentation comments
Add support for doc comments (/// syntax) that can be attached to declarations for documentation purposes. The implementation: - Adds DocComment token kind to lexer - Recognizes /// as doc comment syntax (distinct from // regular comments) - Parses consecutive doc comments and combines them into a single string - Adds doc field to FunctionDecl, TypeDecl, LetDecl, EffectDecl, TraitDecl - Passes doc comments through parser to declarations - Multiple consecutive doc comment lines are joined with newlines This enables documentation extraction and could be used for generating API docs, IDE hover information, and REPL help. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
10
src/ast.rs
10
src/ast.rs
@@ -227,6 +227,8 @@ pub enum Declaration {
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct FunctionDecl {
|
||||
pub visibility: Visibility,
|
||||
/// Documentation comment (from /// doc comments)
|
||||
pub doc: Option<String>,
|
||||
pub name: Ident,
|
||||
pub type_params: Vec<Ident>,
|
||||
pub params: Vec<Parameter>,
|
||||
@@ -251,6 +253,8 @@ pub struct Parameter {
|
||||
/// Effect declaration
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct EffectDecl {
|
||||
/// Documentation comment
|
||||
pub doc: Option<String>,
|
||||
pub name: Ident,
|
||||
pub type_params: Vec<Ident>,
|
||||
pub operations: Vec<EffectOp>,
|
||||
@@ -270,6 +274,8 @@ pub struct EffectOp {
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct TypeDecl {
|
||||
pub visibility: Visibility,
|
||||
/// Documentation comment
|
||||
pub doc: Option<String>,
|
||||
pub name: Ident,
|
||||
pub type_params: Vec<Ident>,
|
||||
/// Optional version annotation: type User @v2 { ... }
|
||||
@@ -342,6 +348,8 @@ pub struct HandlerImpl {
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct LetDecl {
|
||||
pub visibility: Visibility,
|
||||
/// Documentation comment
|
||||
pub doc: Option<String>,
|
||||
pub name: Ident,
|
||||
pub typ: Option<TypeExpr>,
|
||||
pub value: Expr,
|
||||
@@ -352,6 +360,8 @@ pub struct LetDecl {
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct TraitDecl {
|
||||
pub visibility: Visibility,
|
||||
/// Documentation comment
|
||||
pub doc: Option<String>,
|
||||
pub name: Ident,
|
||||
/// Type parameters: trait Functor<F> { ... }
|
||||
pub type_params: Vec<Ident>,
|
||||
|
||||
Reference in New Issue
Block a user