Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixed bad indentation and tests

--HG--
branch : sneakylang
  • Loading branch information...
commit f4441067d53050bfa90b9eea5cbefb1710e4b586 1 parent 7ed28c9
almad authored
View
13 sneakylang/register.py
@@ -94,14 +94,14 @@ def resolve_parser(self, stream, register, whole_stream=None):
""" Resolve parser stream.
Return properly initialized parser or None
"""
- if whole_stream is None:
- whole_stream = stream
-
- matching = []
- for start in self.parser_start:
+ if whole_stream is None:
+ whole_stream = stream
+ matching = []
+
+ for start in self.parser_start:
compiled, parser = self.parser_start[start]
if start.find('^') != -1:
- if compiled.match(whole_stream) and stream == whole_stream:
+ if compiled.match(whole_stream) and stream == whole_stream:
matching.append(compiled.match(whole_stream))
else:
if compiled.match(stream):
@@ -112,6 +112,7 @@ def resolve_parser(self, stream, register, whole_stream=None):
parser, chunk = self._most_matching(matching)
if parser is None or chunk is None:
return None
+
return parser(stream, self, chunk, register)
class Register(object):
View
26 sneakylang/test/module_test.py
@@ -80,13 +80,14 @@ class ParagraphMacro(Macro):
parsersAllowed = ['Strong']
@classmethod
- def get_argument_list(self, argument_string):
- return [argument_string]
+ def get_arguments(self, argument_string):
+ return [argument_string], {}
def expand_to_nodes(self, *args):
if len(args) < 1:
- raise MacroCallError, "Paragraph must have some content"
+ raise MacroCallError("Paragraph must have some content")
content = ''.join([word+' ' for word in args])[:-1]
+ print content
self.builder.append(ParagraphNode())
parse(content, self.register_map, self.register, builder=self.builder)
self.builder.move_up()
@@ -96,6 +97,9 @@ class Paragraph(Parser):
macro = ParagraphMacro
end = '(\n){2}'
+ def get_arguments(self, argument_string):
+ return parse_macro_arguments(argument_string, return_kwargs=True)
+
def resolve_argument_string(self):
end = re.search(self.__class__.end, self.stream)
if end:
@@ -104,6 +108,7 @@ def resolve_argument_string(self):
self.stream = self.stream[end.end():]
else:
self.argument_string = self.stream
+ print self.argument_string
self.stream = ''
class StrongNode(Node): pass
@@ -143,17 +148,14 @@ def expand_to_nodes(self, content, **kwargs):
class Strong(Parser):
start = ['("){2}']
macro = StrongMacro
- end = '("){2}'
def resolve_argument_string(self):
- s = self.stream
- end = re.search(self.__class__.end, s)
- if not end:
- logging.debug('End %s of macro %s not found, rolling back' % (self.__class__.end, self))
- raise ParserRollback
- self.stream = s
- self.argument_string = self.stream[0:end.start()]
- self.stream = self.stream[end.end():]
+ endMatch = re.search(re.escape(self.chunk), self.stream)
+ if not endMatch:
+ raise ParserRollback()
+ self.argument_string = self.stream[0:endMatch.start()]
+ self.chunk_end = self.stream[endMatch.start():endMatch.end()]
+ self.stream = self.stream[endMatch.end():]
class ParagraphDocbookExpand(Expander):
def expand(self, node, format, node_map):
View
5 sneakylang/test/test_macro_syntax.py
@@ -79,10 +79,11 @@ def testProperNested(self):
self.assertEquals(o.children[0].children[1].content, ' text odstavce')
def testProperNestedQuoted(self):
- s = '((odstavec "silne silny)) text odstavce"))'
+ # we cannot use odstavec as macro, because it is not parsing it's args
+ s = '((silne "silne silny)) text odstavce"))'
o = parse(s, self.register_map, document_root=True)
self.assertEquals(len(o.children), 1)
- self.assertEquals(o.children[0].__class__, ParagraphNode)
+ self.assertEquals(o.children[0].__class__, StrongNode)
self.assertEquals(o.children[0].children[0].__class__, TextNode)
self.assertEquals(o.children[0].children[0].content, 'silne silny)) text odstavce')
Please sign in to comment.
Something went wrong with that request. Please try again.