Skip to content
Snippets Groups Projects
Commit 46ced3f2 authored by Xun Yang's avatar Xun Yang
Browse files

filename check

parent d94ee941
No related branches found
No related tags found
No related merge requests found
...@@ -4,6 +4,7 @@ from os.path import isfile, join ...@@ -4,6 +4,7 @@ from os.path import isfile, join
from Scanning import scan from Scanning import scan
from Parsing import parse from Parsing import parse
import Weeding
def allFiles(testDir): def allFiles(testDir):
...@@ -19,28 +20,42 @@ def main(): ...@@ -19,28 +20,42 @@ def main():
for f in testFiles: for f in testFiles:
# print(f) # print(f)
# Scanning # Scanning
content = open(f, "r").read() content = open(f, "r").read()
(tokens, errorString) = scan(content) (tokens, errorString) = scan(content)
# Error in Scanning # Error in Scanning
if tokens is None: if tokens is None:
# print("ERROR in Scanning: " + errorString) # print("ERROR in Scanning: " + errorString)
print("**********************************************************") print("**********************************************************")
continue continue
# s = "All Tokens: " s = "All Tokens: "
# for token in tokens: for token in tokens:
# if (token.name and token.lex): if (token.name and token.lex):
# s += '(' + token.name + ',' + token.lex + '), ' s += '(' + token.name + ',' + token.lex + '), '
# print(s) print(s)
# No weeds if everything is good (weeds = None)
weeds = Weeding.fileNameCheck(tokens, f)
if weeds:
print(weeds)
continue
# Parsing # Parsing
# print("Parsing starts") # print("Parsing starts")
try: # try:
(steps, errorString) = parse(tokens) # (steps, errorString) = parse(tokens)
except: # except:
print("Exception in Parsing") # print("Exception in Parsing")
#
# # Error in Parsing
# if steps is None:
# print("ERROR in Parsing: ", errorString)
# print("**********************************************************")
# continue
# Error in Parsing # Error in Parsing
if steps is None: if steps is None:
...@@ -54,4 +69,4 @@ def main(): ...@@ -54,4 +69,4 @@ def main():
print("**********************************************************") print("**********************************************************")
main() main()
\ No newline at end of file
import string import string
import os
##################### Weeding ########################################## ##################### 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[] # node: Node[]
def oneConstructor(node, insideClass): def oneConstructor(node, insideClass):
...@@ -14,7 +30,7 @@ def oneConstructor(node, insideClass): ...@@ -14,7 +30,7 @@ def oneConstructor(node, insideClass):
elif insideClass: elif insideClass:
if node.name == 'constructorDcl': if node.name == 'constructorDcl':
return True return True
# tree: Node[] # tree: Node[]
def weed(tree): def weed(tree):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment