Igor Kalnitsky avatar Igor Kalnitsky committed 3bf9bdb

Added VHDL Lexer.

Comments (0)

Files changed (3)

 * Ben Hollis -- Mason lexer
 * Tim Howard -- BlitzMax lexer
 * Dennis Kaarsemaker -- sources.list lexer
+* Igor Kalnitsky -- vhdl lexer
 * Benjamin Kowarsch -- Modula-2 lexer
 * Marek Kubica -- Scheme lexer
 * Jochen Kupperschmidt -- Markdown processor

pygments/lexers/_mapping.py

     'VelocityLexer': ('pygments.lexers.templates', 'Velocity', ('velocity',), ('*.vm', '*.fhtml'), ()),
     'VelocityXmlLexer': ('pygments.lexers.templates', 'XML+Velocity', ('xml+velocity',), (), ('application/xml+velocity',)),
     'VerilogLexer': ('pygments.lexers.hdl', 'verilog', ('v',), ('*.v', '*.sv'), ('text/x-verilog',)),
+    'VhdlLexer': ('pygments.lexers.hdl', 'vhdl', ('vhdl',), ('*.vhdl', '*.vhd'), ('text/x-vhdl',)),
     'VimLexer': ('pygments.lexers.text', 'VimL', ('vim',), ('*.vim', '.vimrc', '.exrc', '.gvimrc', '_vimrc', '_exrc', '_gvimrc'), ('text/x-vim',)),
     'XQueryLexer': ('pygments.lexers.web', 'XQuery', ('xquery', 'xqy'), ('*.xqy', '*.xquery'), ('text/xquery', 'application/xquery')),
     'XmlDjangoLexer': ('pygments.lexers.templates', 'XML+Django/Jinja', ('xml+django', 'xml+jinja'), (), ('application/xml+django', 'application/xml+jinja')),

pygments/lexers/hdl.py

 
 import re
 
-from pygments.lexer import RegexLexer, include, bygroups
+from pygments.lexer import RegexLexer, include, bygroups, using, this
 from pygments.token import \
      Text, Comment, Operator, Keyword, Name, String, Number, Punctuation, \
      Error
 
-__all__ = ['VerilogLexer']
+__all__ = ['VerilogLexer', 'VhdlLexer']
 
 
 class VerilogLexer(RegexLexer):
             yield index, token, value
 
 
+class VhdlLexer(RegexLexer):
+    """
+    For vhdl source code.
+    """
+    name = 'vhdl'
+    aliases = ['vhdl']
+    filenames = ['*.vhdl', '*.vhd']
+    mimetypes = ['text/x-vhdl']
+
+    tokens = {
+        'root': [
+            (r'\n', Text),
+            (r'\s+', Text),
+            (r'\\\n', Text), # line continuation
+            (r'--(?![!#$%&*+./<=>?@\^|_~]).*?$', Comment.Single),
+            (r"'(U|X|0|1|Z|W|L|H|-)'", String.Char),
+            (r'[~!%^&*+=|?:<>/-]', Operator),
+            (r"'[a-zA-Z_][a-zA-Z0-9_]*", Name.Attribute),
+            (r'[()\[\],.;\']', Punctuation),
+            (r'"[^\n\\]*"', String),
+
+            (r'(library)(\s+)([a-zA-Z_][a-zA-Z0-9_]*)', bygroups(Keyword, Text, Name.Namespace)),
+            (r'(use)(\s+)([a-zA-Z_][\.a-zA-Z0-9_]*)', bygroups(Keyword, Text, Name.Namespace)),
+            (r'(entity|component)(\s+)([a-zA-Z_][a-zA-Z0-9_]*)', bygroups(Keyword, Text, Name.Class)),
+            (r'(architecture|configuration)(\s+)([a-zA-Z_][a-zA-Z0-9_]*)(\s+)(of)(\s+)([a-zA-Z_][a-zA-Z0-9_]*)(\s+)(is)',
+                bygroups(Keyword, Text, Name.Class, Text, Keyword, Text, Name.Class, Text, Keyword)),
+
+            (r'(end)(\s+)', bygroups(using(this), Text), 'endblock'),
+
+            include('types'),
+            include('keywords'),
+            include('numbers'),
+
+            (r'[a-zA-Z_][a-zA-Z0-9_]*', Name),
+        ],
+        'endblock': [
+            (r'\s+$', Text),
+            (r'[()\[\],.;\']', Punctuation),
+
+            include('keywords'),
+            (r'[a-zA-Z_][a-zA-Z0-9_]*', Name.Class),
+        ],
+        'types': [
+            (r'(boolean|bit|character|severity_level|integer|time|delay_length|'
+             r'natural|positive|string|bit_vector|file_open_kind|file_open_status|'
+             r'std_ulogic|std_ulogic_vector|std_logic|std_logic_vector)\b', Keyword.Type),
+        ],
+        'keywords': [
+            (r'(abs|access|after|alias|all|and|'
+             r'architecture|array|assert|attribute|begin|block|'
+             r'body|buffer|bus|case|component|configuration|'
+             r'constant|disconnect|downto|else|elsif|end|'
+             r'entity|exit|file|for|function|generate|'
+             r'generic|group|guarded|if|impure|in|'
+             r'inertial|inout|is|label|library|linkage|'
+             r'literal|loop|map|mod|nand|new|'
+             r'next|nor|not|null|of|on|'
+             r'open|or|others|out|package|port|'
+             r'postponed|procedure|process|pure|range|record|'
+             r'register|reject|return|rol|ror|select|'
+             r'severity|signal|shared|sla|sli|sra|'
+             r'srl|subtype|then|to|transport|type|'
+             r'units|until|use|variable|wait|when|'
+             r'while|with|xnor|xor)\b', Keyword),
+        ],
+        'numbers': [
+            (r'\d{1,2}#[0-9a-fA-F_]+#?', Number.Integer),
+            (r'[0-1_]+(\.[0-1_])', Number.Integer),
+            (r'\d+', Number.Integer),
+            (r'(\d+\.\d*|\.\d+|\d+)[eE][+-]?\d+', Number.Float),
+            (r'H"[0-9a-fA-F_]+"', Number.Oct),
+            (r'O"[0-7_]+"', Number.Oct),
+            (r'B"[0-1_]+"', Number.Oct),
+        ],
+    }
+
+
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.