src/eric7/Plugins/CheckerPlugins/SyntaxChecker/tomlCheckSyntax.py

branch
eric7
changeset 9507
1f39839655ea
parent 9482
a2bc06a54d9d
child 9653
e67609152c5e
equal deleted inserted replaced
9506:62397ab8df8c 9507:1f39839655ea
27 27
28 @return the entry point for the background client 28 @return the entry point for the background client
29 @rtype func 29 @rtype func
30 """ 30 """
31 return tomlSyntaxBatchCheck 31 return tomlSyntaxBatchCheck
32
33
34 def normalizeCode(codestring):
35 """
36 Function to normalize the given code.
37
38 @param codestring code to be normalized
39 @type str
40 @return normalized code
41 @rtype str
42 """
43 codestring = codestring.replace("\r\n", "\n").replace("\r", "\n")
44
45 if codestring and codestring[-1] != "\n":
46 codestring += "\n"
47
48 return codestring
49 32
50 33
51 def tomlSyntaxCheck(file, codestring): 34 def tomlSyntaxCheck(file, codestring):
52 """ 35 """
53 Function to check a TOML source file for syntax errors. 36 Function to check a TOML source file for syntax errors.
183 ) 166 )
184 except ImportError: 167 except ImportError:
185 error = "tomlkit not available. Install it via the PyPI interface." 168 error = "tomlkit not available. Install it via the PyPI interface."
186 return [{"error": (file, 0, 0, "", error)}] 169 return [{"error": (file, 0, 0, "", error)}]
187 170
188 codestring = normalizeCode(codestring)
189
190 try: 171 try:
191 tomlkit.parse(codestring) 172 tomlkit.parse(codestring)
192 except ParseError as exc: 173 except ParseError as exc:
193 line = exc.line 174 line = exc.line
194 column = exc.col 175 column = exc.col

eric ide

mercurial