Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Antlr4 #49

Merged
merged 27 commits into from
Feb 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
2e6d44b
Added ANTLR4 grammar and generated Python code.
Paebbels Jul 16, 2022
a957563
Updated generated code.
Paebbels Jul 16, 2022
bd16027
Added ANTLR4 CLI command for testing.
Paebbels Jul 16, 2022
261d2d0
Implemented first Visitor code.
Paebbels Jul 17, 2022
24de866
Formatted Lexer code.
Paebbels Jul 17, 2022
a454742
Formatted Parser code.
Paebbels Jul 17, 2022
473a448
Formatted ParserVisitor code.
Paebbels Jul 17, 2022
e8d42a5
Updated grammar.
Paebbels Jul 17, 2022
aa7a28c
Updated Visitor.
Paebbels Jul 17, 2022
8930c15
Further optimizations.
Paebbels Jul 17, 2022
5e99279
Next round of improvements.
Paebbels Jul 17, 2022
5769d72
Renamed APOSTROPHE to TICK.
Paebbels Jul 17, 2022
4dfcc8b
Latest generated parser.
Paebbels Jul 17, 2022
c60a643
Simplified grammar.
Paebbels Jul 17, 2022
4168b4a
Supporting ports.
Paebbels Jul 17, 2022
11140b1
Updated grammar.
Paebbels Jul 19, 2022
08417f3
Ability to read tokens and comments.
Paebbels Jul 19, 2022
e2ac268
Updated.
Paebbels Jul 21, 2022
fd16ddb
Updated lexer and parser grammars to VHDL-2019.
Paebbels Jul 24, 2022
95d7813
Solved ANTLR4 left-recursion problem.
Paebbels Jul 24, 2022
4856d91
Fixed grammar rules.
Paebbels Jul 24, 2022
7d4bb34
Updated auto generated files.
Paebbels Jul 24, 2022
58084cf
Added missing operators.
Paebbels Jul 24, 2022
d03ba2a
Optimizations and new rules for GROUP.
Paebbels Jul 30, 2022
8fd499d
Bumped dependencies.
Paebbels Oct 5, 2022
ebdff5c
General updates.
Paebbels Feb 18, 2023
fff62fe
Merge branch 'dev' into antlr4
Paebbels Feb 18, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions .btd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,4 @@ target: gh-pages
formats: [ html ]
images:
base: btdi/sphinx:pytooling
latex: btdi/latex
theme: https://codeload.GitHub.com/buildthedocs/sphinx.theme/tar.gz/v1
theme: https://codeload.github.com/buildthedocs/sphinx.theme/tar.gz/v1
14 changes: 7 additions & 7 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ coverage.xml
# Dependencies
!requirements.txt

# Sphinx
doc/_build/
doc/pyVHDLParser/**/*.*
!doc/pyVHDLParser/index.rst

# BuildTheDocs
doc/_theme/**/*.*
# Sphinx documentation
/doc/_build/
/doc/_theme/
/doc/pyVHDLParser/**/*.*
!/doc/pyVHDLParser/index.rst

# IntelliJ project files
/.idea/workspace.xml

pyVHDLParser/Sven
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
![PyPI - Python Version](https://img.shields.io/pypi/pyversions/pyVHDLParser?logo=PyPI)
[![Dependent repos (via libraries.io)](https://img.shields.io/librariesio/dependent-repos/pypi/pyVHDLParser)](https://github.com/Paebbels/pyVHDLParser/network/dependents)
[![Libraries.io status for latest release](https://img.shields.io/librariesio/release/pypi/pyVHDLParser)](https://libraries.io/github/Paebbels/pyVHDLParser)
[![Requires.io](https://img.shields.io/requires/github/Paebbels/pyVHDLParser)](https://requires.io/github/Paebbels/pyVHDLParser/requirements/?branch=master)
[![Codacy - Quality](https://img.shields.io/codacy/grade/1155f244b6f54a3a95abdaa80d6771f8?logo=Codacy)](https://www.codacy.com/manual/Paebbels/pyVHDLParser)
[![Codacy - Coverage](https://img.shields.io/codacy/coverage/1155f244b6f54a3a95abdaa80d6771f8?logo=Codacy)](https://www.codacy.com/manual/Paebbels/pyVHDLParser)
[![Codecov - Branch Coverage](https://img.shields.io/codecov/c/github/Paebbels/pyVHDLParser?logo=Codecov)](https://codecov.io/gh/Paebbels/pyVHDLParser)
Expand Down
4 changes: 2 additions & 2 deletions doc/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@
.. only:: html

|SHIELD:svg:pyVHDLParser-github| |SHIELD:svg:pyVHDLParser-tag| |SHIELD:svg:pyVHDLParser-release| |SHIELD:svg:pyVHDLParser-date| |br|
|SHIELD:svg:pyVHDLParser-lib-status| |SHIELD:svg:pyVHDLParser-req-status| |SHIELD:svg:pyVHDLParser-lib-dep| |br|
|SHIELD:svg:pyVHDLParser-lib-status| |SHIELD:svg:pyVHDLParser-lib-dep| |br|
|SHIELD:svg:pyVHDLParser-travis| |SHIELD:svg:pyVHDLParser-pypi-tag| |SHIELD:svg:pyVHDLParser-pypi-status| |SHIELD:svg:pyVHDLParser-pypi-python| |br|
|SHIELD:svg:pyVHDLParser-codacy-quality| |SHIELD:svg:pyVHDLParser-codacy-coverage| |SHIELD:svg:pyVHDLParser-codecov-coverage| |SHIELD:svg:pyVHDLParser-lib-rank| |br|
|SHIELD:svg:pyVHDLParser-rtd| |SHIELD:svg:pyVHDLParser-license|

.. only:: latex

|SHIELD:png:pyVHDLParser-github| |SHIELD:png:pyVHDLParser-tag| |SHIELD:png:pyVHDLParser-release| |SHIELD:png:pyVHDLParser-date| |br|
|SHIELD:png:pyVHDLParser-lib-status| |SHIELD:png:pyVHDLParser-req-status| |SHIELD:png:pyVHDLParser-lib-dep| |br|
|SHIELD:png:pyVHDLParser-lib-status| |SHIELD:png:pyVHDLParser-lib-dep| |br|
|SHIELD:png:pyVHDLParser-travis| |SHIELD:png:pyVHDLParser-pypi-tag| |SHIELD:png:pyVHDLParser-pypi-status| |SHIELD:png:pyVHDLParser-pypi-python| |br|
|SHIELD:png:pyVHDLParser-codacy-quality| |SHIELD:png:pyVHDLParser-codacy-coverage| |SHIELD:png:pyVHDLParser-codecov-coverage| |SHIELD:png:pyVHDLParser-lib-rank| |br|
|SHIELD:png:pyVHDLParser-rtd| |SHIELD:png:pyVHDLParser-license|
Expand Down
7 changes: 7 additions & 0 deletions doc/prolog.inc
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,10 @@

.. role:: underline
:class: underline

.. role:: xlarge
:class: xlarge

.. role:: pycode(code)
:language: python
:class: highlight
9 changes: 0 additions & 9 deletions doc/shields.inc
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,6 @@
:height: 22
:target: https://libraries.io/github/Paebbels/pyVHDLParser

.. |SHIELD:svg:pyVHDLParser-req-status| image:: https://img.shields.io/requires/github/Paebbels/pyVHDLParser
:alt: Requires.io
:height: 22
:target: https://requires.io/github/Paebbels/pyVHDLParser/requirements/?branch=master
.. |SHIELD:png:pyVHDLParser-req-status| image:: https://raster.shields.io/requires/github/Paebbels/pyVHDLParser
:alt: Requires.io
:height: 22
:target: https://requires.io/github/Paebbels/pyVHDLParser/requirements/?branch=master

.. |SHIELD:svg:pyVHDLParser-travis| image:: https://img.shields.io/travis/com/Paebbels/pyVHDLParser?logo=Travis
:alt: Travis - Build on 'master'
:height: 22
Expand Down
315 changes: 315 additions & 0 deletions pyVHDLParser/ANTLR4/VHDLLexer.g4
Original file line number Diff line number Diff line change
@@ -0,0 +1,315 @@
// ================================================================================================================== //
// __ ___ _ ____ _ ____ //
// _ __ _ \ \ / / | | | _ \| | | _ \ __ _ _ __ ___ ___ _ __ //
// | '_ \| | | \ \ / /| |_| | | | | | | |_) / _` | '__/ __|/ _ \ '__| //
// | |_) | |_| |\ V / | _ | |_| | |___| __/ (_| | | \__ \ __/ | //
// | .__/ \__, | \_/ |_| |_|____/|_____|_| \__,_|_| |___/\___|_| //
// |_| |___/ //
// ================================================================================================================== //
// Authors: //
// Patrick Lehmann //
// //
// License: //
// ================================================================================================================== //
// Copyright 2017-2022 Patrick Lehmann - Boetzingen, Germany //
// Copyright 2016-2017 Patrick Lehmann - Dresden, Germany //
// //
// Licensed under the Apache License, Version 2.0 (the "License"); //
// you may not use this file except in compliance with the License. //
// You may obtain a copy of the License at //
// //
// http://www.apache.org/licenses/LICENSE-2.0 //
// //
// Unless required by applicable law or agreed to in writing, software //
// distributed under the License is distributed on an "AS IS" BASIS, //
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. //
// See the License for the specific language governing permissions and //
// limitations under the License. //
// ================================================================================================================== //
//
lexer grammar VHDLLexer;

options {
caseInsensitive = true;
}

channels {
WHITESPACE_CHANNEL,
COMMENT_CHANNEL,
TOOLDIRECTIVE_CHANNEL
}

LINEBREAK: [\r\n]+ -> channel(WHITESPACE_CHANNEL) ;
WHITESPACE: [ \t\f\b]+ -> channel(WHITESPACE_CHANNEL) ;
COMMENT_LINE: '--' ~[\r\n]* -> channel(COMMENT_CHANNEL) ;
COMMENT_BLOCK: '/*' .*? '*/' -> channel(COMMENT_CHANNEL) ;
TOOLDIRECTIVE: '`' ~[\r\n]* -> channel(TOOLDIRECTIVE_CHANNEL) ;

// Reserved words starting with A
OP_ABS: 'abs';
KW_ACCESS: 'access';
KW_AFTER: 'after';
KW_ALIAS: 'alias';
KW_ALL: 'all';
OP_AND: 'and';
KW_ARCHITECTURE: 'architecture';
KW_ARRAY: 'array';
KW_ASSERT: 'assert';
KW_ATTRIBUTE: 'attribute';
KW_PSL_ASSUME: 'assume';
//KW_AMS_ACROSS: 'across';

// Reserved words starting with B
KW_BEGIN: 'begin';
KW_BLOCK: 'block';
KW_BODY: 'body';
KW_BUFFER: 'buffer';
KW_BUS: 'bus';
//KW_AMS_BREAK: 'break';

// Reserved words starting with C
KW_CASE: 'case';
KW_COMPONENT: 'component';
KW_CONFIGURATION: 'configuration';
KW_CONSTANT: 'constant';
KW_CONTEXT: 'context';
KW_PSL_COVER: 'cover';

// Reserved words starting with D
KW_DEFAULT: 'default';
KW_DISCONNECT: 'disconnect';
KW_DOWNTO: 'downto';

// Reserved words starting with E
KW_ELSE: 'else';
KW_ELSIF: 'elsif';
KW_END: 'end';
KW_ENTITY: 'entity';
KW_EXIT: 'exit';

// Reserved words starting with F
KW_FILE: 'file';
KW_FOR: 'for';
KW_FORCE: 'force';
KW_FUNCTION: 'function';
KW_PSL_FAIRNESS: 'fairness';

// Reserved words starting with G
KW_GENERATE: 'generate';
KW_GENERIC: 'generic';
KW_GUARDED: 'guarded';
KW_GROUP: 'group';

// Reserved words starting with I
KW_IF: 'if';
KW_IMPURE: 'impure';
KW_IN: 'in';
KW_INERTIAL: 'inertial';
KW_INOUT: 'inout';
KW_IS: 'is';

// Reserved words starting with L
KW_LABEL: 'label';
KW_LIBRARY: 'library';
KW_LINKAGE: 'linkage';
KW_LOOP: 'loop';
KW_PSL_LITERAL: 'literal';
//KW_AMS_LIMIT: 'limit';

// Reserved words starting with M
KW_MAP: 'map';
OP_MOD: 'mod';

// Reserved words starting with N
OP_NAND: 'nand';
KW_NEW: 'new';
KW_NEXT: 'next';
OP_NOR: 'nor';
OP_NOT: 'not';
KW_NULL: 'null';
//KW_AMS_NATURE: 'nature';
//KW_AMS_NOISE: 'noise';

// Reserved words starting with O
KW_OF: 'of';
KW_ON: 'on';
KW_OPEN: 'open';
OP_OR: 'or';
KW_OTHERS: 'others';
KW_OUT: 'out';

// Reserved words starting with P
KW_PACKAGE: 'package';
KW_PARAMETER: 'parameter';
KW_PORT: 'port';
KW_POSTPONED: 'postponed';
KW_PRIVATE: 'private';
KW_PROCEDURE: 'procedure';
KW_PROCESS: 'process';
KW_PROTECTED: 'protected';
KW_PURE: 'pure';
//KW_AMS_PROCEDURAL: 'procedural';

// Reserved words starting with Q
//KW_AMS_QUANTITY: 'quantity';

// Reserved words starting with R
KW_RANGE: 'range';
KW_RECORD: 'record';
KW_REGISTER: 'register';
KW_REJECT: 'reject';
KW_RELEASE: 'release';
OP_REM: 'rem';
KW_REPORT: 'report';
KW_RETURN: 'return';
OP_ROL: 'rol';
OP_ROR: 'ror';
KW_PSL_RESTRICT: 'restrict';
//KW_AMS_REFERENCE: 'reference';

// Reserved words starting with S
KW_SELECT: 'select';
KW_SEVERITY: 'severity';
KW_SHARED: 'shared';
KW_SIGNAL: 'signal';
OP_SLA: 'sla';
OP_SLL: 'sll';
OP_SRA: 'sra';
OP_SRL: 'srl';
KW_SUBTYPE: 'subtype';
KW_PSL_STRONG: 'strong';
KW_PSL_SEQUENCE: 'sequence';
//KW_AMS_SPECTRUM: 'spectrum';
//KW_AMS_SUBNATURE: 'subnature';

// Reserved words starting with T
KW_THEN: 'then';
KW_TO: 'to';
KW_TRANSPORT: 'transport';
KW_TYPE: 'type';
//KW_AMS_TERMINAL: 'terminal';
//KW_AMS_THROUGH: 'through';
//KW_AMS_TOLERANCE: 'tolerance';

// Reserved words starting with U
KW_UNAFFECTED: 'unaffected';
KW_UNITS: 'units';
KW_UNTIL: 'until';
KW_USE: 'use';

// Reserved words starting with V
KW_VARIABLE: 'variable';
KW_VIEW: 'view';
KW_PSL_VPKG: 'vpkg';
KW_PSL_VMODE: 'vmode';
KW_PSL_VPROP: 'vprop';
KW_PSL_VUNIT: 'vunit';

// Reserved words starting with W
KW_WAIT: 'wait';
KW_WITH: 'with';
KW_WHEN: 'when';
KW_WHILE: 'while';

// Reserved words starting with X
OP_XNOR: 'xnor';
OP_XOR: 'xor';

OP_EQ: '=';
OP_NE: '/=';
OP_LT: '<';
OP_LE: '<=)';
OP_GT: '>';
OP_GE: '>=';
OP_IEQ: '?=';
OP_INE: '?/=';
OP_ILT: '?<';
OP_ILE: '?<=)';
OP_IGT: '?>';
OP_IGE: '?>=';
OP_PLUS: '+';
OP_MINUS: '-';
OP_MUL: '*';
OP_DIV: '/';
OP_POW: '**';
OP_CONCAT: '&';
OP_CONDITION: '??';

TOK_RARROW: '=>';
TOK_SIG_ASSIGN: '<=';
TOK_VAR_ASSIGN: ':=';
TOK_BOX: '<>';
TOK_LP: '(';
TOK_RP: ')';
TOK_LB: '[';
TOK_RB: ']';
TOK_DLA: '<<';
TOK_DRA: '>>';
TOK_COLON: ':';
TOK_SEMICOL: ';';
TOK_COMMA: ',';
TOK_BAR: '|';
TOK_DOT: '.';
TOK_QUESTION: '?';
TOK_AT: '@';
TOK_CIRCUMFLEX: '^';
TOK_TICK: '\'';
TOK_DQUOTE: '"';

fragment Letter: [a-z] ;
fragment Digit: [0-9] ;
fragment ExtendedDigit: [0-9a-z] ;

fragment Integer: [0-9][_0-9]* ;
fragment BasedInteger: ExtendedDigit ('_' | ExtendedDigit)* ;
fragment Exponent: 'e' ( '+' | '-' )? Integer ;
fragment Real: Integer '.' Integer Exponent? ;

fragment BaseLiteral: Integer '#' BasedInteger ( '.' BasedInteger )? '#' Exponent? ;

LIT_ABSTRACT
: Integer
| Real
| BaseLiteral
;

fragment BinaryBitString: Integer? [us]? 'b' '"' ([0-1] | '_')+ '"' ;
fragment OctalBitString: Integer? [us]? 'o' '"' ([0-7] | '_')+ '"' ;
fragment DecimalBitString: Integer? 'd' '"' ([0-9] | '_')+ '"' ;
fragment HexBitString: Integer? [us]? 'x' '"' ([0-9a-f] | '_')+ '"' ;

LIT_BIT_STRING
: BinaryBitString
| OctalBitString
| DecimalBitString
| HexBitString
;

LIT_CHARACTER: '\'' . '\'' ;
LIT_STRING: '"' (~('"' | '\n' | '\r') | '""')* '"' ;

/*
LIT_OTHER_CHARACTER
: '!' | '$' | '%' | '@' | '?' | '^' | '`' | '{' | '}' | '~'
| ' ' | 'Ў' | 'ў' | 'Ј' | '¤' | 'Ґ' | '¦' | '§'
| 'Ё' | '©' | 'Є' | '«' | '¬' | '­' | '®' | 'Ї'
| '°' | '±' | 'І' | 'і' | 'ґ' | 'µ' | '¶' | '·'
| 'ё' | '№' | 'є' | '»' | 'ј' | 'Ѕ' | 'ѕ' | 'ї'
| 'А' | 'Б' | 'В' | 'Г' | 'Д' | 'Е' | 'Ж' | 'З'
| 'И' | 'Й' | 'К' | 'Л' | 'М' | 'Н' | 'О' | 'П'
| 'Р' | 'С' | 'Т' | 'У' | 'Ф' | 'Х' | 'Ц' | 'Ч'
| 'Ш' | 'Щ' | 'Ъ' | 'Ы' | 'Ь' | 'Э' | 'Ю' | 'Я'
| 'а' | 'б' | 'в' | 'г' | 'д' | 'е' | 'ж' | 'з'
| 'и' | 'й' | 'к' | 'л' | 'м' | 'н' | 'о' | 'п'
| 'р' | 'с' | 'т' | 'у' | 'ф' | 'х' | 'ц' | 'ч'
| 'ш' | 'щ' | 'ъ' | 'ы' | 'ь' | 'э' | 'ю' | 'я'
;
*/

fragment BasicIdentifier: [a-z] ('_'? [a-z0-9])* ;
fragment ExtendedIdentifier: '\\' ([a-z0-9] | '_')+ '\\' ;

LIT_IDENTIFIER
: BasicIdentifier
| ExtendedIdentifier
;
Loading