()
| 68 | |
| 69 | # noinspection PyShadowingNames |
| 70 | def parse_root(): |
| 71 | tokens = [] |
| 72 | if not can_advance(): |
| 73 | return Path( |
| 74 | kind=PathAction.KEY, |
| 75 | accessor=EMPTY_STRING, |
| 76 | is_root=True |
| 77 | ) |
| 78 | # (literal | index_path | append_path)? |
| 79 | token = expect(*LITERAL_TOKENS, TokenKind.LEFT_BRACKET) |
| 80 | tokens.append(token) |
| 81 | if token.kind in LITERAL_TOKENS: |
| 82 | action = PathAction.KEY |
| 83 | value = str(token.value) |
| 84 | elif token.kind is TokenKind.LEFT_BRACKET: |
| 85 | token = expect(TokenKind.NUMBER, TokenKind.RIGHT_BRACKET) |
| 86 | tokens.append(token) |
| 87 | if token.kind is TokenKind.NUMBER: |
| 88 | action = PathAction.INDEX |
| 89 | value = token.value |
| 90 | tokens.append(expect(TokenKind.RIGHT_BRACKET)) |
| 91 | elif token.kind is TokenKind.RIGHT_BRACKET: |
| 92 | action = PathAction.APPEND |
| 93 | value = None |
| 94 | else: |
| 95 | assert_cant_happen() |
| 96 | else: |
| 97 | assert_cant_happen() |
| 98 | # noinspection PyUnboundLocalVariable |
| 99 | return Path( |
| 100 | kind=action, |
| 101 | accessor=value, |
| 102 | tokens=tokens, |
| 103 | is_root=True |
| 104 | ) |
| 105 | |
| 106 | yield parse_root() |
| 107 |
no test coverage detected