0

I need to parse an open-source project Postgresql using pycparser.

While parsing its source-code the following error arises:

Traceback (most recent call last):
File "examples\using_cpp_libc.py", line 48, in <module>
getAllFiles(projectName)
File "examples\using_cpp_libc.py", line 29, in getAllFiles
ast = parse_file(dirName+'\\'+fname, use_cpp = True, cpp_path = 'cpp', 
cpp_args = [r'-nostdinc',r'-Iutils/fake_libc_include',r'- 
Iprojects/postgresql/src/include'])
File "G:\python\pycparser-master\pycparser\__init__.py", line 92, in 
parse_file
return parser.parse(text, filename)
File "G:\python\pycparser-master\pycparser\c_parser.py", line 152, in parse
debug=debuglevel)
File "G:\python\pycparser-master\pycparser\ply\yacc.py", line 334, in parse
return self.parseopt_notrack(input, lexer, debug, tracking, tokenfunc)
File "G:\python\pycparser-master\pycparser\ply\yacc.py", line 1204, in 
parseopt_notrack
tok = call_errorfunc(self.errorfunc, errtoken, self)
File "G:\python\pycparser-master\pycparser\ply\yacc.py", line 193, in 
call_errorfunc
r = errorfunc(token)
File "G:\python\pycparser-master\pycparser\c_parser.py", line 1838, in 
p_error
column=self.clex.find_tok_column(p)))
File "G:\python\pycparser-master\pycparser\plyparser.py", line 67, in 
_parse_error
raise ParseError("%s: %s" % (coord, msg))
pycparser.plyparser.ParseError: 
projects/postgresql/src/include/pg_config_os.h:366:15: before: 
pgwin32_signal_event

I am using postgresql-9.6.9, build it using visual studio express 2017 on windows 10 (64-bit)

  • I have studied this blogpost to resolve above error but couldn't get things right: https://eli.thegreenplace.net/2015/on-parsing-c-type-declarations-and-fake-headers/ – Aditi Gupta Nov 01 '18 at 08:48

1 Answers1

0

The blog post you quoted in the comment is the canonical resource. Parsing large C projects is not easy - they have their own quirks - so it takes work. I doubt it's resolvable within the confines of a Stack Overflow question.

You need to start tackling the issues one by one - for example look at the pgwin32_signal_event token in pg_config_os.h - why can't it be parsed? Perhaps its type is unparsable? Was it defined? Could it be added to a "fake" header, etc. Unfortunately, there's no easy way to do this except working through the issues one by one.

Be sure to preprocess the file you're parsing first, dumping the full preprocessed version into a single .c file - this gets all the types into a single file you can work with.

Eli Bendersky
  • 263,248
  • 89
  • 350
  • 412