__version__ = "3.4"
__tabversion__ = "3.2" # Version of table file used
-import re, sys, types, copy, os, inspect
+import re, sys, types, copy, os
# This tuple contains known string types
try:
self.tokens = []
self.reflags = reflags
self.stateinfo = { 'INITIAL' : 'inclusive'}
- self.modules = {}
+ self.files = {}
self.error = 0
if log is None:
for fname, f in self.funcsym[state]:
line = func_code(f).co_firstlineno
file = func_code(f).co_filename
- module = inspect.getmodule(f)
- self.modules[module] = 1
+ self.files[file] = 1
tokname = self.toknames[fname]
if isinstance(f, types.MethodType):
f = efunc
line = func_code(f).co_firstlineno
file = func_code(f).co_filename
- module = inspect.getmodule(f)
- self.modules[module] = 1
+ self.files[file] = 1
if isinstance(f, types.MethodType):
reqargs = 2
self.log.error("%s:%d: Rule '%s' requires an argument", file,line,f.__name__)
self.error = 1
- for module in self.modules:
- self.validate_module(module)
+ for f in self.files:
+ self.validate_file(f)
# -----------------------------------------------------------------------------
- # validate_module()
+ # validate_file()
#
# This checks to see if there are duplicated t_rulename() functions or strings
# in the parser input file. This is done using a simple regular expression
- # match on each line in the source code of the given module.
+ # match on each line in the given file.
# -----------------------------------------------------------------------------
- def validate_module(self, module):
- lines, linen = inspect.getsourcelines(module)
+ def validate_file(self,filename):
+ import os.path
+ base,ext = os.path.splitext(filename)
+ if ext != '.py': return # No idea what the file is. Return OK
+
+ try:
+ f = open(filename)
+ lines = f.readlines()
+ f.close()
+ except IOError:
+ return # Couldn't find the file. Don't worry about it
fre = re.compile(r'\s*def\s+(t_[a-zA-Z_0-9]*)\(')
sre = re.compile(r'\s*(t_[a-zA-Z_0-9]*)\s*=')
counthash = { }
- linen += 1
+ linen = 1
for l in lines:
m = fre.match(l)
if not m:
if not prev:
counthash[name] = linen
else:
- filename = inspect.getsourcefile(module)
self.log.error("%s:%d: Rule %s redefined. Previously defined on line %d",filename,linen,name,prev)
self.error = 1
linen += 1
pickle_protocol = 0 # Protocol to use when writing pickle files
-import re, types, sys, os.path, inspect
+import re, types, sys, os.path
# Compatibility function for python 2.6/3.0
if sys.version_info[0] < 3:
return len(self.prod)
def __nonzero__(self):
- return True
+ return 1
def __getitem__(self,index):
return self.prod[index]
self.start = None
self.error_func = None
self.tokens = None
- self.modules = {}
+ self.files = {}
self.grammar = []
self.error = 0
self.validate_tokens()
self.validate_precedence()
self.validate_pfunctions()
- self.validate_modules()
+ self.validate_files()
return self.error
# Compute a signature over the grammar
return sig.digest()
# -----------------------------------------------------------------------------
- # validate_modules()
+ # validate_file()
#
# This method checks to see if there are duplicated p_rulename() functions
# in the parser module file. Without this function, it is really easy for
# to try and detect duplicates.
# -----------------------------------------------------------------------------
- def validate_modules(self):
+ def validate_files(self):
# Match def p_funcname(
fre = re.compile(r'\s*def\s+(p_[a-zA-Z_0-9]*)\(')
- for module in self.modules.keys():
- lines, linen = inspect.getsourcelines(module)
+ for filename in self.files.keys():
+ base,ext = os.path.splitext(filename)
+ if ext != '.py': return 1 # No idea. Assume it's okay.
+
+ try:
+ f = open(filename)
+ lines = f.readlines()
+ f.close()
+ except IOError:
+ continue
counthash = { }
for linen,l in enumerate(lines):
if not prev:
counthash[name] = linen
else:
- filename = inspect.getsourcefile(module)
self.log.warning("%s:%d: Function %s redefined. Previously defined on line %d", filename,linen,name,prev)
# Get the start symbol
eline = func_code(self.error_func).co_firstlineno
efile = func_code(self.error_func).co_filename
- module = inspect.getmodule(self.error_func)
- self.modules[module] = 1
+ self.files[efile] = 1
if (func_code(self.error_func).co_argcount != 1+ismethod):
self.log.error("%s:%d: p_error() requires 1 argument",efile,eline)
if name == 'p_error': continue
if isinstance(item,(types.FunctionType,types.MethodType)):
line = func_code(item).co_firstlineno
- module = inspect.getmodule(item)
- p_functions.append((line,module,name,item.__doc__))
+ file = func_code(item).co_filename
+ p_functions.append((line,file,name,item.__doc__))
# Sort all of the actions by line number
p_functions.sort()
self.error = 1
return
- for line, module, name, doc in self.pfuncs:
- file = inspect.getsourcefile(module)
+ for line, file, name, doc in self.pfuncs:
func = self.pdict[name]
if isinstance(func, types.MethodType):
reqargs = 2
# Looks like a valid grammar rule
# Mark the file in which defined.
- self.modules[module] = 1
+ self.files[file] = 1
# Secondary validation step that looks for p_ definitions that are not functions
# or functions that look like they might be grammar rules.