def _reportLatexWarnings(self, lnode, content): """Helper to display latex warnings.""" # Locate the Page object where the error was producec. pnode = None for page in content: if lnode.filename in page.destination: pnode = page break # Get the rendered result tree and locate the start/end lines for each node result = None if pnode is not None: result = self.translator.getResultTree(pnode) result['_start_line'] = 1 self._lineCounter(result) # Report warning(s) for w in lnode.warnings: # Locate the rendered node that that caused the error r_node = None if result: for r in anytree.PreOrderIter(result): if w.line >= r.get('_start_line', float('Inf')): r_node = r # Build message msg = '\n' msg += mooseutils.colorText( 'pdfLaTeX Warning: {}\n'.format(w.content), 'LIGHT_YELLOW') if r_node: msg += box(r_node.write(), title='IN: {}:{}'.format(pnode.destination, w.line), width=100, color='GREY') msg += '\n' info = r_node.get('info', None) if info is not None: msg += box(info[0], title='FROM: {}:{}'.format( pnode.source, info.line), color='GREY') LOG.warning(msg)
def _reportLatexWarnings(self, lnode, content): """Helper to display latex warnings.""" # Locate the Page object where the error was producec. pnode = None for page in content: if lnode.filename in page.destination: pnode = page break # Get the rendered result tree and locate the start/end lines for each node result = None if pnode is not None: result = self.translator.getResultTree(pnode) result['_start_line'] = 1 self._lineCounter(result) # Report warning(s) for w in lnode.warnings: # Locate the rendered node that that caused the error r_node = None if result: for r in anytree.PreOrderIter(result): if w.line >= r.get('_start_line', float('Inf')): r_node = r # Build message msg = '\n' msg += mooseutils.colorText('pdfLaTeX Warning: {}\n'.format(w.content), 'LIGHT_YELLOW') if r_node: msg += box(r_node.write(), title='IN: {}:{}'.format(pnode.destination, w.line), width=100, color='GREY') msg += '\n' info = r_node.get('info', None) if info is not None: msg += box(info[0], title='FROM: {}:{}'.format(pnode.source, info.line), color='GREY') LOG.warning(msg)
def tokenize(self, parent, grammer, text, line=1): """ Perform tokenization of the supplied text. Inputs: parent[tree.tokens]: The parent token to which the new token(s) should be attached. grammer[Grammer]: Object containing the grammer (defined by regexs) to search. text[unicode]: The text to tokenize. line[int]: The line number to startwith, this allows for nested calls to begin with the correct line. NOTE: If the functions attached to the Grammer object raise a TokenizeException it will be caught by this object and converted into an Exception token. This allows for the entire text to be tokenized and have the errors report upon completion. The TokenizeException also contains information about the error, via a LexerInformation object to improve error reports. """ common.check_type('text', text, unicode, exc=exceptions.TokenizeException) n = len(text) pos = 0 while pos < n: match = None for pattern in grammer: match = pattern.regex.match(text, pos) if match: info = LexerInformation(match, pattern, line) try: obj = self.buildObject(parent, pattern, info) except Exception as e: #pylint: disable=broad-except obj = tokens.ExceptionToken( parent, info=info, message=e.message, traceback=traceback.format_exc()) if obj is not None: obj.info = info #TODO: set ptype on base Token, change to info line += match.group(0).count('\n') pos = match.end() break else: continue if match is None: break # Produce Exception token if text remains that was not matched if pos < n: msg = u'Unprocessed text exists:\n{}'.format( common.box(text[pos:], line=line)) LOG.error(msg)
def report(self, current): title = 'ERROR: {}'.format(self.message) filename = '' if current: source = current.source filename = mooseutils.colorText('{}:{}\n'.format(source, self.info.line), 'RESET') box = mooseutils.colorText(common.box(self.info[0], line=self.info.line, width=100), 'LIGHT_CYAN') return u'\n{}\n{}{}\n'.format(title, filename, box)
def testBasic(self): b = common.box('foo\nbar', 'title', 42, 12) gold = u'title\n \u250c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510\n42\u2502' \ u'foo \u2502\n43\u2502bar \u2502\n \u2514\u2500\u2500\u2500\u2500\u2500' \ u'\u2500\u2500\u2500\u2518' self.assertEqual(b, gold)