Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
V
vhdl-style
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
image/svg+xml
Discourse
Discourse
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Commits
Open sidebar
misc
vhdl-style
Commits
4da68d6b
Commit
4da68d6b
authored
Mar 20, 2018
by
Tristan Gingold
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improve check_name_decl rule: can now give a dedicated error message.
parent
f78b4f38
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
33 additions
and
10 deletions
+33
-10
vhdllint-ohwr
vhdllint-ohwr
+8
-5
check_name_decl.py
vhdllint/syntaxrules/check_name_decl.py
+25
-5
No files found.
vhdllint-ohwr
View file @
4da68d6b
...
...
@@ -147,11 +147,14 @@ rules.add(CheckNameDecl(kind=iirs.Iir_Kind.Architecture_Body,
name
=
'ArchNames'
))
# [Constants] [M] Constants name
rules
.
add
(
CheckNameDecl
(
kind
=
iirs
.
Iir_Kind
.
Constant_Declaration
,
predicate
=
(
lambda
n
:
len
(
n
)
>=
3
and
n
[:
2
]
==
'c_'
and
n
[
2
:]
.
isupper
()),
name
=
'Constants'
))
rules
.
add
(
CheckNameDecl
(
kind
=
iirs
.
Iir_Kind
.
Constant_Declaration
,
predicate
=
[
lambda
s
:
(
"constant name '{}' must start with 'c_'"
.
format
(
s
)
if
not
s
.
startswith
(
'c_'
)
else
None
),
lambda
s
:
(
"constant name '{}' must be in upper case after 'c_'"
.
format
(
s
)
if
not
s
[
2
:]
.
isupper
()
else
None
)],
name
=
'Constants'
))
# [GenericsName] [M] Generics name
rules
.
add
(
CheckGenerics
(
name
=
'GenericsName'
))
...
...
vhdllint/syntaxrules/check_name_decl.py
View file @
4da68d6b
...
...
@@ -19,17 +19,37 @@ class CheckNameDecl(SyntaxNodeRule):
self
.
kind
=
kind
self
.
predicate
=
predicate
def
check_predicate
(
self
,
p
,
node
,
s
):
"""Test predicate :param p: on string :param s:. The predicate shall
return an error message in case of error or None if the name is
correct."""
res
=
p
(
s
)
if
isinstance
(
res
,
str
):
self
.
error
(
Location
.
from_node
(
node
),
res
)
return
True
elif
res
is
None
or
res
:
return
False
else
:
self
.
error
(
Location
.
from_node
(
node
),
"incorrect name '{}'"
.
format
(
s
))
return
True
def
check
(
self
,
input
,
node
):
if
iirs
.
Get_Kind
(
node
)
==
self
.
kind
:
s
=
nodeutils
.
get_identifier_str
(
node
)
if
not
self
.
predicate
(
s
):
self
.
error
(
Location
.
from_node
(
node
),
"incorrect name '{}'"
.
format
(
s
))
if
isinstance
(
self
.
predicate
,
list
):
for
p
in
self
.
predicate
:
if
self
.
check_predicate
(
p
,
node
,
s
):
break
else
:
self
.
check_predicate
(
self
.
predicate
,
node
,
s
)
@
staticmethod
def
test
(
runner
):
rule
=
CheckNameDecl
(
kind
=
iirs
.
Iir_Kind
.
Constant_Declaration
,
predicate
=
(
lambda
s
:
s
!=
'Reserved'
))
rule
=
CheckNameDecl
(
kind
=
iirs
.
Iir_Kind
.
Constant_Declaration
,
predicate
=
(
lambda
s
:
(
"name {} must not be 'Reserved'"
.
format
(
s
)
if
s
==
'Reserved'
else
None
)))
TestRunOK
(
runner
,
"File without attributes"
,
rule
,
"hello.vhdl"
)
TestRunFail
(
runner
,
"Incorrect name"
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment