Add Cangjie lexer#3108
Open
cy6erGn0m wants to merge 1 commit into
Open
Conversation
Author
Implements an ExtendedRegexLexer for the Cangjie programming language
with 20+ states covering annotations, quotes, generics, strings, and
expressions.
Key features:
- Contextual keywords (abstract/open/sealed/override/redef/internal)
highlighted as keywords before declarations, as identifiers elsewhere
- Triple-quoted strings, string interpolation (${expr}), raw strings
- Macro quote expressions with $() interpolation
- Generic parameters <T>, inheritance with <: operator
- VArray with $ prefix on size, number literals with underscores
12 test files with golden output covering all major syntax categories.
0 Error tokens across 500 stdlib files.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


Summary
This PR adds a lexer for the Cangjie programming language, a modern general-purpose programming language developed by Huawei.
About Cangjie
Cangjie is a high-level, statically typed, multi-paradigm programming language featuring:
The language was first released in June 2024 and was open-sourced in July 2025. It supports multiple platforms including HarmonyOS, Linux, Windows, macOS, Android, and iOS.
Official resources:
Lexer Implementation
The lexer uses
ExtendedRegexLexerto handle complex syntax features like multi-hash raw strings. Key features covered:let/var/const), functionsstruct,class,interface,enum,extend,prop,typeif/else,while,for-in,do-while,match/case,try/catch/finallyi32,f64, etc.), hex/octal/binary, runes#"..."#,##"..."##, etc.), interpolation (${...})foreign func,unsafeblocks,CPointer<T>macro package,quote(...),$interpolation,@expand,@Tuple,@Tokens@Test,@Benchmark,@Override,@Deprecated,@Available, custom annotations with complex argumentsTechnical highlights
LexerContextto efficiently match closing delimiters (#"..."#,##"..."##,###"..."###, etc.) with O(n) complexity instead of O(n²) backtracking@Annotation[...]including operators, lambdas{ => }, match expressions, and nested brackets with proper balancingTesting
The lexer includes comprehensive test coverage: 12 example files covering all major language features
Manual testing: