-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit f3d2e89
Showing
6 changed files
with
805 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
**/__pycache__ | ||
build/ | ||
dist/ | ||
*.egg-info/ | ||
*.eggs | ||
.coverage | ||
**/.vscode |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/pygments-systemrdl.svg)](https://pypi.org/project/pygments-systemrdl) | ||
|
||
# pygments-systemrdl | ||
|
||
This module implements a [SystemRDL 2.0](http://accellera.org/downloads/standards/systemrdl) | ||
language lexer for [Pygments](https://pytments.org). | ||
The lexer is published as an entry point and, once installed, Pygments will | ||
pick it up automatically. | ||
|
||
The language is registered under the alias: `systemrdl` | ||
|
||
## Installation | ||
|
||
Install from [PyPi](https://pypi.org/project/pygments-systemrdl) using pip: | ||
|
||
python3 -m pip install pygments-systemrdl |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
from pygments import lexer | ||
from pygments import token | ||
from pygments.lexers.perl import PerlLexer | ||
|
||
class SystemRDLLexer(lexer.RegexLexer): | ||
name = 'SystemRDL' | ||
aliases = ['systemrdl'] | ||
filenames = ['*.rdl'] | ||
|
||
tokens = { | ||
|
||
'root': [ | ||
lexer.include('comments'), | ||
lexer.include('perl'), | ||
lexer.include('prop-assign'), | ||
lexer.include('comp-def'), | ||
|
||
(lexer.words(( | ||
'addrmap', 'regfile', 'reg', 'field', 'enum', 'struct', | ||
'constraint', 'signal', 'mem' | ||
), suffix=r'\b'), token.Keyword), | ||
|
||
(lexer.words(( | ||
'external', 'abstract', 'alias', 'unsigned' | ||
), suffix=r'\b'), token.Keyword), | ||
|
||
(lexer.words(( | ||
'bit', 'boolean', 'onreadtype', 'onwritetype', 'string', | ||
'accesstype', 'addressingtype', 'component', | ||
), suffix=r'\b'), token.Keyword.Type), | ||
|
||
lexer.include('literals'), | ||
(r'[{}()\[\],.;\']', token.Punctuation), | ||
(r'[~!%^&*+-=|?:<>/-@]', token.Operator), | ||
(r'[a-zA-Z][\w]*', token.Name), | ||
(r'\s', token.Text) | ||
], | ||
|
||
'comments': [ | ||
(r'(?s)/\*.*\*/', token.Comment.Multiline), | ||
(r'//.*?$', token.Comment.Single), | ||
], | ||
|
||
'perl': [ | ||
(r'(?s)(<%=?)(.+?)(%>)', lexer.bygroups(token.Name.Tag, lexer.using(PerlLexer), token.Name.Tag)), | ||
], | ||
|
||
'literals': [ | ||
(r'([0-9]+)?(\'h)[0-9a-fA-F_]+', token.Number.Hex), | ||
(r'([0-9]+)?(\'b)[01_]+', token.Number.Bin), | ||
(r'([0-9]+)?(\'d)[0-9_]+', token.Number.Integer), | ||
(r'([0-9]+)?(\'o)[0-7_]+', token.Number.Oct), | ||
(r'0[xX][0-9a-fA-F_]+', token.Number.Hex), | ||
(lexer.words(('true', 'false'), suffix=r'\b'), token.Literal), | ||
(r'\d+', token.Number.Integer), | ||
(r'"', token.String, 'string'), | ||
], | ||
'string': [ | ||
(r'"', token.String, '#pop'), | ||
(r'\\([\\abfnrtv"\']|x[a-fA-F0-9]{2,4}|[0-7]{1,3})', token.String.Escape), | ||
(r'[^\\"\n]+', token.String), # all other characters | ||
(r'\\\n', token.String), # line continuation | ||
(r'\\', token.String), # stray backslash | ||
], | ||
|
||
'prop-assign': [ | ||
#(r'(\w+)\s*(;)', lexer.bygroups(token.Name.Attribute, token.Operator)), | ||
(r'(\w+)(\s*)(=)', lexer.bygroups(token.Name.Attribute, token.Text, token.Operator)), | ||
(r'(->)(\s*)(\w+)(\s*)(=)', lexer.bygroups( | ||
token.Operator, token.Text, token.Name.Attribute, token.Text, token.Operator | ||
)), | ||
], | ||
|
||
'comp-def': [ | ||
(r'(addrmap|regfile|reg|field|mem|signal)(\s+)([a-zA-Z][\w]*)', lexer.bygroups(token.Keyword, token.Text, token.Name.Class)) | ||
], | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import os | ||
import setuptools | ||
|
||
with open("README.md", "r") as fh: | ||
long_description = fh.read() | ||
|
||
setuptools.setup ( | ||
name='pygments-systemrdl', | ||
version="1.0.0", | ||
author="Alex Mykyta", | ||
author_email="[email protected]", | ||
description="SystemRDL 2.0 lexer extension for Pygments", | ||
long_description=long_description, | ||
long_description_content_type="text/markdown", | ||
packages=setuptools.find_packages(), | ||
install_requires=["pygments"], | ||
entry_points = | ||
""" | ||
[pygments.lexers] | ||
rdllexer = rdl_pygments.rdllexer:SystemRDLLexer | ||
""", | ||
classifiers=( | ||
"Programming Language :: Python", | ||
"Programming Language :: Python :: 2", | ||
"Programming Language :: Python :: 3", | ||
"Operating System :: OS Independent", | ||
), | ||
project_urls={ | ||
"Source": "https://github.com/SystemRDL/systemrdl-pygments", | ||
}, | ||
) |