Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for more declarations and access modifiers in Carbon lexer #2366

Merged
merged 1 commit into from
Mar 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 4 additions & 3 deletions pygments/lexers/carbon.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,13 @@ class CarbonLexer(RegexLexer):
# Declaration
(r'(package|import|api|namespace|library)\b', Keyword.Namespace),
(r'(abstract|alias|fn|class|interface|let|var|virtual|external|'
r'base|addr|extends)\b', Keyword.Declaration),
r'base|addr|extends|choice)\b', Keyword.Declaration),
# Keywords
(words(('as', 'or', 'not', 'and', 'break', 'continue', 'case',
'default', 'if', 'else', 'destructor', 'for', 'forall',
'while', 'where', 'then', 'in', 'is', 'return',
'returned'), suffix=r'\b'), Keyword),
'while', 'where', 'then', 'in', 'is', 'return', 'returned',
'friend', 'partial', 'private', 'protected', 'observe',
'override', 'Self'), suffix=r'\b'), Keyword),
(r'(self)\b', Keyword.Pseudo),
(r'(true|false)\b', Keyword.Constant),
(r'(auto|bool|string|i8|i16|i32|i64|u8|u16|u32|u64|'
Expand Down
30 changes: 30 additions & 0 deletions tests/examplefiles/carbon/declarations.carbon
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package ExplorerTest api;

choice MyOptionalElement(ZZ:! type, YY:! type) {
None(YY),
Element(ZZ)
}

abstract class C {
var a: i32;
}

base class B {
var value_b: i32;
}

interface Vector {
fn Zero() -> Self;
fn Add[self: Self](b: Self) -> Self;
fn Scale[self: Self](v: i32) -> Self;
}

class Pal {
private var x: i32;
protected var y: i32;
friend Buddy;
}

abstract class MyAbstractClass {
protected fn Create() -> partial Self { }
}
248 changes: 248 additions & 0 deletions tests/examplefiles/carbon/declarations.carbon.output

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.