Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
cs444
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Xun Yang
cs444
Commits
46ced3f2
Commit
46ced3f2
authored
5 years ago
by
Xun Yang
Browse files
Options
Downloads
Patches
Plain Diff
filename check
parent
d94ee941
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
Test.py
+28
-13
28 additions, 13 deletions
Test.py
Weeding.py
+17
-1
17 additions, 1 deletion
Weeding.py
with
45 additions
and
14 deletions
Test.py
+
28
−
13
View file @
46ced3f2
...
...
@@ -4,6 +4,7 @@ from os.path import isfile, join
from
Scanning
import
scan
from
Parsing
import
parse
import
Weeding
def
allFiles
(
testDir
):
...
...
@@ -19,28 +20,42 @@ def main():
for
f
in
testFiles
:
# print(f)
# Scanning
# Scanning
content
=
open
(
f
,
"
r
"
).
read
()
(
tokens
,
errorString
)
=
scan
(
content
)
# Error in Scanning
# Error in Scanning
if
tokens
is
None
:
# print("ERROR in Scanning: " + errorString)
print
(
"
**********************************************************
"
)
continue
# s = "All Tokens: "
# for token in tokens:
# if (token.name and token.lex):
# s += '(' + token.name + ',' + token.lex + '), '
# print(s)
s
=
"
All Tokens:
"
for
token
in
tokens
:
if
(
token
.
name
and
token
.
lex
):
s
+=
'
(
'
+
token
.
name
+
'
,
'
+
token
.
lex
+
'
),
'
print
(
s
)
# No weeds if everything is good (weeds = None)
weeds
=
Weeding
.
fileNameCheck
(
tokens
,
f
)
if
weeds
:
print
(
weeds
)
continue
# Parsing
# print("Parsing starts")
try
:
(
steps
,
errorString
)
=
parse
(
tokens
)
except
:
print
(
"
Exception in Parsing
"
)
# try:
# (steps, errorString) = parse(tokens)
# except:
# print("Exception in Parsing")
#
# # Error in Parsing
# if steps is None:
# print("ERROR in Parsing: ", errorString)
# print("**********************************************************")
# continue
# Error in Parsing
if
steps
is
None
:
...
...
@@ -54,4 +69,4 @@ def main():
print
(
"
**********************************************************
"
)
main
()
\ No newline at end of file
main
()
This diff is collapsed.
Click to expand it.
Weeding.py
+
17
−
1
View file @
46ced3f2
import
string
import
os
##################### Weeding ##########################################
def
fileNameCheck
(
tokens
,
f
):
fileName
=
os
.
path
.
basename
(
f
).
split
(
'
.java
'
)[
0
]
check
=
False
for
t
in
tokens
:
if
check
:
if
(
t
.
lex
!=
fileName
):
print
(
t
.
lex
,
fileName
)
return
(
"
ERROR: Class or Interface name should be the same as file name.
"
)
return
None
if
t
.
name
==
'
INTERFACE
'
or
t
.
name
==
'
CLASS
'
:
check
=
True
return
None
# node: Node[]
def
oneConstructor
(
node
,
insideClass
):
...
...
@@ -14,7 +30,7 @@ def oneConstructor(node, insideClass):
elif
insideClass
:
if
node
.
name
==
'
constructorDcl
'
:
return
True
# tree: Node[]
def
weed
(
tree
):
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment