def p_error(p): if p is not None: value = p.value value = ''.join(['|%s|' % hex(ord(x)) if x < ' ' else x for x in value]) error(p.lineno, "syntax error. Unexpected token '%s' [%s]" % (value, p.type)) else: OPTIONS.stderr.value.write("General syntax error at preprocessor " "(unexpected End of File?)") global_.has_errors += 1
def p_program_tokenstring(p): """ program : defs NEWLINE """ try: tmp = [str(x()) if isinstance(x, MacroCall) else x for x in p[1]] except PreprocError as v: error(v.lineno, v.message) tmp.append(p[2]) p[0] = tmp
def p_program_newline(p): """ program : program defs NEWLINE """ try: tmp = [str(x()) if isinstance(x, MacroCall) else x for x in p[2]] except PreprocError as v: error(v.lineno, v.message) p[0] = [] return p[0] = p[1] p[0].extend(tmp) p[0].append(p[3])
def p_define_params_paramlist(p): """ params : LP paramlist RP """ for i in p[2]: if not isinstance(i, ID): error(p.lineno(3), '"%s" might not appear in a macro parameter list' % str(i)) p[0] = None return names = [x.name for x in p[2]] for i in range(len(names)): if names[i] in names[i + 1:]: error(p.lineno(3), 'Duplicated name parameter "%s"' % (names[i])) p[0] = None return p[0] = p[2]
def search_filename(fname, lineno, local_first): """ Search a filename into the list of the include path. If local_first is true, it will try first in the current directory of the file being analyzed. """ fname = api.utils.sanitize_filename(fname) i_path = [CURRENT_DIR] + INCLUDEPATH if local_first else list(INCLUDEPATH) i_path.extend(OPTIONS.include_path.value.split(':') if OPTIONS.include_path.value else []) if os.path.isabs(fname): if os.path.isfile(fname): return fname else: for dir_ in i_path: path = api.utils.sanitize_filename(os.path.join(dir_, fname)) if os.path.exists(path): return path error(lineno, "file '%s' not found" % fname) return ''
def error(self, msg): """ Prints an error msg and continues execution. """ error(self.lex.lineno, msg)
def p_errormsg(p): """ errormsg : ERROR STRING """ if ENABLED: error(p.lineno(1), p[2]) p[0] = []