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:
37
src/main.rs
37
src/main.rs
@@ -1419,5 +1419,42 @@ c")"#;
|
||||
let result = eval(source);
|
||||
assert!(result.is_ok(), "Expected success with explicit effects but got: {:?}", result);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_doc_comments_on_function() {
|
||||
// Test that doc comments are parsed and attached to functions
|
||||
let source = r#"
|
||||
/// Adds two numbers together.
|
||||
/// Returns the sum.
|
||||
fn add(a: Int, b: Int): Int = a + b
|
||||
let result = add(1, 2)
|
||||
"#;
|
||||
assert_eq!(eval(source).unwrap(), "3");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_doc_comments_on_type() {
|
||||
// Test that doc comments are parsed and attached to types
|
||||
let source = r#"
|
||||
/// A point in 2D space.
|
||||
type Point { x: Int, y: Int }
|
||||
let p = { x: 1, y: 2 }
|
||||
let result = p.x + p.y
|
||||
"#;
|
||||
assert_eq!(eval(source).unwrap(), "3");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_doc_comments_multiline() {
|
||||
// Test that multiple doc comment lines are combined
|
||||
let source = r#"
|
||||
/// First line of documentation.
|
||||
/// Second line of documentation.
|
||||
/// Third line of documentation.
|
||||
fn documented(): Int = 42
|
||||
let result = documented()
|
||||
"#;
|
||||
assert_eq!(eval(source).unwrap(), "42");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user