Mercurial > js4py
changeset 158:f4ea703a359b core-javascript.closure-exercises
$ hg rm py/doit.py # late removal of this file (use remove_answers.py instead)
| author | jf3243 |
|---|---|
| date | Wed, 09 Nov 2011 15:51:55 +0000 |
| parents | 5f3017d81e04 |
| children | 1eb05ae4fd4d |
| files | core-javascript/py/doit.py |
| diffstat | 1 files changed, 0 insertions(+), 63 deletions(-) [+] |
line wrap: on
line diff
--- a/core-javascript/py/doit.py Wed Nov 09 15:38:57 2011 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,63 +0,0 @@ -'''Remove answers from exercises file.''' - -import sys - -NORMAL, SKIPPING, ERROR = range(3) -LINE, SOMETHING, START, STOP = range(4) - -lookup = {} - -# All other states are an error. -lookup[NORMAL, LINE] = NORMAL -lookup[NORMAL, SOMETHING] = NORMAL -lookup[NORMAL, START] = SKIPPING -lookup[SKIPPING, LINE] = SKIPPING -# lookup[NORMAL, STOP] = ERROR -# lookup[SKIPPING, SOMETHING] = ERROR -lookup[SKIPPING, STOP] = NORMAL - - -filename = 'core-javascript-work/closure-exercises.js' - -write = sys.stdout.write -with open(filename) as lines: - - new_state = NORMAL - - for lineno, line in enumerate(lines): - - state = new_state - - - stripped_line = line.strip() - - if stripped_line.startswith('something'): - event = SOMETHING - - elif stripped_line == '// start': - event = START - - elif stripped_line == '// stop': - event = STOP - - else: - event = LINE - - new_state = lookup[state, event] - - if event == SOMETHING: - pass - - elif event == STOP: - pass - - elif event == START: - indent = len(line) - len(line.lstrip()) - spaces = line[0:indent] - write(spaces + '// Please write your answer here.\r\n') - - elif state == SKIPPING: - pass - - elif event == LINE: - write(line.rstrip() + '\r\n')
