Skip to content

Commit

Permalink
Add support for more declarations and access modifiers in Carbon lexer (
Browse files Browse the repository at this point in the history
  • Loading branch information
AmrDeveloper committed Mar 2, 2023
1 parent 12a4d51 commit 2a0503b
Show file tree
Hide file tree
Showing 3 changed files with 282 additions and 3 deletions.
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.

0 comments on commit 2a0503b

Please sign in to comment.