Permalink
Browse files

Fixed long argument resolving (#30)

--HG--
branch : sneakylang
  • Loading branch information...
1 parent 38882b0 commit 74d4d1b10e4dcaee602abe0b410bfefaa50cc343 almad committed Mar 10, 2009
Showing with 15 additions and 10 deletions.
  1. +13 −8 sneakylang/macro_caller.py
  2. +1 −1 sneakylang/test/test_macro_caller.py
  3. +1 −1 sneakylang/test/test_macro_syntax.py
View
@@ -74,7 +74,7 @@ def parse_macro_arguments(argument_string, return_kwargs=False):
kwarg_name_buffer = u''
in_long_argument = False
current_kwarg_name = None
- after_argument_separator = False
+ last_char = None
for char in argument_string:
# first, append to buffers et al
@@ -93,8 +93,16 @@ def parse_macro_arguments(argument_string, return_kwargs=False):
else:
buffer = u''.join([buffer, char])
elif char != ARGUMENT_SEPARATOR:
- # if char == LONG_ARGUMENT_BEGIN and (after_name_separator or after_kwargs_separator):
- if char == LONG_ARGUMENT_BEGIN:
+ if char == LONG_ARGUMENT_BEGIN and (
+ # we're at beginning of the string
+ last_char is None
+ or
+ # unnamed long argument
+ last_char == ARGUMENT_SEPARATOR
+ or
+ # keyword argument (must be named)
+ (last_char == KEYWORD_ARGUMENT_SEPARATOR and current_kwarg_name)
+ ):
in_long_argument = True
else:
# could be both text and kwarg name
@@ -114,11 +122,8 @@ def parse_macro_arguments(argument_string, return_kwargs=False):
else:
raise NotImplementedError("char != ARGUMENT_SEPARATOR && char == ARGUMENT_SEPARATOR WTF?!?")
- # then, set position flags
- if char == ARGUMENT_SEPARATOR:
- after_argument_separator = True
- else:
- after_argument_separator = False
+ # then, cache last char
+ last_char = char
if len(buffer) > 0:
# FIXME: This is cut& pasted from char == ARGUMENT_SEPARATOR
@@ -38,7 +38,7 @@ def testKeywordArgument(self):
self.assertEquals(([], {'argument' : u'testing arg'}), parse_macro_arguments(u'argument="testing arg"', return_kwargs=True))
def testKeywordMustBeNamed(self):
- self.assertEquals(([u"blah", u'="testing arg"'], {}), parse_macro_arguments(u'blah ="testing arg"', return_kwargs=True))
+ self.assertEquals(([u"blah", u'="testing', u'arg"'], {}), parse_macro_arguments(u'blah ="testing arg"', return_kwargs=True))
class TestHelperFunctions(TestCase):
def test_strip_long_argument_chunk(self):
@@ -38,7 +38,7 @@ def setUp(self):
self.expanderMap = {
'docbook5' : {
ParagraphNode : ParagraphDocbookExpand,
- TextNode : TextNodeExpander
+ TextNode : TextNodeExpander,
}
}

0 comments on commit 74d4d1b

Please sign in to comment.