diff --git a/CHANGES b/CHANGES index 27828195a0..4d9969c5b5 100644 --- a/CHANGES +++ b/CHANGES @@ -19,6 +19,8 @@ Version 2.14.0 * Inform 6: fix lexing of properties and doubles (#2214) * NASM: add support for SSE/AVX/AVX-512 registers as well as 'rel' and 'abs' address operators (#2212) + * Spice: add ``enum`` keyword and fix a bug regarding binary, + hexadecimal and octal number tokens (#2227) - Fix `make mapfiles` when Pygments is not installed in editable mode (#2223) diff --git a/pygments/lexers/spice.py b/pygments/lexers/spice.py index c8269f318b..e7a37f4d41 100644 --- a/pygments/lexers/spice.py +++ b/pygments/lexers/spice.py @@ -40,25 +40,25 @@ 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)), # 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-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 (r'\'(\\\\|\\[^\\]|[^\'\\])\'', String.Char), # tokens - (r'(<<=|>>=|<<|>>|<=|>=|\+=|-=|\*=|/=|\%=|\|=|&=|\^=|&&|\|\||&|\||\+\+|--|\%|\^|\~|==|!=|[.]{3}|[+\-*/&])', Operator), + (r'<<=|>>=|<<|>>|<=|>=|\+=|-=|\*=|/=|\%=|\|=|&=|\^=|&&|\|\||&|\||\+\+|--|\%|\^|\~|==|!=|::|[.]{3}|[+\-*/&]', Operator), (r'[|<>=!()\[\]{}.,;:\?]', Punctuation), # identifiers (r'[^\W\d]\w*', Name.Other), diff --git a/tests/examplefiles/spice/example.spice b/tests/examplefiles/spice/example.spice index 699efdf252..55d87753d2 100644 --- a/tests/examplefiles/spice/example.spice +++ b/tests/examplefiles/spice/example.spice @@ -1,3 +1,19 @@ +const int test 0x123; + +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 { diff --git a/tests/examplefiles/spice/example.spice.output b/tests/examplefiles/spice/example.spice.output index 3d75ef94c1..9746813d32 100644 --- a/tests/examplefiles/spice/example.spice.output +++ b/tests/examplefiles/spice/example.spice.output @@ -1,3 +1,96 @@ +'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 +' ' 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