Linux cesa-www-main 6.1.0-49-cloud-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.1.174-1 (2026-05-26) x86_64
Apache/2.4.68 (Debian)
Server IP : 10.218.0.2 & Your IP : 216.73.216.28
Domains :
Cant Read [ /etc/named.conf ]
User : www-data
Terminal
Auto Root
Create File
Create Folder
Localroot Suggester
Backdoor Destroyer
Readme
/
usr /
lib /
google-cloud-sdk /
lib /
third_party /
lark /
Delete
Unzip
Name
Size
Permission
Date
Action
__pycache__
[ DIR ]
drwxr-xr-x
2026-06-08 18:08
__pyinstaller
[ DIR ]
drwxr-xr-x
2026-06-08 18:08
grammars
[ DIR ]
drwxr-xr-x
2026-06-08 18:08
parsers
[ DIR ]
drwxr-xr-x
2026-06-08 18:08
tools
[ DIR ]
drwxr-xr-x
2026-06-08 18:08
LICENSE
1.03
KB
-rw-r--r--
1980-01-01 08:00
__init__.py
744
B
-rw-r--r--
1980-01-01 08:00
ast_utils.py
2.04
KB
-rw-r--r--
1980-01-01 08:00
common.py
2.83
KB
-rw-r--r--
1980-01-01 08:00
exceptions.py
10.68
KB
-rw-r--r--
1980-01-01 08:00
grammar.py
3.35
KB
-rw-r--r--
1980-01-01 08:00
indenter.py
3
KB
-rw-r--r--
1980-01-01 08:00
lark.py
27.09
KB
-rw-r--r--
1980-01-01 08:00
lexer.py
22.98
KB
-rw-r--r--
1980-01-01 08:00
load_grammar.py
52.23
KB
-rw-r--r--
1980-01-01 08:00
parse_tree_builder.py
13.78
KB
-rw-r--r--
1980-01-01 08:00
parser_frontends.py
9.82
KB
-rw-r--r--
1980-01-01 08:00
py.typed
0
B
-rw-r--r--
1980-01-01 08:00
reconstruct.py
3.63
KB
-rw-r--r--
1980-01-01 08:00
tree.py
8.04
KB
-rw-r--r--
1980-01-01 08:00
tree_matcher.py
5.86
KB
-rw-r--r--
1980-01-01 08:00
tree_templates.py
6
KB
-rw-r--r--
1980-01-01 08:00
utils.py
10.73
KB
-rw-r--r--
1980-01-01 08:00
visitors.py
20.6
KB
-rw-r--r--
1980-01-01 08:00
Save
Rename
"""Reconstruct text from a tree, based on Lark grammar""" from typing import Dict, Callable, Iterable, Optional from .lark import Lark from .tree import Tree, ParseTree from .visitors import Transformer_InPlace from .lexer import Token, PatternStr, TerminalDef from .grammar import Terminal, NonTerminal, Symbol from .tree_matcher import TreeMatcher, is_discarded_terminal from .utils import is_id_continue def is_iter_empty(i): try: _ = next(i) return False except StopIteration: return True class WriteTokensTransformer(Transformer_InPlace): "Inserts discarded tokens into their correct place, according to the rules of grammar" tokens: Dict[str, TerminalDef] term_subs: Dict[str, Callable[[Symbol], str]] def __init__(self, tokens: Dict[str, TerminalDef], term_subs: Dict[str, Callable[[Symbol], str]]) -> None: self.tokens = tokens self.term_subs = term_subs def __default__(self, data, children, meta): if not getattr(meta, 'match_tree', False): return Tree(data, children) iter_args = iter(children) to_write = [] for sym in meta.orig_expansion: if is_discarded_terminal(sym): try: v = self.term_subs[sym.name](sym) except KeyError: t = self.tokens[sym.name] if not isinstance(t.pattern, PatternStr): raise NotImplementedError("Reconstructing regexps not supported yet: %s" % t) v = t.pattern.value to_write.append(v) else: x = next(iter_args) if isinstance(x, list): to_write += x else: if isinstance(x, Token): assert Terminal(x.type) == sym, x else: assert NonTerminal(x.data) == sym, (sym, x) to_write.append(x) assert is_iter_empty(iter_args) return to_write class Reconstructor(TreeMatcher): """ A Reconstructor that will, given a full parse Tree, generate source code. Note: The reconstructor cannot generate values from regexps. If you need to produce discarded regexes, such as newlines, use `term_subs` and provide default values for them. Parameters: parser: a Lark instance term_subs: a dictionary of [Terminal name as str] to [output text as str] """ write_tokens: WriteTokensTransformer def __init__(self, parser: Lark, term_subs: Optional[Dict[str, Callable[[Symbol], str]]]=None) -> None: TreeMatcher.__init__(self, parser) self.write_tokens = WriteTokensTransformer({t.name:t for t in self.tokens}, term_subs or {}) def _reconstruct(self, tree): unreduced_tree = self.match_tree(tree, tree.data) res = self.write_tokens.transform(unreduced_tree) for item in res: if isinstance(item, Tree): # TODO use orig_expansion.rulename to support templates yield from self._reconstruct(item) else: yield item def reconstruct(self, tree: ParseTree, postproc: Optional[Callable[[Iterable[str]], Iterable[str]]]=None, insert_spaces: bool=True) -> str: x = self._reconstruct(tree) if postproc: x = postproc(x) y = [] prev_item = '' for item in x: if insert_spaces and prev_item and item and is_id_continue(prev_item[-1]) and is_id_continue(item[0]): y.append(' ') y.append(item) prev_item = item return ''.join(y)