From 58e98cc43952385dd165885d04eb2260f3ddc38e Mon Sep 17 00:00:00 2001 From: Lars-Dominik Braun Date: Sun, 9 Jul 2017 14:39:58 +0200 Subject: Add ELAN vim syntax file/pygments lexer and README --- elan.py | 135 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 135 insertions(+) create mode 100644 elan.py (limited to 'elan.py') diff --git a/elan.py b/elan.py new file mode 100644 index 0000000..beeb9f8 --- /dev/null +++ b/elan.py @@ -0,0 +1,135 @@ +""" +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'), + ] + } + -- cgit v1.2.3