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 --- README.rst | 5 +++ elan.py | 135 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ elan.vim | 51 +++++++++++++++++++++++ 3 files changed, 191 insertions(+) create mode 100644 README.rst create mode 100644 elan.py create mode 100644 elan.vim diff --git a/README.rst b/README.rst new file mode 100644 index 0000000..2b83812 --- /dev/null +++ b/README.rst @@ -0,0 +1,5 @@ +EUMEL-python +============ + +Tools for dealing with EUMEL datastructures and files, mostly written in Python. + 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'), + ] + } + diff --git a/elan.vim b/elan.vim new file mode 100644 index 0000000..56f03d6 --- /dev/null +++ b/elan.vim @@ -0,0 +1,51 @@ +" Vim syntax file +" Copy to ~/.vim/syntax/ and enable with :set filetype=elan +" Language: ELAN +" Maintainer: Lars-Dominik Braun +" Latest Revision: 2017-02-26 + +if exists("b:current_syntax") + finish +endif + +syn keyword elanStatement PROC ENDPROC OP PACKET LEAVE WITH END LET DEFINES +syn keyword elanConditional IF ELSE FI THEN SELECT OF ELIF +syn keyword elanRepeat FOR FROM UPTO REP PER WHILE UNTIL +syn keyword elanBoolean TRUE FALSE +syn keyword elanType DATASPACE INT TEXT BOOL THESAURUS FILE REAL +syn match elanOperator ":=" +syn match elanOperator "::" +syn match elanOperator "\*" +syn match elanOperator "<>" +syn keyword elanOperator AND OR CAND COR NOT XOR +syn keyword elanOperator DIV MUL ISUB INCR DECR MOD SUB LENGTH CAT LIKE CONTAINS +syn keyword elanStorageClass VAR CONST BOUND ROW +syn keyword elanStructure STRUCT TYPE +syn keyword elanLabel CASE OTHERWISE +syn match elanNumber "-\=\<\d\+\>" +syn match elanFloat "\d\+\.\d\+" + +syn region elanComment start=+(\*+ end=+\*)+ +" XXX: tried to fix strings containing numbers that are not escapes, like "2", +syn region elanString start=+"+rs=s+1 end=+"+re=e-1 contains=elanStringEscape +"syn match elanStringEscape contained +"[0-9]\+"+ + + +hi def link elanBoolean Boolean +hi def link elanConditional Conditional +hi def link elanRepeat Repeat +hi def link elanType Type +hi def link elanComment Comment +hi def link elanOperator Operator +hi def link elanString String +hi def link elanStringEscape Special +hi def link elanStorageClass StorageClass +hi def link elanStructure Structure +hi def link elanLabel Label +hi def link elanStatement Statement +hi def link elanNumber Number +hi def link elanFloat Float + +let b:current_syntax = "elan" + + -- cgit v1.2.3