summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarc Auberer <marc.auberer@sap.com>2022-09-13 23:23:42 +0200
committerGitHub <noreply@github.com>2022-09-13 23:23:42 +0200
commitca56bf26961a04e53c7691f4f15a1ffe1d222fec (patch)
tree55bbe4e3c01672d901390c7cf34c50656f93f39b
parente94cb7eeaabaf8cccffabf3e431e284561139f04 (diff)
downloadpygments-git-ca56bf26961a04e53c7691f4f15a1ffe1d222fec.tar.gz
[Spice] Add new keywords and fix bugs (#2227)
* Cleanup * Add scope access operator * Add enum keyword * Update test ref * Fix bug for tokenizing number formats * Add pr to CHANGES
-rw-r--r--CHANGES2
-rw-r--r--pygments/lexers/spice.py16
-rw-r--r--tests/examplefiles/spice/example.spice16
-rw-r--r--tests/examplefiles/spice/example.spice.output93
4 files changed, 119 insertions, 8 deletions
diff --git a/CHANGES b/CHANGES
index 27828195..4d9969c5 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 c8269f31..e7a37f4d 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 699efdf2..55d87753 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<int> fib(int n) {
if n <= 2 {
diff --git a/tests/examplefiles/spice/example.spice.output b/tests/examplefiles/spice/example.spice.output
index 3d75ef94..9746813d 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