Created
March 21, 2018 06:11
-
-
Save milesrout/7e65e149d9f9434a1cba8939ab0e532e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@compose(E.ControlStructureExpression) | |
@compose(list) | |
def linked_control_structure_stmt(self, initial, pos0): | |
linking_structure = self.linked_control_structures[self.current_token().string] | |
while True: | |
pos = self.current_token().pos | |
name = self.get_token().string | |
options = linking_structure[name] | |
params = [] | |
i, j = 0, 0 | |
while not self.accept('colon'): | |
if i >= len(options): | |
self.expect('colon') | |
if j >= len(options[i]): | |
j = 0 | |
i += 1 | |
if options[i][j] is None: | |
params.append(self.test()) | |
else: | |
params.append(E.SymbolExpression(self.get_token())) | |
j += 1 | |
else: | |
if i != len(options) and j != len(options[i]): | |
if options[i][j] is None: | |
self.raise_unexpected() | |
else: | |
self.expect_symbol(options[i][j]) | |
self.next_token() | |
suite = self.suite() | |
yield E.ControlStructureLinkExpression(name, params, suite, pos) | |
if not self.accept_symbol(*self.acceptable_lcs_successors(initial)): | |
break |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment