[DEV] better parsing

This commit is contained in:
Edouard DUPIN 2017-08-17 21:32:55 +02:00
parent b34ab69747
commit 9bd3e16588
3 changed files with 65 additions and 8 deletions

View File

@ -81,6 +81,8 @@ prude.init()
actionDone = False; actionDone = False;
summary = []
# parse all argument # parse all argument
number_of_error = 0 number_of_error = 0
for argument in localArgument: for argument in localArgument:
@ -93,7 +95,39 @@ for argument in localArgument:
debug.warning("Can not understand argument : '" + argument.get_option_name() + "'") debug.warning("Can not understand argument : '" + argument.get_option_name() + "'")
usage() usage()
break; 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 actionDone = True
# if no action done : we do "all" ... # if no action done : we do "all" ...
@ -102,4 +136,13 @@ if actionDone == False:
exit(-1) exit(-1)
if number_of_error != 0: 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); exit(-1);
debug.info("[ OK ]")
exit(0);

View File

@ -90,6 +90,8 @@ def get_local_filter():
# specific control check # specific control check
if elem == "!NO_CAPITAL_LETTER": if elem == "!NO_CAPITAL_LETTER":
filter_list[0]["check-capital"] = False filter_list[0]["check-capital"] = False
elif elem == "!CAPITAL_LETTER":
filter_list[0]["check-capital"] = True
else: else:
debug.error("unknows parameter: '" + elem + "'") debug.error("unknows parameter: '" + elem + "'")
continue continue

View File

@ -61,7 +61,8 @@ generic_cpp_type = [
"bvec2", "bvec2",
"bvec3", "bvec3",
"Edouard", "Edouard",
"DUPIN" "DUPIN",
"__asm__",
] ]
tolerate_words = [ tolerate_words = [
@ -74,10 +75,11 @@ tolerate_words = [
# classicle programation achronimes: # classicle programation achronimes:
"pc", "cpu", "gpio", "io", "proc", "ctrl", "rx", "tx", "msg", "async", "sync", "ack", "src", "freq", "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", "unicode", "utf", "xml", "json", "bmp", "jpg", "jpeg", "tga", "gif", "http", "https",
"sys", "arg", "args", "argc", "argv", "init", "main", "fnmatch", "env", "len", "desc", "str", "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 #classical libraries
"lua", "lua",
@ -85,7 +87,7 @@ tolerate_words = [
"param", "param",
#language word: #language word:
"ifdef", "ifndef","endif", "elif", "ifdef", "ifndef","endif", "elif", "elseif",
# licences: # licences:
"mpl", "bsd", "lgpl", "gpl", "mpl", "bsd", "lgpl", "gpl",
@ -93,6 +95,7 @@ tolerate_words = [
# units: # units:
"hz", "khz", "mhz", "thz", "hz", "khz", "mhz", "thz",
"ms", "us", "ns", "min", "sec", "ms", "us", "ns", "min", "sec",
"mv", "kv",
# some hewxa values: # some hewxa values:
"xf", "xff", "xfff", "xffff", "xfffff", "xffffff", "xf", "xff", "xfff", "xffff", "xfffff", "xffffff",
@ -101,11 +104,16 @@ tolerate_words = [
"xll", "xll",
#libc funtions #libc funtions
"memcpy", "strncpy", "printf", "sprintf", "fopen", "malloc", "calloc", "kalloc", "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 application_filter = None
previous_sugestion = {}
def annalyse(filename): def annalyse(filename):
global application_filter global application_filter
@ -243,7 +251,7 @@ def annalyse(filename):
debug.extreme_verbose("reject global names " + elem["word"]); debug.extreme_verbose("reject global names " + elem["word"]);
continue continue
for elem_sub in elem["word-list"]: for elem_sub in elem["word-list"]:
if application_filter[0]["check-capital"]: if application_filter[0]["check-capital"] == False:
capital = True capital = True
for elemmm in elem_sub[1]: for elemmm in elem_sub[1]:
if elemmm in "ABCDEFGHIJKLMNOPQRSTUVWXYZ": 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(filename + ":" + str(elem["line-id"]) + ":error: unknown word: '" + tmp_elem + "'")
debug.print_compilator(" '" + str(elem["line"]) + "'") debug.print_compilator(" '" + str(elem["line"]) + "'")
debug.print_compilator(" " + " "*(elem["pos"]+elem_sub[0]) + "^") 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: if len(list_of_words) != 0:
debug.print_compilator(" try: " + str(list_of_words)) debug.print_compilator(" try: " + str(list_of_words))
if number_of_error != 0: if number_of_error != 0: