From 826dc600e8458a2a65c712492c48ec30a19fce2c Mon Sep 17 00:00:00 2001 From: Amr Hesham Date: Thu, 2 Mar 2023 21:24:29 +0200 Subject: Add support for impl and constraint declaration in Carbon lexer (#2368) --- pygments/lexers/carbon.py | 2 +- tests/examplefiles/carbon/declarations.carbon | 9 ++++- .../examplefiles/carbon/declarations.carbon.output | 44 ++++++++++++++++++++++ 3 files changed, 53 insertions(+), 2 deletions(-) diff --git a/pygments/lexers/carbon.py b/pygments/lexers/carbon.py index bb1cb36d..07cf75dd 100644 --- a/pygments/lexers/carbon.py +++ b/pygments/lexers/carbon.py @@ -41,7 +41,7 @@ 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|choice)\b', Keyword.Declaration), + r'base|addr|extends|choice|constraint|impl)\b', Keyword.Declaration), # Keywords (words(('as', 'or', 'not', 'and', 'break', 'continue', 'case', 'default', 'if', 'else', 'destructor', 'for', 'forall', diff --git a/tests/examplefiles/carbon/declarations.carbon b/tests/examplefiles/carbon/declarations.carbon index 4f61d307..bcb9e05b 100644 --- a/tests/examplefiles/carbon/declarations.carbon +++ b/tests/examplefiles/carbon/declarations.carbon @@ -27,4 +27,11 @@ class Pal { abstract class MyAbstractClass { protected fn Create() -> partial Self { } -} \ No newline at end of file +} + +constraint DrawVectorLegoFish { + impl as VectorLegoFish; + impl as Drawable; +} + +impl JustX as X {} \ No newline at end of file diff --git a/tests/examplefiles/carbon/declarations.carbon.output b/tests/examplefiles/carbon/declarations.carbon.output index b1db4d97..48b1362f 100644 --- a/tests/examplefiles/carbon/declarations.carbon.output +++ b/tests/examplefiles/carbon/declarations.carbon.output @@ -242,3 +242,47 @@ '}' Punctuation '\n' Text.Whitespace + +'\n' Text.Whitespace + +'constraint' Keyword.Declaration +' ' Text.Whitespace +'DrawVectorLegoFish' Name.Other +' ' Text.Whitespace +'{' Punctuation +'\n' Text.Whitespace + +' ' Text.Whitespace +'impl' Keyword.Declaration +' ' Text.Whitespace +'as' Keyword +' ' Text.Whitespace +'VectorLegoFish' Name.Other +';' Punctuation +'\n' Text.Whitespace + +' ' Text.Whitespace +'impl' Keyword.Declaration +' ' Text.Whitespace +'as' Keyword +' ' Text.Whitespace +'Drawable' Name.Other +';' Punctuation +'\n' Text.Whitespace + +'}' Punctuation +'\n' Text.Whitespace + +'\n' Text.Whitespace + +'impl' Keyword.Declaration +' ' Text.Whitespace +'JustX' Name.Other +' ' Text.Whitespace +'as' Keyword +' ' Text.Whitespace +'X' Name.Other +' ' Text.Whitespace +'{' Punctuation +'}' Punctuation +'\n' Text.Whitespace -- cgit v1.2.1