Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Spice] Add new keywords and fix bugs #2227

Merged
merged 8 commits into from Sep 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGES
Expand Up @@ -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)
Expand Down
16 changes: 8 additions & 8 deletions pygments/lexers/spice.py
Expand Up @@ -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),
Expand Down
16 changes: 16 additions & 0 deletions 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 {
Expand Down
93 changes: 93 additions & 0 deletions tests/examplefiles/spice/example.spice.output

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.