3 pygments.lexers.modula2 |
3 pygments.lexers.modula2 |
4 ~~~~~~~~~~~~~~~~~~~~~~~ |
4 ~~~~~~~~~~~~~~~~~~~~~~~ |
5 |
5 |
6 Multi-Dialect Lexer for Modula-2. |
6 Multi-Dialect Lexer for Modula-2. |
7 |
7 |
8 :copyright: Copyright 2006-2020 by the Pygments team, see AUTHORS. |
8 :copyright: Copyright 2006-2021 by the Pygments team, see AUTHORS. |
9 :license: BSD, see LICENSE for details. |
9 :license: BSD, see LICENSE for details. |
10 """ |
10 """ |
11 |
11 |
12 import re |
12 import re |
13 |
13 |
226 # |
226 # |
227 # Base-16, number |
227 # Base-16, number |
228 (r'[0-9A-F]+H', Number.Hex), |
228 (r'[0-9A-F]+H', Number.Hex), |
229 ], |
229 ], |
230 'string_literals': [ |
230 'string_literals': [ |
231 (r"'(\\\\|\\'|[^'])*'", String), # single quoted string |
231 (r'"(\\\\|\\[^\\]|[^"\\])*"', String.Double), |
232 (r'"(\\\\|\\"|[^"])*"', String), # double quoted string |
232 (r"'(\\\\|\\[^\\]|[^'\\])*'", String.Single), |
233 ], |
233 ], |
234 'digraph_operators': [ |
234 'digraph_operators': [ |
235 # Dot Product Operator |
235 # Dot Product Operator |
236 (r'\*\.', Operator), |
236 (r'\*\.', Operator), |
237 # Array Concatenation Operator |
237 # Array Concatenation Operator |
1557 elif value == '*.': |
1557 elif value == '*.': |
1558 value = '•' |
1558 value = '•' |
1559 |
1559 |
1560 # return result |
1560 # return result |
1561 yield index, token, value |
1561 yield index, token, value |
|
1562 |
|
1563 def analyse_text(text): |
|
1564 """It's Pascal-like, but does not use FUNCTION -- uses PROCEDURE |
|
1565 instead.""" |
|
1566 |
|
1567 # Check if this looks like Pascal, if not, bail out early |
|
1568 if not ('(*' in text and '*)' in text and ':=' in text): |
|
1569 return |
|
1570 |
|
1571 result = 0 |
|
1572 # Procedure is in Modula2 |
|
1573 if re.search(r'\bPROCEDURE\b', text): |
|
1574 result += 0.6 |
|
1575 |
|
1576 # FUNCTION is only valid in Pascal, but not in Modula2 |
|
1577 if re.search(r'\bFUNCTION\b', text): |
|
1578 result = 0.0 |
|
1579 |
|
1580 return result |