-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a Pygments lexer for the Alt-Ergo language
This patch adds a custom Pygments lexer for the Alt-Ergo language and uses it to make the Sphinx documentation prettier.
- Loading branch information
1 parent
0700dea
commit b7bc2b9
Showing
3 changed files
with
89 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,5 +41,8 @@ alt-ergo.js | |
alt-ergo-worker.js | ||
www/ | ||
|
||
# Generated python files | ||
__pycache__ | ||
|
||
# Generated nix files | ||
/result* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
from pygments.lexer import RegexLexer, include | ||
from pygments.token import * | ||
|
||
__globals__ = [ 'AltErgoLexer' ] | ||
|
||
class AltErgoLexer(RegexLexer): | ||
""" | ||
For the Alt-Ergo language. | ||
""" | ||
|
||
name = 'Alt-Ergo' | ||
url = 'https://alt-ergo.ocamlpro.com/' | ||
aliases = ['alt-ergo'] | ||
filenames = ['*.ae'] | ||
mimetypes = ['text/x-alt-ergo'] | ||
|
||
keywords = ( | ||
'ac', 'axiom', 'bitv', 'case_split', 'check', 'cut', | ||
'distinct', 'else', 'end', 'exists', 'extends', 'forall', | ||
'function', 'goal', 'check_sat', 'if', 'let', 'logic', 'not', | ||
'predicate', 'prop', 'rewriting', 'then', 'theory', | ||
'type', 'match', 'with', 'of', | ||
) | ||
keyopts = ( | ||
r',', r';', r'\(', r'\)', r':', r'->', r'<-', r'<->', r'=', r'<', r'<=', | ||
r'>', r'>=', r'<>', r'\+', r'-', r'\*', r'\*\*', r'\*\*\.', r'/', r'%', | ||
r'@', r'\.', r'#', r'\[', r'\]', r'\{', r'\}', 'r\|', r'\^', r'\|->', | ||
) | ||
|
||
word_operators = ('and', 'in', 'or', 'xor') | ||
primitives = ('bool', 'int', 'real', 'unit', 'void') | ||
|
||
tokens = { | ||
'escape-sequence': [ | ||
(r'\\[\\"\'ntbr]', String.Escape), | ||
(r'\\[0-9]{3}', String.Escape), | ||
(r'\\x[0-9a-fA-F]{2}', String.Escape), | ||
], | ||
'root': [ | ||
(r'\s+', Text), | ||
(r'false|true', Name.Builtin.Pseudo), | ||
(r'\(\*(?![)])', Comment, 'comment'), | ||
(r'\b(%s)\b' % '|'.join(keywords), Keyword), | ||
(r'(%s)' % '|'.join(keyopts[::-1]), Operator), | ||
(r'\b(%s)\b' % '|'.join(word_operators), Operator.Word), | ||
(r'\b(%s)\b' % '|'.join(primitives), Keyword.Type), | ||
|
||
(r"\??[^\W\d][\w?']*", Name), | ||
|
||
(r'-?\d[\d_]*(.[\d_]*)?([eE][+\-]?\d[\d_]*)', Number.Float), | ||
(r'0[xX][\da-fA-F][\da-fA-F_]*', Number.Hex), | ||
(r'0[oO][0-7][0-7_]*', Number.Oct), | ||
(r'0[bB][01][01_]*', Number.Bin), | ||
(r'\d[\d_]*', Number.Integer), | ||
|
||
(r"'", Keyword), | ||
|
||
(r'"', String.Double, 'string'), | ||
], | ||
'comment': [ | ||
(r'[^(*)]+', Comment), | ||
(r'\(\*', Comment, '#push'), | ||
(r'\*\)', Comment, '#pop'), | ||
(r'[(*)]', Comment), | ||
], | ||
'string': [ | ||
(r'[^\\"]+', String.Double), | ||
include('escape-sequence'), | ||
(r'\\\n', String.Double), | ||
(r'"', String.Double, '#pop'), | ||
], | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters