Section 15A: Attributes & Comments
Goal: Implement approved attribute syntax changes and comment restrictions
Source:
docs/ori_lang/proposals/approved/
15A.1 Simplified Attribute Syntax
Proposal: proposals/approved/simplified-attributes-proposal.md
Change attribute syntax from #[name(...)] to #name(...). Attributes are now generalizable to all declarations.
// Before
#[derive(Eq, Clone)]
#[skip("reason")]
// After
#derive(Eq, Clone)
#skip("reason")
Key Design Decisions
- Generalized attributes: Any attribute can appear before any declaration
- Compiler validation: The compiler validates which attributes are valid for which declarations
- Positioning: Attributes must appear immediately before the declaration they modify
Implementation
-
Implement: Update lexer to emit
Hashtoken instead ofHashBracket- Rust Tests:
ori_lexer/src/lib.rs— attribute token tests - Ori Tests:
tests/spec/attributes/simplified_syntax.ori - LLVM Support: LLVM codegen for simplified attribute token
- LLVM Rust Tests:
ori_llvm/tests/attribute_tests.rs— simplified attribute token codegen - AOT Tests:
ori_llvm/tests/aot/— simplified attribute token end-to-end
- Rust Tests:
-
Implement: Update parser to parse
#name(...)syntax- Rust Tests:
ori_parse/src/grammar/attr.rs— simplified attribute parsing - Ori Tests:
tests/spec/attributes/simplified_syntax.ori - LLVM Support: LLVM codegen for simplified attribute parsing
- LLVM Rust Tests:
ori_llvm/tests/attribute_tests.rs— simplified attribute parsing codegen - AOT Tests:
ori_llvm/tests/aot/— simplified attribute parsing end-to-end
- Rust Tests:
-
Implement: Generalize attributes to all declarations (functions, types, traits, impls, tests, constants)
- Rust Tests:
ori_parse/src/grammar/decl.rs— generalized attribute parsing - Ori Tests:
tests/spec/attributes/any_declaration.ori - LLVM Support: LLVM codegen for generalized attributes
- LLVM Rust Tests:
ori_llvm/tests/attribute_tests.rs— generalized attribute codegen - AOT Tests:
ori_llvm/tests/aot/— generalized attribute end-to-end
- Rust Tests:
-
Implement: Attribute validation (which attributes valid for which declarations)
- Rust Tests:
ori_types/src/check/attr.rs— attribute validation - Ori Tests:
tests/compile-fail/invalid_attribute_target.ori - LLVM Support: LLVM codegen for attribute validation
- LLVM Rust Tests:
ori_llvm/tests/attribute_tests.rs— attribute validation codegen
- Rust Tests:
-
Implement: Support migration: accept both syntaxes temporarily
- Rust Tests:
ori_parse/src/grammar/attr.rs— migration compatibility - Ori Tests:
tests/spec/attributes/migration.ori - LLVM Support: LLVM codegen for attribute migration compatibility
- LLVM Rust Tests:
ori_llvm/tests/attribute_tests.rs— attribute migration codegen - AOT Tests:
ori_llvm/tests/aot/— attribute migration end-to-end
- Rust Tests:
-
Implement: Add deprecation warning for bracket syntax
- LLVM Support: LLVM codegen for deprecation warning
- LLVM Rust Tests:
ori_llvm/tests/attribute_tests.rs— deprecation warning codegen
-
Implement: Update
ori fmtto auto-migrate- LLVM Support: LLVM codegen for ori fmt auto-migrate
- LLVM Rust Tests:
ori_llvm/tests/attribute_tests.rs— ori fmt auto-migrate codegen
15A.2 function_seq vs function_exp Formalization
Proposal: proposals/approved/function-seq-exp-distinction.md
Formalize the distinction between sequential patterns and named-expression patterns.
function_seq (special syntax): run, try, match, catch
function_exp (named args): recurse, parallel, spawn, timeout, cache, with, for
function_val (positional): — REMOVED by int, float, str, byteas proposal
NOTE: The
asconversion proposal (proposals/approved/as-conversion-proposal.md) removesfunction_valentirely. Type conversions now usex as T/x as? Tsyntax, eliminating the special case for positional arguments.
Implementation
-
Implement: Verify AST has separate
FunctionSeqandFunctionExptypes- Rust Tests:
ori_ir/src/ast/expr.rs— AST variant tests - Ori Tests:
tests/spec/patterns/function_seq_exp.ori - LLVM Support: LLVM codegen for FunctionSeq and FunctionExp
- LLVM Rust Tests:
ori_llvm/tests/syntax_tests.rs— FunctionSeq/FunctionExp codegen - AOT Tests:
ori_llvm/tests/aot/— FunctionSeq/FunctionExp end-to-end
- Rust Tests:
-
Implement: Parser allows positional for type conversions only
- Rust Tests:
ori_parse/src/grammar/call.rs— positional arg handling - Ori Tests:
tests/spec/expressions/type_conversions.ori - LLVM Support: LLVM codegen for positional type conversions
- LLVM Rust Tests:
ori_llvm/tests/syntax_tests.rs— positional type conversions codegen - AOT Tests:
ori_llvm/tests/aot/— positional type conversions end-to-end
- Rust Tests:
-
Implement: Parser enforces named args for all other builtins
- Rust Tests:
ori_parse/src/grammar/call.rs— named arg enforcement - Ori Tests:
tests/spec/expressions/builtin_named_args.ori - LLVM Support: LLVM codegen for named arg enforcement
- LLVM Rust Tests:
ori_llvm/tests/syntax_tests.rs— named arg enforcement codegen - AOT Tests:
ori_llvm/tests/aot/— named arg enforcement end-to-end
- Rust Tests:
-
Implement: Add clear error message for positional args in builtins
- Rust Tests:
ori_diagnostic/src/problem.rs— positional arg error - Ori Tests:
tests/compile-fail/builtin_positional_args.ori - LLVM Support: LLVM codegen for positional arg error
- LLVM Rust Tests:
ori_llvm/tests/syntax_tests.rs— positional arg error codegen
- Rust Tests:
15A.3 Inline Comments Prohibition
Comments must appear on their own line. Inline comments are not allowed.
// This is valid
let x = 42
let y = 42 // SYNTAX ERROR
Implementation
-
Implement: Update lexer to reject inline comments
- Rust Tests:
ori_lexer/src/lib.rs— inline comment rejection - Ori Tests:
tests/compile-fail/inline_comments.ori - LLVM Support: LLVM codegen for inline comment rejection
- LLVM Rust Tests:
ori_llvm/tests/syntax_tests.rs— inline comment rejection codegen
- Rust Tests:
-
Implement: Add clear error message for inline comments
- LLVM Support: LLVM codegen for inline comment error message
- LLVM Rust Tests:
ori_llvm/tests/syntax_tests.rs— inline comment error codegen
15A.4 Simplified Doc Comment Syntax
Proposal: proposals/approved/simplified-doc-comments-proposal.md
Simplify doc comment syntax by removing verbose markers:
// Before
// #Computes the sum.
// @param a The first operand.
// @param b The second operand.
// After
// Computes the sum.
// * a: The first operand.
// * b: The second operand.
Key Design Decisions
- Remove
#marker for descriptions — Unmarked comments before declarations are descriptions - Replace
@param/@fieldwith*— Markdown-like list syntax, context determines meaning - Canonical spacing —
// * name: descriptionwith space after*, colon always required - Non-doc comment separation — Blank line separates non-doc comments from declarations
Implementation
-
Implement: Update
CommentKindenum- Replace
DocParam,DocFieldwith unifiedDocMember - Remove
DocDescriptiondetection from lexer (moved to formatter) - Rust Tests:
ori_ir/src/comment.rs— enum variant tests - Ori Tests:
tests/spec/comments/doc_markers.ori
- Replace
-
Implement: Update lexer comment classification
- Recognize
*as member doc marker - Remove
#,@param,@fieldrecognition - Rust Tests:
ori_lexer/src/lib.rs— comment classification tests - Ori Tests:
tests/spec/comments/classification.ori
- Recognize
-
Implement: Update formatter doc comment reordering
- Update
extract_member_nameto parse* name:syntax - Move description detection to formatter (check preceding declaration)
- Rust Tests:
ori_fmt/src/comments.rs— reordering tests - Ori Tests:
tests/fmt/comments/reordering.ori
- Update
-
Implement: Support migration from old syntax
- Lexer recognizes both old and new formats during transition
-
ori fmtconverts old to new automatically - Add deprecation warning for old format
- Ori Tests:
tests/spec/comments/migration.ori
-
Implement: LLVM backend support
- LLVM Rust Tests:
ori_llvm/tests/comment_tests.rs
- LLVM Rust Tests:
15A.5 Section Completion Checklist
- All implementation items have checkboxes marked
[ ] - All spec docs updated
- CLAUDE.md updated with syntax changes
- Migration tools working
- All tests pass:
./test-all.sh
Exit Criteria: Attribute syntax, comment rules, and doc comment syntax implemented