From 8822854ba656e1fd1e83e8864fac3faa42ac4350 Mon Sep 17 00:00:00 2001 From: Marc Auberer Date: Fri, 12 Aug 2022 22:39:11 +0200 Subject: [PATCH 1/6] Cleanup --- pygments/lexers/spice.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/pygments/lexers/spice.py b/pygments/lexers/spice.py index c8269f318b..354a3491e8 100644 --- a/pygments/lexers/spice.py +++ b/pygments/lexers/spice.py @@ -48,17 +48,17 @@ class SpiceLexer(RegexLexer): (words(('double', 'int', 'short', 'long', 'byte', 'char', 'string', 'bool', 'dyn'), suffix=r'\b'), Keyword.Type), (words(('printf', 'sizeof', 'len', 'tid', 'join'), suffix=r'\b(\()'), bygroups(Name.Builtin, Punctuation)), # numeric literals - (r'([0-9]*[.][0-9]+)', Number.Double), - (r'((0[dD])?[0-9]+[sl]?)', Number.Integer), - (r'(0[bB][01]+[sl]?)', Number.Bin), - (r'(0[oO][0-7]+[sl]?)', Number.Oct), - (r'(0[xXhH][0-9a-fA-F]+[sl]?)', Number.Hex), + (r'(0[dD])?[0-9]+[sl]?', Number.Integer), + (r'[0-9]*.[0-9]+', Number.Double), + (r'0[bB][01]+[sl]?', Number.Bin), + (r'0[oO][0-7]+[sl]?', Number.Oct), + (r'0[xXhH][0-9a-fA-F]+[sl]?', Number.Hex), # string literal (r'"(\\\\|\\[^\\]|[^"\\])*"', String), # char literal (r'\'(\\\\|\\[^\\]|[^\'\\])\'', String.Char), # tokens - (r'(<<=|>>=|<<|>>|<=|>=|\+=|-=|\*=|/=|\%=|\|=|&=|\^=|&&|\|\||&|\||\+\+|--|\%|\^|\~|==|!=|[.]{3}|[+\-*/&])', Operator), + (r'<<=|>>=|<<|>>|<=|>=|\+=|-=|\*=|/=|\%=|\|=|&=|\^=|&&|\|\||&|\||\+\+|--|\%|\^|\~|==|!=|[.]{3}|[+\-*/&]', Operator), (r'[|<>=!()\[\]{}.,;:\?]', Punctuation), # identifiers (r'[^\W\d]\w*', Name.Other), From 17ce808eea660a541dd1c702629067f64a4b302a Mon Sep 17 00:00:00 2001 From: Marc Auberer Date: Tue, 23 Aug 2022 21:47:33 +0200 Subject: [PATCH 2/6] Add scope access operator --- pygments/lexers/spice.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pygments/lexers/spice.py b/pygments/lexers/spice.py index 354a3491e8..36a33e6b66 100644 --- a/pygments/lexers/spice.py +++ b/pygments/lexers/spice.py @@ -58,7 +58,7 @@ class SpiceLexer(RegexLexer): # char literal (r'\'(\\\\|\\[^\\]|[^\'\\])\'', String.Char), # tokens - (r'<<=|>>=|<<|>>|<=|>=|\+=|-=|\*=|/=|\%=|\|=|&=|\^=|&&|\|\||&|\||\+\+|--|\%|\^|\~|==|!=|[.]{3}|[+\-*/&]', Operator), + (r'<<=|>>=|<<|>>|<=|>=|\+=|-=|\*=|/=|\%=|\|=|&=|\^=|&&|\|\||&|\||\+\+|--|\%|\^|\~|==|!=|::|[.]{3}|[+\-*/&]', Operator), (r'[|<>=!()\[\]{}.,;:\?]', Punctuation), # identifiers (r'[^\W\d]\w*', Name.Other), From 11f664d7f9cfc52076f7ab190e8004400b50757b Mon Sep 17 00:00:00 2001 From: Marc Auberer Date: Fri, 9 Sep 2022 12:18:59 +0200 Subject: [PATCH 3/6] Add enum keyword --- pygments/lexers/spice.py | 4 ++-- tests/examplefiles/spice/example.spice | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/pygments/lexers/spice.py b/pygments/lexers/spice.py index 36a33e6b66..f28601d788 100644 --- a/pygments/lexers/spice.py +++ b/pygments/lexers/spice.py @@ -40,10 +40,10 @@ class SpiceLexer(RegexLexer): (r'/(\\\n)?[*](.|\n)*?[*](\\\n)?/', Comment.Multiline), # keywords (r'(import|as)\b', Keyword.Namespace), - (r'(f|p|type|struct)\b', Keyword.Declaration), + (r'(f|p|type|struct|enum)\b', Keyword.Declaration), (words(('if', 'else', 'for', 'foreach', 'while', 'break', 'continue', 'return', 'assert', 'thread', 'unsafe', 'ext', 'dll'), suffix=r'\b'), Keyword), (words(('const', 'signed', 'unsigned', 'inline', 'public'), suffix=r'\b'), Keyword.Pseudo), - (words(('new', 'switch', 'case', 'yield', 'stash', 'pick', 'sync'), suffix=r'\b'), Keyword.Reserved), + (words(('new', 'switch', 'case', 'yield', 'stash', 'pick', 'sync', 'class'), suffix=r'\b'), Keyword.Reserved), (r'(true|false|nil)\b', Keyword.Constant), (words(('double', 'int', 'short', 'long', 'byte', 'char', 'string', 'bool', 'dyn'), suffix=r'\b'), Keyword.Type), (words(('printf', 'sizeof', 'len', 'tid', 'join'), suffix=r'\b(\()'), bygroups(Name.Builtin, Punctuation)), diff --git a/tests/examplefiles/spice/example.spice b/tests/examplefiles/spice/example.spice index 699efdf252..18e5d9cc5c 100644 --- a/tests/examplefiles/spice/example.spice +++ b/tests/examplefiles/spice/example.spice @@ -1,3 +1,17 @@ +type BloodType enum { + A, + B = 3, + AB, + ZERO = 0 +} + +type Person struct { + string firstName + string lastName + unsigned int age + BloodType bloodType +} + // Function to compute fibonacci numbers recursively f fib(int n) { if n <= 2 { From c41638f1294586cc33d6e1da53e3d9db8dd01e0b Mon Sep 17 00:00:00 2001 From: Marc Auberer Date: Sat, 10 Sep 2022 18:41:03 +0200 Subject: [PATCH 4/6] Update test ref --- tests/examplefiles/spice/example.spice.output | 81 +++++++++++++++++++ 1 file changed, 81 insertions(+) diff --git a/tests/examplefiles/spice/example.spice.output b/tests/examplefiles/spice/example.spice.output index 3d75ef94c1..d01ff3522f 100644 --- a/tests/examplefiles/spice/example.spice.output +++ b/tests/examplefiles/spice/example.spice.output @@ -1,3 +1,84 @@ +'type' Keyword.Declaration +' ' Text.Whitespace +'BloodType' Name.Other +' ' Text.Whitespace +'enum' Keyword.Declaration +' ' Text.Whitespace +'{' Punctuation +'\n' Text.Whitespace + +' ' Text.Whitespace +'A' Name.Other +',' Punctuation +'\n' Text.Whitespace + +' ' Text.Whitespace +'B' Name.Other +' ' Text.Whitespace +'=' Punctuation +' ' Text.Whitespace +'3' Literal.Number.Integer +',' Punctuation +'\n' Text.Whitespace + +' ' Text.Whitespace +'AB' Name.Other +',' Punctuation +'\n' Text.Whitespace + +' ' Text.Whitespace +'ZERO' Name.Other +' ' Text.Whitespace +'=' Punctuation +' ' Text.Whitespace +'0' Literal.Number.Integer +'\n' Text.Whitespace + +'}' Punctuation +'\n' Text.Whitespace + +'\n' Text.Whitespace + +'type' Keyword.Declaration +' ' Text.Whitespace +'Person' Name.Other +' ' Text.Whitespace +'struct' Keyword.Declaration +' ' Text.Whitespace +'{' Punctuation +'\n' Text.Whitespace + +' ' Text.Whitespace +'string' Keyword.Type +' ' Text.Whitespace +'firstName' Name.Other +'\n' Text.Whitespace + +' ' Text.Whitespace +'string' Keyword.Type +' ' Text.Whitespace +'lastName' Name.Other +'\n' Text.Whitespace + +' ' Text.Whitespace +'unsigned' Keyword.Pseudo +' ' Text.Whitespace +'int' Keyword.Type +' ' Text.Whitespace +'age' Name.Other +'\n' Text.Whitespace + +' ' Text.Whitespace +'BloodType' Name.Other +' ' Text.Whitespace +'bloodType' Name.Other +'\n' Text.Whitespace + +'}' Punctuation +'\n' Text.Whitespace + +'\n' Text.Whitespace + '// Function to compute fibonacci numbers recursively\n' Comment.Single 'f' Keyword.Declaration From a9076a359992fafd2520d7e27dd6dd318d3ddd7c Mon Sep 17 00:00:00 2001 From: Marc Auberer Date: Sat, 10 Sep 2022 19:03:56 +0200 Subject: [PATCH 5/6] Fix bug for tokenizing number formats --- pygments/lexers/spice.py | 4 ++-- tests/examplefiles/spice/example.spice | 2 ++ tests/examplefiles/spice/example.spice.output | 12 ++++++++++++ 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/pygments/lexers/spice.py b/pygments/lexers/spice.py index f28601d788..e7a37f4d41 100644 --- a/pygments/lexers/spice.py +++ b/pygments/lexers/spice.py @@ -48,11 +48,11 @@ class SpiceLexer(RegexLexer): (words(('double', 'int', 'short', 'long', 'byte', 'char', 'string', 'bool', 'dyn'), suffix=r'\b'), Keyword.Type), (words(('printf', 'sizeof', 'len', 'tid', 'join'), suffix=r'\b(\()'), bygroups(Name.Builtin, Punctuation)), # numeric literals - (r'(0[dD])?[0-9]+[sl]?', Number.Integer), - (r'[0-9]*.[0-9]+', Number.Double), + (r'[0-9]*[.][0-9]+', Number.Double), (r'0[bB][01]+[sl]?', Number.Bin), (r'0[oO][0-7]+[sl]?', Number.Oct), (r'0[xXhH][0-9a-fA-F]+[sl]?', Number.Hex), + (r'(0[dD])?[0-9]+[sl]?', Number.Integer), # string literal (r'"(\\\\|\\[^\\]|[^"\\])*"', String), # char literal diff --git a/tests/examplefiles/spice/example.spice b/tests/examplefiles/spice/example.spice index 18e5d9cc5c..55d87753d2 100644 --- a/tests/examplefiles/spice/example.spice +++ b/tests/examplefiles/spice/example.spice @@ -1,3 +1,5 @@ +const int test 0x123; + type BloodType enum { A, B = 3, diff --git a/tests/examplefiles/spice/example.spice.output b/tests/examplefiles/spice/example.spice.output index d01ff3522f..9746813d32 100644 --- a/tests/examplefiles/spice/example.spice.output +++ b/tests/examplefiles/spice/example.spice.output @@ -1,3 +1,15 @@ +'const' Keyword.Pseudo +' ' Text.Whitespace +'int' Keyword.Type +' ' Text.Whitespace +'test' Name.Other +' ' Text.Whitespace +'0x123' Literal.Number.Hex +';' Punctuation +'\n' Text.Whitespace + +'\n' Text.Whitespace + 'type' Keyword.Declaration ' ' Text.Whitespace 'BloodType' Name.Other From 5fbfa3af1b3fa25f1610a2b76e1bcf24d7ac713e Mon Sep 17 00:00:00 2001 From: Marc Auberer Date: Sat, 10 Sep 2022 19:12:07 +0200 Subject: [PATCH 6/6] Add pr to CHANGES --- CHANGES | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGES b/CHANGES index d9e4a40bd6..f43dbd9624 100644 --- a/CHANGES +++ b/CHANGES @@ -7,6 +7,11 @@ Version 2.14.0 -------------- (not released yet) +- Updated lexers: + + * Spice: add ``enum`` keyword and fix a bug regarding binary, + hexadecimal and octal number tokens (#2227) + Version 2.13.0 -------------- (released August 15th, 2022)