1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
|
"""
pygments.lexers.macaulay2
~~~~~~~~~~~~~~~~~~~~~~~~~
Lexer for Macaulay2.
:copyright: Copyright 2006-2024 by the Pygments team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
from pygments.lexer import RegexLexer, words
from pygments.token import Comment, Keyword, Name, String, Text
__all__ = ['Macaulay2Lexer']
@M2BANNER@
M2KEYWORDS = (
@M2KEYWORDS@
)
M2DATATYPES = (
@M2DATATYPES@
)
M2FUNCTIONS = (
@M2FUNCTIONS@
)
M2CONSTANTS = (
@M2CONSTANTS@
)
class Macaulay2Lexer(RegexLexer):
"""Lexer for Macaulay2, a software system for research in algebraic geometry."""
name = 'Macaulay2'
url = 'https://macaulay2.com/'
aliases = ['macaulay2']
filenames = ['*.m2']
version_added = '2.12'
tokens = {
'root': [
(r'--.*$', Comment.Single),
(r'-\*', Comment.Multiline, 'block comment'),
(r'"', String, 'quote string'),
(r'///', String, 'slash string'),
(words(M2KEYWORDS, prefix=r'\b', suffix=r'\b'), Keyword),
(words(M2DATATYPES, prefix=r'\b', suffix=r'\b'), Name.Builtin),
(words(M2FUNCTIONS, prefix=r'\b', suffix=r'\b'), Name.Function),
(words(M2CONSTANTS, prefix=r'\b', suffix=r'\b'), Name.Constant),
(r'\s+', Text.Whitespace),
(r'.', Text)
],
'block comment' : [
(r'[^*-]+', Comment.Multiline),
(r'\*-', Comment.Multiline, '#pop'),
(r'[*-]', Comment.Multiline)
],
'quote string' : [
(r'[^\\"]+', String),
(r'"', String, '#pop'),
(r'\\"?', String),
],
'slash string' : [
(r'[^/]+', String),
(r'(//)+(?!/)', String),
(r'/(//)+(?!/)', String, '#pop'),
(r'/', String)
]
}
|