This file contains 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
""" | |
Proof-of-concept `@ast_transformer` decorator that allows somewhat easy | |
AST based transformation of functions, even if those are deeply nested within | |
classes or other functions, while correctly dealing with closures. | |
Also tries to handle composition of transformers, however currently, they will | |
be applied multiple times, an extra time for each transformer above it. | |
The correct handling of closures is achieved by compiling the entire file | |
again, with the transformed AST integrated. Then the correct code object | |
is extracted and inserted into the function. |
This file contains 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
from __future__ import annotations | |
from functools import cache | |
# Solution for https://stackoverflow.com/questions/75807633 | |
def countGoodArrays(arr): | |
MOD = 10 ** 9 + 7 | |
zero_count = 0 | |
last = None |
This file contains 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
from lark import Lark, UnexpectedToken, Token, UnexpectedCharacters | |
from lark.lexer import LexerThread, LexerState, LineCounter | |
grammar = r""" | |
start: _NL* _section+ | |
_section: _HEADER _content* _HEADER | |
_HEADER: "--- SECTION ---" _NL | |
_content: number_list | |
| assign | |
| _other |
This file contains 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
from __future__ import annotations | |
from dataclasses import dataclass | |
from typing import List, NewType, Dict, Tuple | |
Player = NewType('Player', str) | |
@dataclass(frozen=True) | |
class Move: |