Ejemplo n.º 1
0
 def _regular_comment(self, parser, caret):
     """Parse regular comments. """
     if parser.text[caret+2:caret+4] != '--':
         index = parser.text.find('!>', caret+2)
         if index != -1:
             parser.update(index+2)
             content = replace(parser.text[caret+2:index], ('--', '- '))
             return Comment(content)
         index = parser.text.find('>', caret+2)
         if index == -1:
             self.msg('E100', parser.pos)
             parser.update(parser.end)
             content = parser.text[caret+2:parser.end]
             return Comment(replace(content, ('--', '- ')))
         parser.update(index+1)
         content = replace(parser.text[caret+2:index], ('--', '- '))
         return Comment(content)
     index = parser.text.find('--', caret+4)
     if index == -1:
         self.msg('E200', parser.pos)
         parser.update(parser.end)
         return Comment(parser.text[caret+4:parser.end])
     content = parser.text[caret+4:index]
     while parser.text[index:index+3] != '-->':
         content += '- '
         newindex = parser.text.find('--', index+1)
         if newindex == -1:
             content += parser.text[index+2:parser.end]
             self.msg('E200', parser.pos)
             parser.update(parser.end)
             return Comment(content)
         content += parser.text[index+2:newindex]
         index = newindex
     parser.update(index+3)
     return Comment(content)
Ejemplo n.º 2
0
 def _handle_bogus(self, parser, caret):
     """Helper method for make_node. """
     self.msg('E100', parser.pos)
     index = parser.text.find('>', caret+2)
     if index == -1:
         parser.update(parser.end)
         self.msg('E201', parser.pos)
         content = parser.text[caret+2:parser.end]
         return Comment(replace(content, ('--', '- ')))
     pos = parser.compute(index)
     self.msg('E300', pos)
     parser.update(index+1)
     content = replace(parser.text[caret+2:index], ('--', '- '))
     return Comment(content)
Ejemplo n.º 3
0
 def _new_comment(self, parser, caret):
     """parse new style comment. """
     index = parser.text.find('%%', caret+3)
     if index == -1:
         self.msg('E100', parser.pos)
         parser.update(parser.end)
         return Comment(parser.text[caret+3:parser.end])
     content = parser.text[caret+3:index]
     parser.update(index+3)
     return Comment(replace(content, ('--', '- ')))
 def handle_data(data, node):
     """Look for sequences of the form `$(variable)` and
     do a replacement with the current variable. """
     variables = RE.findall(data)
     replace_list = list()
     meta = node.owner.meta
     for var in variables:
         if var in meta:
             replace_list.append(('$(%s)' % var, meta[var]))
         else:
             replace_list.append(('$(%s)' % var, ""))
     if replace_list:
         return replace(data, *replace_list)
     return data
 def handle_set_delayed(self, text, index, node):
     """"Helper function for handle_token and eval_text. """
     args = []
     next_index = next_char(text, index)
     while text[next_index] == '{':
         arg, next_index = get_input(text, next_index + 1)
         args.append(self.eval_text(arg))
         if next_index == len(text):
             break
     index = next_index
     evaled_val = self.eval_text(node['value'])
     if 'arg' in node:
         od_ = node['arg'].copy()
         keys = od_.keys()
         for i in xrange(len(args)):
             od_[keys[i]] = args[i]
         mapping = []
         for key, val in od_.iteritems():
             mapping.append([':' + key + ':', val])
         return replace(evaled_val, *mapping), index
     return evaled_val, index
 def handle_set_delayed(self, text, index, node):
     """"Helper function for handle_token and eval_text. """
     args = []
     next_index = next_char(text, index)
     while text[next_index] == '{':
         arg, next_index = get_input(text, next_index+1)
         args.append(self.eval_text(arg))
         if next_index == len(text):
             break
     index = next_index
     evaled_val = self.eval_text(node['value'])
     if 'arg' in node:
         od_ = node['arg'].copy()
         keys = od_.keys()
         for i in xrange(len(args)):
             od_[keys[i]] = args[i]
         mapping = []
         for key, val in od_.iteritems():
             mapping.append([':'+key+':', val])
         return replace(evaled_val, *mapping), index
     return evaled_val, index