eric7/Plugins/CheckerPlugins/SyntaxChecker/tomlCheckSyntax.py

branch
eric7
changeset 9107
8e9525a780ae
parent 8881
54e42bc2437a
equal deleted inserted replaced
9106:287d5afa2dbe 9107:8e9525a780ae
171 (file name, line number, column, codestring (only at syntax 171 (file name, line number, column, codestring (only at syntax
172 errors), the message, a list with arguments for the message) 172 errors), the message, a list with arguments for the message)
173 @rtype dict 173 @rtype dict
174 """ 174 """
175 try: 175 try:
176 import toml 176 import tomlkit
177 from tomlkit.exceptions import ParseError
177 except ImportError: 178 except ImportError:
178 error = "toml not available. Install it via the PyPI interface." 179 error = "tomlkit not available. Install it via the PyPI interface."
179 return [{'error': (file, 0, 0, '', error)}] 180 return [{'error': (file, 0, 0, '', error)}]
180 181
181 codestring = normalizeCode(codestring) 182 codestring = normalizeCode(codestring)
182 183
183 try: 184 try:
184 toml.loads(codestring) 185 tomlkit.parse(codestring)
185 except toml.TomlDecodeError as exc: 186 except ParseError as exc:
186 line = exc.lineno 187 line = exc.line
187 column = exc.colno 188 column = exc.col
188 error = exc.msg 189 error = str(exc).split(" at ", 1)[0].strip()
190 # get error message without location
189 191
190 cline = min(len(codestring.splitlines()), int(line)) - 1 192 cline = min(len(codestring.splitlines()), int(line)) - 1
191 code = codestring.splitlines()[cline] 193 code = codestring.splitlines()[cline]
192 194
193 return [{'error': (file, line, column, code, error)}] 195 return [{'error': (file, line, column, code, error)}]

eric ide

mercurial