Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

skip any non-ASCII characters in the files #28

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions pycscope/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,19 @@
import getopt, sys, os, string, re
import keyword, parser, symbol, token

_re_ascii_filter = '[^%s]' % (re.escape(string.printable), )

def ascii_dammit( sourcecode, _re_expr = re.compile( _re_ascii_filter ) ):
"""
just ignore all non-ascii characters
since any identifiers should be ASCII anyway ;
nb: this will work for utf-8 as well

"""

result = _re_expr.sub( '', sourcecode )
return result


class Mark(object):
""" Marks, as defined by Cscope, that are implemented.
Expand Down Expand Up @@ -238,10 +251,16 @@ def parseFile(basepath, relpath, indexbuff, indexbuff_len, fnamesbuff, dump=Fals
# Add path info to any syntax errors in the source files
if filecontents:
try:
filecontents = ascii_dammit( filecontents )
indexbuff_len = parseSource(filecontents, indexbuff, indexbuff_len, dump)
except (SyntaxError, AssertionError) as e:
e.filename = fullpath
raise e
except Exception as e:
# debug a fatal exception:
e.filename = fullpath
print( "pycscope.py: %s in %s" % ( e, repr(fullpath) ) )
raise e

return indexbuff_len

Expand Down