""" pygments lexer for Elementary Language (ELAN) - Rainer Hahn, Peter Stock: ELAN Handbuch. 1979. - Rainer Hahn, Dietmar Heinrichs, Peter Heyderhoff: EUMEL Benutzerhandbuch Version 1.7. 1984. """ from pygments.lexer import RegexLexer, bygroups, include, words from pygments.token import * __all__ = ['ElanLexer'] def uppercaseWords (l): """ Match only uppercase words provided in l. For example FOR should not match FORMAT. """ return words (l, prefix=r'(?', '<=', '>=', '<', '>', # math '**', '*','+', '-', '/', ), prefix=r'(?*+-/])', suffix=r'(?![:=<>*+-/])'), Operator), # packets, function and operators # no space required between keyword and identifier # XXX comments may be allowed between keyword and name (r'((?:END\s*)?PACKET)([^A-Za-z]*)([a-z][a-z0-9 ]+)', bygroups (Keyword.Declaration, Text, Name.Namespace)), (r'((?:END\s*)?PROC)([^A-Za-z]*)([a-z][a-z0-9 ]+)', bygroups (Keyword.Declaration, Text, Name.Function)), (r'((?:END\s*)?OP)([^A-Za-z]*)([^a-z0-9 (;]+)', bygroups (Keyword.Declaration, Text, Name.Function)), # Refinements (r'\.(?![a-z])', Text, 'refinement'), (r'.', Text), ], 'comment': [ (r'\(\*', Comment, 'comment-inside1'), (r'\{', Comment, 'comment-inside2'), (r'#\(', Comment, 'comment-inside3'), ], 'comment-inside1': [ # comment can be nested include('comment'), (r'\*\)', Comment, '#pop'), (r'(.|\n)', Comment), ], 'comment-inside2': [ # comment can be nested include('comment'), (r'\}', Comment, '#pop'), (r'(.|\n)', Comment), ], 'comment-inside3': [ # comment can be nested include('comment'), (r'#\)', Comment, '#pop'), (r'(.|\n)', Comment), ], 'string': [ # "" equals '\"', "12" is '\12' (r'"[0-9]*"', String.Escape), (r'"', String.Double, '#pop'), (r'.', String.Double), ], 'refinement': [ include('comment'), (r'\s+', Text), (r'([a-z][a-z0-9 ]*)(:\s+)', bygroups(Name.Label, Text), '#pop'), (r'', Text, '#pop'), ] }