Commits

Anonymous committed bc7f4f2

Add support for priority check + a few small fixes

Comments (0)

Files changed (4)

sneakylang/node.py

 
         if isinstance(node, TextNode):
             if self.actual_text_content is not None:
-                raise ValueError, 'Adding a text node, but one is alread present'
+                raise ValueError('Adding a text node, but one is already present')
             self.actual_text_content = node
         else:
             self.actual_text_content = None
         """ Insert child on given position """
         if isinstance(node, TextNode):
             if self.actual_text_content is not None:
-                raise ValueError, 'Adding a text node, but one is alread present'
+                raise ValueError('Adding a text node, but one is already present')
             self.actual_text_content = node
         else:
             self.actual_text_content = None

sneakylang/parser.py

                 stream = stream_new
                 opened_text_node = None
             else:
-                # macro not resolved, add text node
+                logging.debug('Macro not resolved, add text node')
                 node, stream = _get_text_node(stream, register, register_map, builder, state, opened_text_node=opened_text_node, whole_stream=whole_stream)
                 if opened_text_node is None:
                     builder.append(node, move_actual=False)
-                opened_text_node=node
+                opened_text_node = node
         except (ParserRollback, MacroCallError):
-            #badly resolved macro
-            logging.debug('Catched ParseRollback, forcing text char')
+            # badly resolved macro
+            logging.debug('ParserRollback caught, forcing text char')
             node, stream = _get_text_node(stream, register, register_map, builder, state, True, opened_text_node=opened_text_node, whole_stream=whole_stream)
             if opened_text_node is None:
                 builder.append(node, move_actual=False)

sneakylang/register.py

         most = None
         length = 0
         for m in matching:
-            if len(m.string[m.start():m.end()]) > length:
+            mlen = len(m.string[m.start():m.end()])
+
+            if mlen > length:
                 most = m
                 length = len(m.string[m.start():m.end()])
+            elif mlen == length:
+                logging.debug('Two or more parsers are matching, ' \
+                    'performing the priority check')
+                m_parser = self.parser_start[m.re.pattern[1:]][1]
+                most_parser = self.parser_start[most.re.pattern[1:]][1]
+                if getattr(m_parser, 'priority', 0) > \
+                    getattr(most_parser, 'priority', 0):
+                    most = m
+
         if most is None:
             return (None, None)
         return (self.parser_start[most.re.pattern[1:]][1], most.string[most.start():most.end()])
 	for start in self.parser_start:
             compiled, parser = self.parser_start[start]
             if start.find('^') != -1:
-		if compiled.match(whole_stream):
+		if compiled.match(whole_stream) and stream == whole_stream:
                     matching.append(compiled.match(whole_stream))
             else:
                 if compiled.match(stream):
             whole_stream = stream
 
         parser = self.parser_register.resolve_parser(stream, self, whole_stream)
+
         if parser is not None:
             # Macro resolved in alternate syntax, use parser to get pacro
             macro, stream_new = parser.get_macro(builder, state)

sneakylang/treebuilder.py

         else:
             raise ValueError, 'Node %s not found in tree' % node
 
-    actual_node = property(fget=get_actual_node)
+    actual_node = property(fget=get_actual_node)