New submission from alon horev:
Some context for this feature request:
I'm using the wonderful ast module for a library that translates python code to
MongoDB queries (https://github.com/alonho/pql). I also did the same for SQL
queries using sqlalchemy as a part of another project
(https://github.com/alonho/pytrace).
One of the things I find lacking in python's parser is additional information
about SyntaxErrors. This could help users of the 'ast' module, IDE and
developers.
Here are some examples of what I'd like to see
1. ast.parse('* 2') -> SyntaxError('Unexpected operator at start of an
expression')
2. ast.parse('2 *') -> SyntaxError('Missing right hand side operand')
3. ast.parse('if a = 1: pass') -> SyntaxError('Cannot assign inside an
expression')
There are several challenges here:
1. Does the parser have this information and doesn't surface it?
2. Can such messages be automatically generated without filling the code with
error handling code? 3. Which part of the code could be responsible for this
kind of a task? I've looked at the BNF and it contains more than just syntax
legality but operator precedence and such. Perhaps there's another (simpler)
grammar definition somewhere?
I was curious to see what Ruby does, and it uses a simple solution of providing
raw information along with the exception:
>> a == * 1
SyntaxError: compile error
(irb):17: syntax error, unexpected tSTAR
a == * 1
^
from (irb):17
----------
components: Interpreter Core
messages: 198341
nosy: alonho
priority: normal
severity: normal
status: open
title: Enrich SyntaxError with additional information
type: enhancement
_______________________________________
Python tracker <[email protected]>
<http://bugs.python.org/issue19080>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com