Skip to content

Commit

Permalink
Fix multiple lexer issues:
Browse files Browse the repository at this point in the history
- Fix escaped chars in strings
- Fix parameterized components
- Add support for verilog-style preprocessor
  • Loading branch information
amykyta3 committed Aug 11, 2019
1 parent f3d2e89 commit cdd96bf
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
18 changes: 14 additions & 4 deletions rdl_pygments/rdllexer.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class SystemRDLLexer(lexer.RegexLexer):
'root': [
lexer.include('comments'),
lexer.include('perl'),
lexer.include('verilog_pp'),
lexer.include('prop-assign'),
lexer.include('comp-def'),

Expand All @@ -30,7 +31,7 @@ class SystemRDLLexer(lexer.RegexLexer):
), suffix=r'\b'), token.Keyword.Type),

lexer.include('literals'),
(r'[{}()\[\],.;\']', token.Punctuation),
(r'[#{}()\[\],.;\']', token.Punctuation),
(r'[~!%^&*+-=|?:<>/-@]', token.Operator),
(r'[a-zA-Z][\w]*', token.Name),
(r'\s', token.Text)
Expand All @@ -45,6 +46,16 @@ class SystemRDLLexer(lexer.RegexLexer):
(r'(?s)(<%=?)(.+?)(%>)', lexer.bygroups(token.Name.Tag, lexer.using(PerlLexer), token.Name.Tag)),
],

'verilog_pp': [
(r'`[ \t]*include[ \t]+(<[^"\r\n]+>|"[^"\r\n]+")', token.Comment.Preproc),
(r'`[ \t]*define', token.Comment.Preproc, 'verilog_define')
],
'verilog_define':[
(r'\n', token.Comment.Preproc, '#pop'),
(r'\\\n', token.Comment.Preproc),
(r'[^\\\n]+', token.Comment.Preproc), # all other characters
],

'literals': [
(r'([0-9]+)?(\'h)[0-9a-fA-F_]+', token.Number.Hex),
(r'([0-9]+)?(\'b)[01_]+', token.Number.Bin),
Expand All @@ -57,9 +68,8 @@ class SystemRDLLexer(lexer.RegexLexer):
],
'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.Escape),
(r'[^\\"]+', token.String), # all other characters
(r'\\', token.String), # stray backslash
],

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

setuptools.setup (
name='pygments-systemrdl',
version="1.0.0",
version="1.1.0",
author="Alex Mykyta",
author_email="[email protected]",
description="SystemRDL 2.0 lexer extension for Pygments",
Expand Down

0 comments on commit cdd96bf

Please sign in to comment.