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
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()
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):
......
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