Skip to content
Browse files

Первое приближение

  • Loading branch information
ilovb committed May 17, 2014
1 parent 377599d commit ce1b2e0c34891cbe25d59ef8506fc5ca969697f3
Showing with 28 additions and 122 deletions.
  1. +28 −122
@@ -1,24 +1,13 @@
class Modula2Lexer(RegexLexer):
For `Modula-2 <>`_ source code.
For `Component Pascal <>`_ source code.
Additional options that determine which keywords are highlighted:
Select PIM Modula-2 dialect (default: True).
Select ISO Modula-2 dialect (default: False).
Select Objective Modula-2 dialect (default: False).
Also highlight GNU extensions (default: False).
.. versionadded:: 1.3
.. versionadded:: 0.0
name = 'Modula-2'
aliases = ['modula2', 'm2']
filenames = ['*.def', '*.mod']
mimetypes = ['text/x-modula2']
name = 'Component Pascal'
aliases = ['ComponentPascal', 'cp', 'CP']
filenames = ['*.cp', '*.cps']
mimetypes = ['text/plain']

flags = re.MULTILINE | re.DOTALL

@@ -31,14 +20,11 @@ class Modula2Lexer(RegexLexer):
(r'([a-zA-Z_\$][\w\$]*)', Name),
'numliterals': [
(r'[01]+B', Number.Binary), # binary number (ObjM2)
(r'[0-7]+B', Number.Oct), # octal number (PIM + ISO)
(r'[0-7]+C', Number.Oct), # char code (PIM + ISO)
(r'[0-9A-F]+C', Number.Hex), # char code (ObjM2)
(r'[0-9A-F]+H', Number.Hex), # hexadecimal number
(r'[0-9A-F]+X', Number.Hex), # char code
(r'[0-9A-F]+[HL]', Number.Hex), # hexadecimal number
(r'[0-9]+\.[0-9]+E[+-][0-9]+', Number.Float), # real number
(r'[0-9]+\.[0-9]+', Number.Float), # real number
(r'[0-9]+', Number.Integer), # decimal whole number
(r'[0-9]+\.[0-9]+', Number.Float), # real number
(r'[0-9]+', Number.Integer), # decimal whole number
'strings': [
(r"'(\\\\|\\'|[^'])*'", String), # single quoted string
@@ -47,23 +33,18 @@ class Modula2Lexer(RegexLexer):
'operators': [
(r'[*/+=#~&<>\^-]', Operator),
(r':=', Operator), # assignment
(r'@', Operator), # pointer deref (ISO)
(r'^', Operator), # pointer deref
(r'\.\.', Operator), # ellipsis or range
(r'`', Operator), # Smalltalk message (ObjM2)
(r'::', Operator), # type conversion (ObjM2)
'punctuation': [
(r'[\(\)\[\]{},.:;|]', Punctuation),
'comments': [
(r'//.*?\n', Comment.Single), # ObjM2
(r'/\*(.*?)\*/', Comment.Multiline), # ObjM2
(r'\(\*([^\$].*?)\*\)', Comment.Multiline),
# TO DO: nesting of (* ... *) comments
'pragmas': [
(r'\(\*\$(.*?)\*\)', Comment.Preproc), # PIM
(r'<\*(.*?)\*>', Comment.Preproc), # ISO + ObjM2
# ???
'root': [
@@ -77,104 +58,29 @@ class Modula2Lexer(RegexLexer):

pim_reserved_words = [
# 40 reserved words
'DIV', 'DO', 'ELSE', 'ELSIF', 'END', 'EXIT', 'EXPORT', 'FOR',

pim_pervasives = [
# 31 pervasives
'ORD', 'PROC', 'REAL', 'SIZE', 'TRUE', 'TRUNC', 'VAL',

iso_reserved_words = [
# 46 reserved words

iso_pervasives = [
# 42 pervasives

objm2_reserved_words = [
# base language, 42 reserved words
'DO', 'ELSE', 'ELSIF', 'END', 'ENUM', 'EXIT', 'FOR', 'FROM', 'IF',
# OO extensions, 16 reserved words

objm2_pervasives = [
# base language, 38 pervasives
'OCTET', 'ODD', 'ORD', 'PRED', 'PROC', 'READ', 'REAL', 'SUCC', 'TMAX',
# OO extensions, 3 pervasives
'OBJECT', 'NO', 'YES',

gnu_reserved_words = [
# 10 additional reserved words
'ASM', '__ATTRIBUTE__', '__BUILTIN__', '__COLUMN__', '__DATE__',
'__FILE__', '__FUNCTION__', '__LINE__', '__MODULE__', 'VOLATILE',
cp_reserved_words = [
# 36 reserved words
'IF', 'IMPORT', 'IN', 'IS', 'LIMITED', 'LOOP', 'MOD', 'MODULE', 'NIL',
'OF', 'OR', 'OUT', 'RETURN', 'THEN', 'TO', 'TYPE', 'UNTIL', 'VAR',

gnu_pervasives = [
# 21 identifiers, actually from pseudo-module SYSTEM
# but we will highlight them as if they were pervasives
'REAL8', 'REAL16', 'REAL32', 'REAL96', 'REAL128', 'THROW',
cp_pervasives = [
# 36 pervasives
'CAP', 'CHAR', 'CHR', 'DEC', 'ENTIER', 'EXCL', 'HALT', 'INC', 'INCL',

def __init__(self, **options):
self.reserved_words = set()
self.pervasives = set()
# ISO Modula-2
if get_bool_opt(options, 'iso', False):
# Objective Modula-2
elif get_bool_opt(options, 'objm2', False):
# PIM Modula-2 (DEFAULT)
# GNU extensions
if get_bool_opt(options, 'gm2ext', False):
# initialise
RegexLexer.__init__(self, **options)

0 comments on commit ce1b2e0

Please sign in to comment.
You can’t perform that action at this time.