[DEV] better parsing
This commit is contained in:
parent
b34ab69747
commit
9bd3e16588
45
bin/prude
45
bin/prude
@ -81,6 +81,8 @@ prude.init()
|
||||
|
||||
actionDone = False;
|
||||
|
||||
summary = []
|
||||
|
||||
# parse all argument
|
||||
number_of_error = 0
|
||||
for argument in localArgument:
|
||||
@ -93,7 +95,39 @@ for argument in localArgument:
|
||||
debug.warning("Can not understand argument : '" + argument.get_option_name() + "'")
|
||||
usage()
|
||||
break;
|
||||
number_of_error += module.annalyse(argument_value)
|
||||
if os.path.isfile(argument_value) == True:
|
||||
# Single file:
|
||||
tmp_count_error = module.annalyse(argument_value)
|
||||
summary.append([argument_value, tmp_count_error])
|
||||
number_of_error += tmp_count_error
|
||||
else:
|
||||
# a full path
|
||||
list_files = os.listdir(argument_value)
|
||||
real_list = []
|
||||
for ff_file in list_files:
|
||||
if os.path.isfile(os.path.join(argument_value,ff_file)) == False:
|
||||
continue
|
||||
if len(ff_file) > 3 \
|
||||
and ( ff_file[-4:].lower() == ".cpp" \
|
||||
or ff_file[-4:].lower() == ".hpp" \
|
||||
or ff_file[-4:].lower() == ".c++" \
|
||||
or ff_file[-2:].lower() == ".c" \
|
||||
or ff_file[-4:].lower() == ".h++" \
|
||||
or ff_file[-2:].lower() == ".h" \
|
||||
or ff_file[-3:].lower() == ".hh" \
|
||||
or ff_file[-3:].lower() == ".cc" \
|
||||
or ff_file[-3:].lower() == ".py" \
|
||||
or ff_file[-4:].lower() == ".lua" \
|
||||
or ff_file[-3:].lower() == ".md"):
|
||||
real_list.append(os.path.join(argument_value,ff_file))
|
||||
# sort list to have all time the same order.
|
||||
real_list.sort()
|
||||
# TODO: Add filter if needed.
|
||||
for ff_file in real_list:
|
||||
debug.info("-----------------------------------------------")
|
||||
tmp_count_error = module.annalyse(ff_file)
|
||||
summary.append([ff_file, tmp_count_error])
|
||||
number_of_error += tmp_count_error
|
||||
actionDone = True
|
||||
|
||||
# if no action done : we do "all" ...
|
||||
@ -102,4 +136,13 @@ if actionDone == False:
|
||||
exit(-1)
|
||||
|
||||
if number_of_error != 0:
|
||||
debug.info("Detected " + str(number_of_error) + " ERROR(s) on " + str(len(summary)) + " files")
|
||||
for elem in summary:
|
||||
if elem[1] != 0:
|
||||
debug.info(elem[0] + "\r\t\t\t\t\t\t [ERROR] " + str(elem[1]))
|
||||
else:
|
||||
debug.info(elem[0] + "\r\t\t\t\t\t\t [ OK ]")
|
||||
exit(-1);
|
||||
|
||||
debug.info("[ OK ]")
|
||||
exit(0);
|
||||
|
@ -90,6 +90,8 @@ def get_local_filter():
|
||||
# specific control check
|
||||
if elem == "!NO_CAPITAL_LETTER":
|
||||
filter_list[0]["check-capital"] = False
|
||||
elif elem == "!CAPITAL_LETTER":
|
||||
filter_list[0]["check-capital"] = True
|
||||
else:
|
||||
debug.error("unknows parameter: '" + elem + "'")
|
||||
continue
|
||||
|
@ -61,7 +61,8 @@ generic_cpp_type = [
|
||||
"bvec2",
|
||||
"bvec3",
|
||||
"Edouard",
|
||||
"DUPIN"
|
||||
"DUPIN",
|
||||
"__asm__",
|
||||
]
|
||||
|
||||
tolerate_words = [
|
||||
@ -74,10 +75,11 @@ tolerate_words = [
|
||||
|
||||
# classicle programation achronimes:
|
||||
"pc", "cpu", "gpio", "io", "proc", "ctrl", "rx", "tx", "msg", "async", "sync", "ack", "src", "freq",
|
||||
"ui", "params", "ip", "log", "udp", "tcp", "ftp",
|
||||
"ui", "params", "ip", "log", "udp", "tcp", "ftp", "led", "leds", "isr", "dsr", "irq", "wifi", "spi", "ic",
|
||||
"unicode", "utf", "xml", "json", "bmp", "jpg", "jpeg", "tga", "gif", "http", "https",
|
||||
"sys", "arg", "args", "argc", "argv", "init", "main", "fnmatch", "env", "len", "desc", "str",
|
||||
"cmd", "dir", "bsy", "id",
|
||||
"cmd", "dir", "bsy", "id", "destructor", "utils", "configs", "config", "crc", "rgb", "bootloader", "rom", "fs",
|
||||
"todo",
|
||||
#classical libraries
|
||||
"lua",
|
||||
|
||||
@ -85,7 +87,7 @@ tolerate_words = [
|
||||
"param",
|
||||
|
||||
#language word:
|
||||
"ifdef", "ifndef","endif", "elif",
|
||||
"ifdef", "ifndef","endif", "elif", "elseif",
|
||||
|
||||
# licences:
|
||||
"mpl", "bsd", "lgpl", "gpl",
|
||||
@ -93,6 +95,7 @@ tolerate_words = [
|
||||
# units:
|
||||
"hz", "khz", "mhz", "thz",
|
||||
"ms", "us", "ns", "min", "sec",
|
||||
"mv", "kv",
|
||||
|
||||
# some hewxa values:
|
||||
"xf", "xff", "xfff", "xffff", "xfffff", "xffffff",
|
||||
@ -101,11 +104,16 @@ tolerate_words = [
|
||||
"xll",
|
||||
#libc funtions
|
||||
"memcpy", "strncpy", "printf", "sprintf", "fopen", "malloc", "calloc", "kalloc",
|
||||
"noinline", "ramtext", "constexpr", "typename", "inline", "memet",
|
||||
"noinline", "ramtext", "constexpr", "typename", "inline", "memset", "getchar", "putchar",
|
||||
"fread", "fwrite", "gets", "puts",
|
||||
#pb with number parsing:
|
||||
"ull",
|
||||
|
||||
]
|
||||
|
||||
application_filter = None
|
||||
|
||||
previous_sugestion = {}
|
||||
|
||||
def annalyse(filename):
|
||||
global application_filter
|
||||
@ -243,7 +251,7 @@ def annalyse(filename):
|
||||
debug.extreme_verbose("reject global names " + elem["word"]);
|
||||
continue
|
||||
for elem_sub in elem["word-list"]:
|
||||
if application_filter[0]["check-capital"]:
|
||||
if application_filter[0]["check-capital"] == False:
|
||||
capital = True
|
||||
for elemmm in elem_sub[1]:
|
||||
if elemmm in "ABCDEFGHIJKLMNOPQRSTUVWXYZ":
|
||||
@ -272,7 +280,11 @@ def annalyse(filename):
|
||||
debug.print_compilator(filename + ":" + str(elem["line-id"]) + ":error: unknown word: '" + tmp_elem + "'")
|
||||
debug.print_compilator(" '" + str(elem["line"]) + "'")
|
||||
debug.print_compilator(" " + " "*(elem["pos"]+elem_sub[0]) + "^")
|
||||
list_of_words = difflib.get_close_matches(tmp_elem, english.list_english_word)
|
||||
if tmp_elem in previous_sugestion:
|
||||
list_of_words = previous_sugestion[tmp_elem]
|
||||
else:
|
||||
list_of_words = difflib.get_close_matches(tmp_elem, english.list_english_word)
|
||||
previous_sugestion[tmp_elem] = list_of_words
|
||||
if len(list_of_words) != 0:
|
||||
debug.print_compilator(" try: " + str(list_of_words))
|
||||
if number_of_error != 0:
|
||||
|
Loading…
Reference in New Issue
Block a user