diff options
author | Martin Vilcans <martin@librador.com> | 2011-09-10 20:20:49 +0200 |
---|---|---|
committer | Martin Vilcans <martin@librador.com> | 2011-09-10 23:42:57 +0200 |
commit | 98e8bb6ffd01ff1f14f915d35ce3371740968b1d (patch) | |
tree | 5b42f0414ee69eb11f29436fa87bbddc5da851aa | |
parent | 7d3877f94a8de98a11bcea631b79b6db9b7f47fe (diff) | |
download | screenplain-98e8bb6ffd01ff1f14f915d35ce3371740968b1d.tar.gz |
A Transition must be followed by a slug, otherwise it's Action
-rw-r--r-- | screenplain/parsers/spmd.py | 15 | ||||
-rw-r--r-- | tests/spmd_test.py | 2 |
2 files changed, 12 insertions, 5 deletions
diff --git a/screenplain/parsers/spmd.py b/screenplain/parsers/spmd.py index fbf2ffa..ff9ac67 100644 --- a/screenplain/parsers/spmd.py +++ b/screenplain/parsers/spmd.py @@ -41,8 +41,8 @@ def create_paragraph(blanks_before, line_list): ): return _create_dialog(line_list) elif len(line_list) == 1 and line_list[0].endswith(':') and line_list[0].isupper(): - # TODO: need to check whether the *next* paragraph is a slug - # before assuming this is a transition. + # Assume this is a transition. It may be changed to Action + # later if we find that it's not followed by a slug. return Transition(line_list) else: return Action(line_list) @@ -60,8 +60,17 @@ def parse(source): """Reads raw text input and generates paragraph objects.""" blank_count = 0 source = (clean_line(line) for line in source) + paragraphs = [] for blank, lines in itertools.groupby(source, is_blank): if blank: blank_count = len(list(lines)) else: - yield create_paragraph(blank_count, list(lines)) + paragraphs.append(create_paragraph(blank_count, list(lines))) + + # Make a second pass over the script and replace transitions not + # followed by sluglines with action. + for i in xrange(len(paragraphs) - 1): + if (isinstance(paragraphs[i], Transition) and + not isinstance(paragraphs[i + 1], Slug)): + paragraphs[i] = Action(paragraphs[i].lines) + return paragraphs diff --git a/tests/spmd_test.py b/tests/spmd_test.py index b66c478..caa5b20 100644 --- a/tests/spmd_test.py +++ b/tests/spmd_test.py @@ -136,8 +136,6 @@ class ParseTests(unittest2.TestCase): ])) self.assertEquals([Action, Action, Slug], [type(p) for p in paras]) - # Not implemented yet - @unittest2.expectedFailure def test_transition_must_be_followed_by_slug(self): paras = list(parse([ 'Bill lights a cigarette.', |