~yacinechaouche/mergou/trunk

Viewing all changes in revision 104.

  • Committer: yacinechaouche at yahoo
  • Date: 2013-12-08 23:55:18 UTC
  • Revision ID: yacinechaouche@yahoo.com-20131208235518-fzoucz3h1ovh29tz
Fixed a bug that discounted lines of code when paren mismatch was in a string. Example : 


start_code = '\033[31;1;5m' 27

and 

end_code   = '\033[m' 21

are both treated as leaving an open bracket, which is a bug because the reader should ignore brackets inside strings.

The solution was to compile the line if there's a parens mismatch which gives a somewhat good indicator about the location of the paren (part of the code or not).

SOLUTION:

    def _parse(self,line):
        _line = line.lstrip()
        missing = _line.count("(") + _line.count("[") - _line.count(")") - _line.count("]")
        # make sure that there's really something missing
        if missing :
            utils.debug("[DEBUG Reader._parse] paren mismatch", missing)
            try:
                compile(_line,"/tmp/tmpcode","single")
                utils.debug("[DEBUG Reader._parse] line compiles.")
            except SyntaxError,e:
                utils.debug("[DEBUG Reader._parse] line doesn't compile")
                self._open_parens += missing

        ...

expand all expand all

Show diffs side-by-side

added added

removed removed

Lines of Context: