Few new preproc improvement

This commit is contained in:
Némunaire 2011-11-17 22:55:35 +01:00
parent 19221eba77
commit 7407966f2d
2 changed files with 33 additions and 3 deletions

30
c.py
View File

@ -34,6 +34,7 @@ def validatePreprocDirective(path, content, start, start_lign, states):
lign += 1
cOnLine = -1
if content[current - 1] == '\t':
perr(path, "Tabulation are baned!", lign)
if cOnLine % 8 == 0:
cOnLine += 8 + 1
else:
@ -55,7 +56,7 @@ def validatePreprocDirective(path, content, start, start_lign, states):
perr(path, "Bad endline preprocessor alignement (expected: {0}, real: {1})".format(eolAlign, cOnLine), lign)
#Spaces state
if state == 2 or state == 4:
if state == 2 or state == 4 or state == 6 or state == 8:
if content[current] != ' ' and content[current] != '\t':
state += 1
@ -66,6 +67,27 @@ def validatePreprocDirective(path, content, start, start_lign, states):
else:
state += 1
#Validate Macro Name
if state == 3:
if content[current] != ' ' and content[current] != '\t' and content[current] != '(':
restol += content[current]
else:
state += 1
if re.match("^[A-Z0-9_]$", restol) is None:
perr(path, "Preprocessor macro name not fully capitalized or contain invalid chars ({0})".format(restol), lign)
restol = ""
#Validate Macro Var
if state == 5:
if content[current] != ' ' and content[current] != '\t' and content[current] != ',':
restol += content[current]
else:
if content[current] != ')':
state += 1
if restol != "" and re.match("^[A-Z][a-z0-9_]$", restol) is None:
perr(path, "Preprocessor macro variable name not fully capitalized or contains invalid chars ({0})".format(restol), lign)
restol = ""
if directive.find("endif") == 0:
states['preproc-ident'] -= 1
@ -421,6 +443,12 @@ def validateFunction(path, content, start, start_lign, states, prototype):
elif content[current] != '\n':
cOnLine += 1
#String
if content[current] == '"':
eatenChar = validateString(path, content, current, lign)
current += eatenChar
cOnLine += eatenChar
if content[current - 2] == 'f' and content[current - 1] == 'o' and content[current] == 'r':
eaten = validateFor(path, content, current, lign, states)
cOnLine = eaten['col'];

View File

@ -2,7 +2,9 @@
def perr(path, descr, line):
if line >= 0:
print("\033[3m{0}\033[m in `{1}' on line {2}".format(descr, path, line))
#print("\033[3m{0}\033[m in `{1}' on line {2}".format(descr, path, line))
print("{0} in `{1}' on line {2}".format(descr, path, line))
else:
print("\033[3m{0}\033[m in `{1}'".format(descr, path))
#print("\033[3m{0}\033[m in `{1}'".format(descr, path))
print("{0} in `{1}'".format(descr, path))