ystyle/cangjie-lang-skill
Overview
This skill is an expert assistant for generating, reviewing, and analyzing Cangjie (.cj) language code. It provides idiomatic code generation, syntax validation, common-error checks, and targeted refactor suggestions based on Cangjie language rules. Use it to speed development, enforce style, and avoid the language's common pitfalls.
How this skill works
I inspect source snippets or specifications and produce Cangjie-compliant code, explanations, or diagnostics. Analysis covers variable declarations, types (Rune, String, numeric), pattern matching, functions, enums, classes, Option usages, control flow, and unit test structure. I flag 19 common error patterns, suggest fixes, and produce minimal reproducible examples or templates on request.
When to use it
- You need idiomatic Cangjie code samples or templates (functions, classes, enums, unit tests).
- You want automated checks for common language pitfalls (bracketed if, let vs var, raw string rules).
- You are converting requirements or pseudocode into working .cj source files.
- You want a code review focused on Cangjie-specific semantics (pattern guards, Option short-circuiting).
- You need help writing concise unit tests or test cases using @Test/@TestCase annotations.
Best practices
- Always include parentheses for if and while conditions—omitting them is a common error.
- Use let for immutable bindings and var for mutable state; avoid shadowing let in the same scope.
- Prefer pattern matching and Option short-circuit operators (??, ?? return/throw) for safe value handling.
- Use raw multi-line strings when you need to preserve exact layout, but remember they do not support interpolation or escapes.
- Keep function parameters immutable; create local vars if you need to mutate values.
Example use cases
- Generate a main() program that reads values, uses Option<T>, and demonstrates ?? short-circuit return.
- Refactor a function to replace nested if-else with match and pattern guards using where clauses.
- Create an enum-based state machine and matching handlers with nested tuple and enum patterns.
- Write unit tests for a lexer or parser using @Test and @TestCase with Assert/Expect assertions.
- Analyze a class definition for incorrect visibility, static usage, or improper constructor/init patterns.
FAQ
No. Multi-line raw strings do not support interpolation or escape sequences; use single/double quoted or normal multi-line strings for interpolation.
Can function parameters be declared as var or let explicitly?
No. Function parameters are implicitly immutable (like let). To change a parameter, assign it to a local var inside the function.