31 Initialize the batch service and return the entry point. |
31 Initialize the batch service and return the entry point. |
32 |
32 |
33 @return the entry point for the background client (function) |
33 @return the entry point for the background client (function) |
34 """ |
34 """ |
35 return jsSyntaxBatchCheck |
35 return jsSyntaxBatchCheck |
36 |
|
37 |
|
38 def normalizeCode(codestring): |
|
39 """ |
|
40 Function to normalize the given code. |
|
41 |
|
42 @param codestring code to be normalized (string) |
|
43 @return normalized code (string) |
|
44 """ |
|
45 codestring = codestring.replace("\r\n", "\n").replace("\r", "\n") |
|
46 |
|
47 if codestring and codestring[-1] != "\n": |
|
48 codestring += "\n" |
|
49 |
|
50 return codestring |
|
51 |
36 |
52 |
37 |
53 def jsSyntaxCheck(file, codestring): |
38 def jsSyntaxCheck(file, codestring): |
54 """ |
39 """ |
55 Function to check a Javascript source file for syntax errors. |
40 Function to check a Javascript source file for syntax errors. |
169 errors), the message, a list with arguments for the message) |
154 errors), the message, a list with arguments for the message) |
170 """ |
155 """ |
171 import jasy.script.parse.Parser as jsParser # __IGNORE_WARNING_I102__ |
156 import jasy.script.parse.Parser as jsParser # __IGNORE_WARNING_I102__ |
172 import jasy.script.tokenize.Tokenizer as jsTokenizer # __IGNORE_WARNING_I102__ |
157 import jasy.script.tokenize.Tokenizer as jsTokenizer # __IGNORE_WARNING_I102__ |
173 |
158 |
174 codestring = normalizeCode(codestring) |
|
175 |
|
176 try: |
159 try: |
177 jsParser.parse(codestring, file) |
160 jsParser.parse(codestring, file) |
178 except (jsParser.SyntaxError, jsTokenizer.ParseError) as exc: |
161 except (jsParser.SyntaxError, jsTokenizer.ParseError) as exc: |
179 details = exc.args[0] |
162 details = exc.args[0] |
180 error, details = details.splitlines() |
163 error, details = details.splitlines() |